0

If I have a 2 page pdf document with a signature field (signature1), how can I parse the document using pdfBox to find which page contains the signature field (either blank or signed). OR how can I find the page No for signature1 in a multi page pdf document?

I can successfully add a signature field to page 2:

page = doc.getPage(1)

widget = signatureField.getWidgets().get(0)

widget.setAppearance(appearanceDictionary)

widget.setRectangle(rect)

//set it to page 2

widget.setPage(page)

from code example: https://www.programcreek.com/java-api-examples/?api=org.apache.pdfbox.pdmodel.interactive.form.PDSignatureField

user2677034
  • 624
  • 10
  • 20
  • 1
    possible duplicate of [Get page index of pdf page containing digital signature](https://stackoverflow.com/questions/51530482/get-page-index-of-pdf-page-containing-digital-signature) – raviraja Mar 31 '20 at 05:23
  • have answered this question here: https://stackoverflow.com/questions/22074449/how-to-know-if-a-field-is-on-a-particular-page – user2677034 Mar 31 '20 at 21:20

1 Answers1

1

assuming you have the widget and it is not null:

PDPage signaturePage = widget.getPage();
int pageIndex = document.getPages().indexOf(signaturePage);

now you have the 0-based page number.

Tilman Hausherr
  • 17,731
  • 7
  • 58
  • 97
  • If I remember correctly, the widget **P** page property is optional as far as the pdf specification is concerned. So if **P** is not present, does `widget.getPage()` meanwhile search the page? Or does it simply return `null`? – mkl Mar 31 '20 at 07:09
  • See also your [older answer](https://stackoverflow.com/a/36894982/1729265) I closed this as a duplicate of – mkl Mar 31 '20 at 07:24
  • Yeah, the older answer is really better. No, getPage() doesn't search, and it returns null. – Tilman Hausherr Mar 31 '20 at 07:27