4
votes

I am using laravel-snappy as a wrapper for wkhtmltopdf for creating PDFs out of HTML.

While running the same code with the same configuration, I am getting different outputs:

CentOS output: enter image description here (centered correctly but with big margin at the bottom)

macOS output: enter image description here (right part is cropped, and also theres a big margin at the bottom)

Both environments are using wkhtmltopdf 0.12.4 (with patched qt), any ideas for this difference?

3
Have you checked that the page size is the same for both? Either in exact units or something like Letter v A4?Phil

3 Answers

4
votes

There are a couple of things you can try:

--disable-smart-shrinking

--dpi 96 Experiment with this number to get consistent results (could be around 130)

--zoom 1.33

Set a font family that is common across platforms (see http://www.apaddedcell.com/sites/www.apaddedcell.com/files/fonts-article/final/index.html). Set with font-family: xxx, xxx, xxx, sans-serif

Another thing that has been mentioned before is to set the page dimensions in px instead of mm --page-width 1588px --page-height 1210px

3
votes

Wkhtmltopdf relies on Qt Webkit to do the headless rendering of a PDF. Qt Webkit is cross-platform, but uses different APIs between CentOS and MacOS.

There is a Github issue that, while closed, still has people reporting similar problems in the 12.4 version when using an X11 version of Qt Webkit. The last comment is from someone who reported that solutions like @kerrin's do not work for them, so maybe you are having the same problem.

I am running an older version of Wkhtmltopdf on CentOS in production and MacOS locally, and have not noticed problems like this.

Try and older version like 0.12.1, and if you still notice the issue, then try to use the --dpi and --disable-smart-shrinking flags.

1
votes

The solution here for me was doing:

--disable-smart-shrinking

and

--page-size Letter