如何使用 PDFBOX 从 PDF 表单中获取当前页码? [英] How to get the current Page Number from PDF form using PDFBOX?

查看:82
本文介绍了如何使用 PDFBOX 从 PDF 表单中获取当前页码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 PDFBOX 从 PDF 表单中获取当前页码?

How to get the current Page Number from PDF form using PDFBOX ?

有没有办法获取特定字段的页码?例如,如果一个名为 First name 的文本框出现在 PDF 表单的第 4 页上,是否可以将当前页码检索为 4?

Is there any way to get the particular fields page number? For example, if a text box named First name is present on 4 page of a PDF form is it possible to retrieve current Page number as 4?

对可能的解决方案有任何见解吗?

Any insight into a possible solution?

谢谢

推荐答案

我通常在 pdf 构建期间在每个新页面上填写页码信息.这意味着我知道当前是最后一页的已编辑页面的页码.

I am usually filling the page number information on every new page during the pdf build. This means that I know the page number of the edited page which is currently the last page.

private void addPageNumber(int page, PDPageContentStream content) throws Exception {
  content.beginText();
  String pageNumber = page + "";
  // TODO: move to the needed text position
  content.drawString(pageNumber);
  content.endText();
}

我以当前页数作为参数调用此方法:

I call this method with the current number of pages as a parameter:

addPageNumber(_document.getNumberOfPages(), content);

这篇关于如何使用 PDFBOX 从 PDF 表单中获取当前页码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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