PDFbox内容流是按页面完成的,但这些字段来自目录中的表单,该表格来自pdf文档本身.所以我不确定哪些字段在哪些页面上,并且导致将文本写入错误的位置/页面.
即.我正在处理每页的字段,但不确定哪些字段在哪些页面上.
有没有办法告诉哪个字段在哪个页面上?或者,有没有办法获得当前页面上的字段?
谢谢!
标记
代码段:
PDDocument pdfDoc = PDDocument.load(file);
PDDocumentCatalog docCatalog = pdfDoc.getDocumentCatalog();
PDAcroForm acroForm = docCatalog.getAcroForm();
// Get field names
List<PDField> fieldList = acroForm.getFields();
List<PDPage> pages = pdfDoc.getDocumentCatalog().getAllPages();
for (PDPage page : pages) {
PDPageContentStream contentStream = new PDPageContentStream(pdfDoc, page, true, true, true);
processFields(acroForm, fieldList, contentStream, page);
contentStream.close();
}
Run Code Online (Sandbox Code Playgroud)