Fix wkhtmltopdf headers clipping content?

2019-03-12 11:06发布

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?

标签: wkhtmltopdf
5条回答
姐就是有狂的资本
2楼-- · 2019-03-12 11:08

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)

查看更多
Anthone
3楼-- · 2019-03-12 11:23

This worked for me
thead{display: table-header-group;}
tfoot {display: table-row-group;}
tr {page-break-inside: avoid;}

查看更多
Evening l夕情丶
4楼-- · 2019-03-12 11:24

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.

查看更多
smile是对你的礼貌
5楼-- · 2019-03-12 11:29

Make sure you have <!doctype html> at the start of your header/footer page. Webkit renders the page in quirksmode otherwise.

查看更多
SAY GOODBYE
6楼-- · 2019-03-12 11:30

this worked for me

--header-spacing XX -T XXmm

XX should be the same value eq: --header-spacing 20 -T 20mm

查看更多
登录 后发表回答