如何使用iText在每个页面上添加总页数? [英] How to add total page number on every page with iText?
本文介绍了如何使用iText在每个页面上添加总页数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用iText在每个页面上添加总页数?
How to add the total page number on every page with iText?
推荐答案
- 处理输出从
PdfWriter
到字节流
首先显示虚拟页数。 - 从
字节流
创建PdfReader
,调用PdfReader.getNumberOfPages
获取实际的页数。 - 重新创建PDF输出,知道页数是多少,相应地更改页脚。
- Process the output from a
PdfWriter
to abytestream
first with a dummy page count. - Create a
PdfReader
from thatbytestream
, callingPdfReader.getNumberOfPages
to get the actual page count. - Recreate the PDF output, knowing what the page count will be, changing the footer accordingly.
这很麻烦,但没有简单的方法可以在没有两遍方法的情况下知道页数。有关详细信息,请参阅示例代码关于操纵PDF。
It's messy, but there's no easy way to know the page count without a two-pass approach. See the example code for details on manipulating PDFs.
这篇关于如何使用iText在每个页面上添加总页数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文