Tuesday, March 14, 2017

Laravel wkhtmltopdf different results

I'm using wkhtmltopdf and Snappy in a Laravel project to generate pdf's. However, I'm getting different results for some reason!

When I generate a PDF in my Windows localhost environment I get the right result, I get the following:

enter image description here

This is the result I expect, so on Windows it's working fine. However, when I try this on the hosted server running Ubuntu, I get the following result:

enter image description here

Code

In my controller:

$view = view('pages.qr.sheet', [
    'qrs' => $qrs,
    'codes' => $codes,
    'checksums' => $checksums,
    'image' => public_path().'\\'.$sheet->image]);


return SnappyPdf::loadHTML($view)
    ->stream('my.pdf', array('Attachment'=>0));

My Snappy config file:

'pdf' => array(
    'enabled' => true,
    'binary'  => "\"".base_path(env('SNAPPY_PATH', '/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'))."\"",
    'timeout' => false,
    'options' => array(
        'orientation' => 'landscape',
        'enable-javascript' => true,
        'javascript-delay' => 0,
        'no-stop-slow-scripts' => true,
        'no-background' => false,
        'lowquality' => false,
        'encoding' => 'utf-8',
        'images' => true,
        'cookie' => array(),
        'dpi' => 300,
        'image-dpi' => 300,
        'enable-external-links' => true,
        'enable-internal-links' => true
    ),
    'env'     => array(),
),

Why do the results differ so much? The Windows version looks perfect but when I run it on my hosted webserver it doesn't fit on one page. Looks like it's a problem with DPI or something! Hope someone can help so both results look the same.



via Markinson

Advertisement