-->

wkhtmltopdf css sizes in cm/mm

2020-06-08 05:37发布

问题:

I use wkhtmltopdf to produce A4 sized PDFs. When I create a <div> tag and set its style to height: 297mm; width: 210mm (which is the defined size of A4), set wkhtmltopdf's margin settings to 0 (wkhtmltopdf -B 0 -T 0 -L 0 -R 0 ...) and give the <div> a red background, I can see a thin white line at the bottom of the page, i.e. the <div> is not filling the page completely. This is happening consistently with 0.11.0 rc1 (the latest version) on Debian and with 0.10.0 rc2 on Mac OS X.

Has anyone else seen this? Is this a known problem, or is there a workaround?

回答1:

I had a method that worked for me that used margins.

style="margin:0,auto"

If that doesn't work try:

style="margin:0,auto,0,auto"


回答2:

Perhaps try increasing the height of the <div> a fraction of a mm?

height: 297.5mm or height: 298mm instead?

Let me know if that works.



回答3:

Try set <div> element style="margin: 0;" in my case this helps...