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?
Asked
Active
Viewed 672 times
1
-
1IMHO that was a valid question, except that the OP misused the itext label. – Tilman Hausherr Jul 26 '18 at 08:44
-
1Indeed, even though the question is short, it contains all the required information. – mkl Jul 27 '18 at 16:12
1 Answers
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));
}
}
}
}
}

Tilman Hausherr
- 17,731
- 7
- 58
- 97
-
1Actually the widget page attribute is optional, so `page` may indeed be `null` in spite of the signature being visible on some page. For such a case you should use the _plan B_ illustrated in [this answer](https://stackoverflow.com/a/22132921/1729265) and [this answer](https://stackoverflow.com/a/36894982/1729265). – mkl Jul 27 '18 at 16:21