Wkhtmltopdf - same configuration of different output

I am using wkhtmltopdf via instant in my project. On my local machine, the output is correct: https://www.dropbox.com/s/ml9cp2pa6d8wja5/Zaznaczenie_100.png?dl=0

but when I deploy the project to the server, the PDF format looks completely different, maybe the width of the viewport is different: https://www.dropbox.com/s/8g0c29bzaxltyb9/170311_123139_4775.jpg?dl=0

Both systems use exactly the same configuration to generate pdf.

My questions:

  • How can I check what is the default whtmltopdf setting on a specific machine?
  • How can I resize the viewport, so my output will be exactly the same on different machines?

I set the width and height of the output page manually (21 cm and 50 cm, respectively). I tried different combinations with the DPI parameter, but it seems to have no effect.

I use the PHP wkhtmltpdf wrapper - snappy - but I checked and I get the same output in the console, so the wkhtmltopdf problem is related, not instantaneous.

+5
source share
2 answers

One of the main things that seem different in your PDF output is the font. wkhtmltopdf requires the fonts to be installed on your operating system just as a browser would require. It is possible that differences in spacing and font sizes affect the layout of your page. First you should see what fonts you are trying to use in the source file and install them on your server. A good start is to install basic Microsoft fonts from here or from server distribution repositories.

Alternative way: use @font-face directives in your stylesheets of the source file to refer to fonts from the URL without installing them on your server:

 @font-face { font-family: 'Roboto'; font-style: normal; font-weight: 400; src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/CWB0XYA8bzo0kSThX0UTuA.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215; } 

For Google web fonts, you can import your stylesheets instead:

 <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet" /> 

Another thing to check is the wkhtmltopdf versions on your workstation and on your server. Running wkhtmltopdf --version will tell you your installed version. Your server may have an outdated version of wkhtmltopdf installed. The easiest way to install the latest version of wkhtmltopdf with the necessary functions is here , where you can download statically linked Linux files for any distribution.

The last thing to try is to use different arguments --margin-top , --margin-right , --margin-bottom and --margin-left . There is also a flag called --viewport-size , which can help get better results.

 wkhtmltopdf --viewport-size 1024x768 page.html output.pdf 

If you use the same version of wkhtmltopdf both on your workstation and on the server, these configuration parameters should not matter, since you stated that you are using the same configuration for both already.

0
source

To create a backup of Candy Gumdrop, we tried the fields, but our answer turned out to be an administrator who reused a 32-bit copy of wkhtmltopdf on the production server, and not the 64-bit version that I used. All results of "wkhtmltopdf --version" must match not only the version number.

0
source

Source: https://habr.com/ru/post/1265399/


All Articles