Reputation: 49
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
Upvotes: 4
Views: 1555
Reputation: 18851
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).
Upvotes: 2