Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pdfbox PDFBox 2.0.0 get field position

Tags:

java

pdfbox

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

like image 487
Ron Partuk Avatar asked Oct 23 '25 03:10

Ron Partuk


1 Answers

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).

like image 91
Tilman Hausherr Avatar answered Oct 26 '25 05:10

Tilman Hausherr