Cannot set wkhtmltopdf margins (top and bottom)

I am using wkhtmltopdf 0.10.0 rc2 on Ubuntu (Linux 3.2.0-24-generic #38-Ubuntu x86_64 GNU/Linux). The problem I'm experiencing is that I can't create PDFs with margin-top or margin-bottom. I'm not getting any errors.

I'm using the following commands:

wkhtmltopdf -T 50 -B 50 http://google.com ./test.pdf
wkhtmltopdf --margin-top 50 --margin-bottom 50 page.html ./test.pdf

However, when I try the following, margin-left and margin-right works perfectly (but still no margin-top or margin-bottom)

wkhtmltopdf -L 50 -R 50 -T 50 -B 50 page.html ./test.pdf

It doesn't matter which URL or page I try to convert. How can I set a margin-top and margin-bottom?


I believe you're missing units. Try:

wkhtmltopdf -L 50mm -R 50mm -T 50mm -B 50mm page.html ./test.pdf

mm, of course, is millimeters. You could also do 0.5in or 2cm, something like that.


I'm super late here, but I ran into a similar issue (I kept changing the margins to no effect) and after a lot of work I figured out my issue: My content was of a limited size, so the margins didn't matter.

I was using Bootstrap 3 to create a layout for my PDF, and in Bootstrap I had a <div class="container"> element wrapping the whole page. Containers in Bootstrap have natural padding around them, so my content was only something like 668 pixels wide (despite wkHTMLtoPDF loading the page in an 800-pixel wide browser). When I replaced this with <div class="container-fluid"> my margins suddenly started working

Just something worth checking