PHPOffice / PHPPresentation

A pure PHP library for reading and writing presentations documents
https://phpoffice.github.io/PHPPresentation
Other
1.31k stars 521 forks source link

Broken layout on html to pdf conversion #381

Open jozellrili opened 7 years ago

jozellrili commented 7 years ago

Hello, has someone encounter this issue during conversion of html to pdf? The design looks good in html and is exactly how I like it to be. But when I converted it to pdf, the layout is broken. It's either the image is overlapping each other or they are like what you can see on the picture.

Please help me, I've been doing a lot of adjustments in my css but it doesn't seem to solve the problem.

HTML on the left vs PDF on the right

html_to_pdf

This is my code for converting it to pdf. I'm using ZF2.

public function savePdf($arr = array(), $template, $fileName)
{
    $renderer = $viewRender = $this->serviceLocator->get('ViewRenderer');
    $view = new ViewModel();
    $view->setTerminal(true);
    $view->setTemplate($template);
    $view->setVariables(array('campaigns' => $arr));
    $options = $this->serviceLocator->get('Config')['wkhtmltopdf'];
    $pdf = new Pdf($options['options']);
    $pdf->setOptions(array(
        'orientation' => 'landscape',
        'margin-top' => '0',
        'margin-right' => '0',
        'margin-bottom' => '0',
        'margin-left' => '0',
        'page-width' => '5.60in',
        'page-height' => '10in',
        'dpi' => '120',
        'zoom' => '100',
    ));

    $page = $renderer->render($view);
    //        echo $page; exit;

    $pdf->addPage($page);

    $upload_dir = TEMP_DIR.'/campaigns/';
    if(!file_exists($upload_dir)){
        mkdir($upload_dir, 0777, true);
    }

    $name = $fileName . '.pdf';

    //save file without duplicate number
    if (!$pdf->saveAs($upload_dir.$name)) {
        echo $pdf->getError();
        echo $page;
    }
    return $name;;

}

Thanks!

Progi1984 commented 2 months ago

@jozellrili Have you always the bug ?