wkhtmltopdf Default Settings?
Asked Answered
V

3

5

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?

Varhol answered 11/10, 2017 at 8:5 Comment(1)
Have you checked that the page size is the same for both? Either in exact units or something like Letter v A4?Forwardness
H
5

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

Her answered 11/10, 2017 at 21:56 Comment(1)
Still not working, even with these flags. something is just not right. This is the original URL: tfasim.gdn/test-pdf/0XVCU?html=true This is the output from OSX: tfasim.gdn/good.pdf (not perfect, but looks good) This is the output from Ubuntu: tfasim.gdn/bad.pdf (looks bad!) I am trying to a build a HTML template that will result in a valid and good-looking PDF output via wkhtmltopdf.Varhol
F
5

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 an older version like 0.12.1, and if you still notice the issue, then try to use the --dpi and --disable-smart-shrinking flags.

Faulty answered 15/11, 2017 at 22:4 Comment(0)
T
1

The solution here for me was doing:

--disable-smart-shrinking

and

--page-size Letter
Totalizator answered 2/5, 2018 at 16:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.