我需要获取pdf文档中包含数字签名的页面的页面索引。如何使用Apache PDFBox获得它?
答案 0 :(得分:0)
try (PDDocument doc = PDDocument.load(new File("....")))
{
PDPageTree pageTree = doc.getPages();
PDAcroForm acroForm = doc.getDocumentCatalog().getAcroForm();
for (PDField field : acroForm.getFieldTree()) // null check omitted
{
if (field instanceof PDSignatureField)
{
PDSignatureField sigField = (PDSignatureField) field;
for (PDAnnotationWidget widget : sigField.getWidgets())
{
PDPage page = widget.getPage();
if (page != null)
{
System.out.println("Signature on page " + (pageTree.indexOf(widget.getPage()) + 1));
}
}
}
}
}