Snappy和wkhtmltopdf:在页脚中添加页面编号

9

我希望在使用Snappy和Wkhtmltopdf生成的每一页页面底部都有页码,但是我没有找到任何线索。

我可以设置页脚文本(使用选项“footer-center”),但是如何放置页码呢?

2个回答

11

...这里的文档表明,某些标签会被替换为页面编号等内容。


设置[页面]无法工作。问题是如何解决的? - Gogol
8
我是这样使用的:$snappy->setOption('footer-center', 'Page [page]'); - qdelettre
1
--footer-right "Page [page] of [toPage]" --footer-font-size 8 - Bradley Flood
2
@user1254498,那个链接已经失效了。这个链接可能会有所帮助:https://wkhtmltopdf.org/usage/wkhtmltopdf.txt,主题是“页眉和页脚”。 - userfuser

2

将其作为被接受的答案添加只是一个404链接。

根据文档,Wkhtmltopdf为我们提供了许多选项来控制页脚文本放置的位置:

  --footer-center <text>          Centered footer text
  --footer-font-name <name>       Set footer font name (default Arial)
  --footer-font-size <size>       Set footer font size (default 12)
  --footer-html <url>             Adds a html footer
  --footer-left <text>            Left aligned footer text
  --footer-line                   Display line above the footer
  --no-footer-line                Do not display line above the footer
                                  (default)
  --footer-right <text>           Right aligned footer text
  --footer-spacing <real>         Spacing between footer and content in mm
                                  (default 0)

在页脚(或页眉)中,您将拥有许多关键字。
* [page]       Replaced by the number of the pages currently being printed
* [frompage]   Replaced by the number of the first page to be printed
* [topage]     Replaced by the number of the last page to be printed
* [webpage]    Replaced by the URL of the page being printed
* [section]    Replaced by the name of the current section
* [subsection] Replaced by the name of the current subsection
* [date]       Replaced by the current date in system local format
* [isodate]    Replaced by the current date in ISO 8601 extended format
* [time]       Replaced by the current time in system local format
* [title]      Replaced by the title of the of the current page object
* [doctitle]   Replaced by the title of the output document
* [sitepage]   Replaced by the number of the page in the current site being converted
* [sitepages]  Replaced by the number of pages in the current site being converted

所以举个例子,为了在页面页脚右侧添加一个连续的页码,您可以在KnpSnappy中这样做:
$snappyPdf->setOption('footer-right', '[page]');

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接