Page size in PDF generated by wkhtmltopdf is 25% smaller than expected

user6269864 picture user6269864 · Nov 8, 2016 · Viewed 11k times · Source

I am using the following CSS a web page 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 Print Preview in Google Chrome or IE, it looks fine: the content in the page fills in the full 21cm of width and 29cm of height of the page.

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

enter image description here

I run wkhtmltopdf without any extra options.

If I set the width and height to 100%, it works, but the font size is still small. Thus, I also have to increase the font size from 9pt to 12pt to achieve about the same look in the PDF as in Chrome's print preview.

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

What am I missing? Are "centimeters" meaning different things for the browser and for wkhtmltopdf?

Answer

user6269864 picture user6269864 · Nov 8, 2016

This argument to wkhtmltopdf solved the issue:

--disable-smart-shrinking

Not so smart after all.