Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fix wkhtmltopdf headers clipping content?

Tags:

wkhtmltopdf

My headers often clip content so that the content below it is not completely visible, it appears as though the page continues underneath the header before the header ends and as a result, not all of the content is shown.

Image demonstrating the problem, content is shown below the header

Is there a CSS rule I can use for this? Or a cmd argument for wkhtmltopdf? Or any other way?

like image 424
Joel Peltonen Avatar asked Jul 12 '12 08:07

Joel Peltonen


2 Answers

I have learned that this is actually a known issue and is unlikely to be changed in a while. The workaround is to use style="margin:0; padding:0;" in the header <body> element. Another workaround would be to experiment with the --header-spacing n parameter. Yet another way is to wrap all top-page elements and add margin there, but that is a very bad an non-dynamic idea.

For for further information see:

http://code.google.com/p/wkhtmltopdf/issues/detail?id=182 (duplicate of this issue) http://code.google.com/p/wkhtmltopdf/issues/detail?id=175 (the origins of this issue) http://code.google.com/p/wkhtmltopdf/issues/detail?id=523 (header-spacing workaround)

like image 72
Joel Peltonen Avatar answered Sep 24 '22 01:09

Joel Peltonen


Worked for me with <body style='height:50px;overflow:hidden;margin:0;padding:0;'> in the header and footer and the --header-spacing 30 -T 45mm parameters.

like image 23
user3536077 Avatar answered Sep 25 '22 01:09

user3536077