将内容添加到最后一页的底部
我正在使用 wkhtmltopdf 从 HTML 创建 PDF 报告,我需要创建一个遵循以下模式的自定义报告:
- 第一页顶部的一些信息。
- 一个可以有 1 到 n 行的表(它应该使用它需要的任意数量的页面)
- 最后一页末尾的一些信息。
把所有这些放在一起就可以了。但是,由于步骤 3 信息立即出现在表格之后,有没有办法将内容放在页面末尾?
我什至不确定这个解决方案是基于 CSS 还是基于 wkhtmltopdf。
I am using wkhtmltopdf to create PDF reports from HTML, I need to create a custom report that follows this pattern:
- Some information at the top of the first page.
- A table that can have 1 to n rows (it should use any amount of pages it needs)
- Some information at the end of the last page.
Putting all this together does the trick; however because step 3 info appears immediately after the table, is there a way to put the content at the end of the page?
I am not even sure if this solution is CSS based or wkhtmltopdf based.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
http://madalgo.au.dk/~jakobt/wkhtmltoxdoc /wkhtmltopdf-0.9.9-doc.html
查看“页脚和页眉”部分。
您可以使用
--footer-html
结合一些 JavaScript 来执行此操作。我的
footer.html
内容基于上面链接中提供的示例:http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf-0.9.9-doc.html
Take a look at "Footers And Headers" section.
You can use
--footer-html
combined with some JavaScript to do this.I based the contents of my
footer.html
on the example provided in the link above:这是一项相当困难的任务,我认为你目前无法用纯 CSS 来解决这个问题(尽管我很乐意被证明是错误的)。
此外,对确定分页符(
page-break-inside:void;
)的支持也不是最好的。事实上,到目前为止我认为它不适用于表格。您可能最终会在分页器周围分割出一些行。 (Webkit 渲染一个 PDF,然后将其切成单页,主要不管边缘是什么...)我对这个困境的解决方案是创建单个页面大小的占位符
div
,然后在生成 PDF 之前使用一些编程语言在这些占位符之间分配内容。在最后一个这样的包装器中,您可以在底部添加绝对定位的页脚。
这是一些示例代码:
This a quite difficult task and I don't think you can solve this with pure CSS at this time (though I would love to be proven wrong).
Also the support for determined page breaks (
page-break-inside: avoid;
) isn't the best. In fact I don't think it works with table so far. You probably would end up with some rows split around the pagebrake. (Webkit renders one PDF and then cuts it into single pages, mostly regardless whats on the edge...)My solution to this dilemma was to create single placeholder
div
s in the size of a single page and then distribute the content with some programming langugae between these placeholders before generating the PDF.In the last of such wrappers you could then add an absolute positioned footer at the bottom.
Here is some sample code:
我在理解你的意思时遇到了一些困难。内容“紧接在表格之后”和“在表格末尾”有什么区别?
tfoot
元素可能是您正在寻找的:如果不是,您能详细说明吗?您拥有的 HTML 的简短示例或它的外观以及您希望它的外观的图片可能会有所帮助。
I’m having a little trouble following what you mean. What’s the difference between the content being “immediately after the table” and “at the end of the table”?
The
tfoot
element might be what you’re looking for:If not, could you elaborate? A short example of the HTML you have or pictures of what it looks like and what you want it to look like might help.