GordonZ
GordonZ

Reputation: 374

How to set margin top for header?

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?

Upvotes: 20

Views: 31084

Answers (3)

Mxooo
Mxooo

Reputation: 11

-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>

Upvotes: 1

Ironluca
Ironluca

Reputation: 3762

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.

Upvotes: 33

tumbudu
tumbudu

Reputation: 831

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

wkhtmltopdf -B 13 -L 13 -R 13 -T 53  /tmp/e0cb9c4597860b5abfbf2bafc1000d5a.html /tmp/e0cb9c4597860b5abfbf2bafc1000d5a.pdf

Upvotes: 11

Related Questions