问题
I have the requirement to get the page index of the page containing a digital signature in a pdf document. How can I get it using Apache PDFBox?
回答1:
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));
}
}
}
}
}
来源:https://stackoverflow.com/questions/51530482/get-page-index-of-pdf-page-containing-digital-signature