How to set margin top for header?
Asked Answered
B

3

19

The --margin-top option is for the contents margin, but I would like to set the margin from the top of the page to the header. The project I'm working on allows users to create header and footer themselves, so the height of the header or footer is dynamic.

I don't know how to do it so can anyone help?

Bikaner answered 20/9, 2016 at 12:16 Comment(0)
J
32

The built-in options for top margin are

  1. --margin-top (as you mentioned above) and
  2. --header-spacing Spacing between header and content in mm (refer: http://wkhtmltopdf.org/usage/wkhtmltopdf.txt).

None of them will probably help you as there is no option (at least to my knowledge) that can explicitly set some margin from the top of the page to the header. However, in your case, you could explore --header-html <url> and add a html header. This can take an HTML where you could probably set the custom header and add space/margin accordingly and then the HTML gets displayed in on the header.

Jarlathus answered 20/9, 2016 at 12:41 Comment(3)
+1. You can just use a web page as header, you will set margin from the top of the page using <body> margin or padding on the header HTML contentPeaceful
Thank you, I did try it but because I forgot to remove the margin-top option it didn't work. After I removed the option it works now.Bikaner
I was struggling with this, too - adding the margin-top style to the header and removing the --margin-top switch for wkhtmltopdf worked for me. Thanks, @PeacefulPotheen
B
10

Use -T -B -L and -R for margins.

wkhtmltopdf -B 13 -L 13 -R 13 -T 53  /tmp/e0cb9c4597860b5abfbf2bafc1000d5a.html /tmp/e0cb9c4597860b5abfbf2bafc1000d5a.pdf
Bongbongo answered 7/7, 2017 at 5:13 Comment(2)
Works, thanks! the other answer is not working for me, no matter margn-top is used or notMitsue
The rest of them is working except bottom.Exsect
C
1

-T 10 is working by adding an empty HTML.

wkhtmltopdf.exe -T 10 --header-html header.html  content.html generatedpdf.pdf

the empty html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <META http-equiv="Content-Type" content="text/html; charset=utf-16">
  </head>
  <body >
  </body>
</html>
Castra answered 30/5, 2022 at 14:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.