如何在 wkhtmltopdf 中使用页脚和页眉?

问题描述:

我遇到了一种情况,我不得不在生成的 PDF 打印输出中使用页脚和页眉.CSS 解决方案仅适用于第一页.我发现的唯一信息是 WKPDF 根本不支持它,但这可以追溯到 2009 年,所以可能会发生一些变化.

I encountered a situation where I had to use footers and headers in my generated PDF printounts. CSS solution works for the first page only. And the only information I found is that it is not supported in WKPDF at all, but this dates back to 2009, so something might have changed.

有人成功过吗?

谢谢.

Wkhtmltopdf 甚至支持非常复杂的页眉和页脚.

Wkhtmltopdf does support even very complex headers and footers.

wkhtmltopdf.exe -T 50mm --header-html www.google.com www.*.com test.pdf && test.pdf

该命令将 www.google.com 上的页面用作 www.*.com 的每个页面的 50 毫米标题.

That command uses the page at www.google.com as a 50mm header for www.*.com for every page.

注意:如果您使用自定义页面作为页眉/页脚,则需要在页眉/页脚 HTML 的开头添加

Note: If you use a custom page for the header/footer, you need to add <!DOCTYPE HTML> in the beginning of your header/footer HTML!