Skip to content

Broken layout on html to pdf conversion #381

@jozellrili

Description

@jozellrili

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!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions