如何使用iText在每个页面上添加总页数? [英] How to add total page number on every page with iText?

查看:1123
本文介绍了如何使用iText在每个页面上添加总页数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用iText在每个页面上添加总页数?

How to add the total page number on every page with iText?

推荐答案


  1. 处理输出从 PdfWriter 字节流首先显示虚拟页数。

  2. 字节流创建 PdfReader ,调用 PdfReader.getNumberOfPages 获取实际的页数。

  3. 重新创建PDF输出,知道页数是多少,相应地更改页脚。

  1. Process the output from a PdfWriter to a bytestream first with a dummy page count.
  2. Create a PdfReader from that bytestream, calling PdfReader.getNumberOfPages to get the actual page count.
  3. 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屋!

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