Fix wkhtmltopdf headers clipping content?

Joel Peltonen picture Joel Peltonen · Jul 12, 2012 · Viewed 17.2k times · Source

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?

Answer

Joel Peltonen picture Joel Peltonen · Jul 17, 2012

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)