how i get field position with PDFBox 2.0.0? in with Pdfbox 1.8.11 it works me like this:
String formTemplate = "Template.pdf";
PDDocument pdfDocument = PDDocument.load(new File(formTemplate));
PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
PDAcroForm acroForm = docCatalog.getAcroForm();
String fieldName = "Name";
PDField f = acroForm.getField(fieldName);
if (f != null) {
PDRectangle r = f.getWidget().getRectangle();
float llx = r.getLowerLeftX();
float lly = r.getLowerLeftY();
float urx = r.getUpperRightX();
float ury = r.getUpperRightY();
Now, f.getWidget() Dont work anymore..
thanks ron
use
f.getWidgets().get(0)
to get the first widget of a field. Most of the time there will be only one. There can be several if form fields are "mirrored" (e.g. you enter your name once, but it appears on several pages of a complex form).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With