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

[亡魂溺海] 提交于 2019-12-23 05:17:30

问题


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

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?

Thanks


回答1:


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);


来源:https://stackoverflow.com/questions/14831695/how-to-get-the-current-page-number-from-pdf-form-using-pdfbox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!