如何为 Web 文档的每个打印页面添加页眉和页脚(没有浏览器限制)? [英] How to add a header and footer to each printed page of a web document (without browser restriction)?

查看:84
本文介绍了如何为 Web 文档的每个打印页面添加页眉和页脚(没有浏览器限制)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 CakePHP 构建一个 web 应用程序(并非真正密切相关,但无论如何),其任务之一是生成一个网页,其中包含存储在数据库中的一堆内容(文章集合).我需要能够打印此文档并在打印文档时为每一页包含一个简单的页眉和页脚.

I'm building a webapp with CakePHP (not really germane, but anyway) whose mission is, among other things, to produce a single web page containing a bunch of content that's stored in the database (a collection of articles). I need to be able to print this document and include a simple header and footer for each page when the document is printed.

此外,我无法保证文章集合中单个项目的渲染长度会小于一张纸的渲染长度,因此我无法像这样对每篇文章进行书尾:

Additionally, I have no way of guaranteeing that the rendered length of a single item in the collection of articles will be less than that of a piece of paper, so I won't be able to bookend each article like so:

<?php echo $header; ?>
<?php echo $article; // etc. ?>
<?php echo $footer; ?>

这里的好处是我将是唯一一个打印这个的人(实际上是将它保存为 PDF),所以任何建议的解决方案都不需要与任何仍然发生的神秘浏览器一起使用周围(IE6 等).

The plus side here is that I'm going to be the only person printing this (and saving it as a PDF, actually), so any proposed solution won't be required to work with any arcane browsers that still happen to be around (IE6, etc.).

(在将此问题标记为此类似问题的副本之前,请注意我'我不尝试使用 IE6 并且我正在打印的单个内容位的长度很可能超过单个打印页.因此,针对该问题的基于表格的解决方案在这里不适用——至少,就目前而言我看得出来.)

(Before you mark this question as a duplicate of this similar question, note that I'm not trying to work with IE6 and the individual bits of content I'm printing may well exceed a single printed page in length. As such, the table-based solution to that problem is not applicable here -- at least, as far as I can tell.)

如果这需要我做一些时髦的算术来将一个大的连续内容块分解成大约大小的页面"(显然,这将由页脚+分页符+页眉组合分隔),我'如果没有更明智的方法来解决这个问题,我可以接受.

If this is going to require me to do some funky arithmetic to break up a large contiguous block of content into approximately-sized "pages" (which would be delimited by the footer+pagebreak+header combination, obviously), I'm fine with that provided there isn't a more sane way to go about it.

预先感谢您 - 如果您认为我可以提供更多信息或以其他方式使这种情况更容易解决,请发表评论.

Thank you in advance - please comment if you feel I could provide more information or otherwise make this situation easier to resolve.

推荐答案

要处理 PDF 端,请使用 wkhtmltopdf - 除了在生成 PDF 方面非常出色之外,还有对页眉和页脚的可靠支持.

To handle the PDF side, use wkhtmltopdf - besides being fantastic in general for generating PDFs, there's solid support for a header and footer.

查看手册中的页眉和页脚选项"部分:http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf-0.9.9-doc.html

Take a look at the "Headers And Footer Options" section here in the manual: http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf-0.9.9-doc.html

当然,这假设您可以在服务器上运行自定义可执行文件.

Of course, this presumes that you can run custom executables on your server.

这篇关于如何为 Web 文档的每个打印页面添加页眉和页脚(没有浏览器限制)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆