PDF page size created by wkhtmltopdf is 25% smaller than expected

I use the following CSS webpage that the user will print:

.page { padding: 1.04cm 1.54cm 1.04cm 1.54cm; width: 21cm; min-height: 29.7cm; height: 29.7cm; } 

When using the preview in Google Chrome or IE, it looks great: the content of the page fills a full 21 cm wide and 29 cm from the height of the page.

However, PDF content created from the same page using wkhtmltopdf occupies only 75% of the available width, as if the centimeters for wkhtmltopdf were different.

enter image description here

I run wkhtmltopdf without any additional options.

If I set the width and height to 100% , it works, but the font size still remains small. Thus, I also need to increase the font size from 9pt to 12pt in order to achieve the same look in PDF format as in the Chrome preview.

I confirmed in my PDF reader that the page size of the PDF file is actually 21x29 cm, the standard size is A4.

What am I missing? “Centimeters” mean different things to the browser and to wkhtmltopdf ?

+6
source share
1 answer

This wkhtmltopdf argument solved the problem:

 --disable-smart-shrinking 

Not so smart.

+12
source

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


All Articles