简体   繁体   中英

pdfbox PDFBox 2.0.0 get field position

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" (eg you enter your name once, but it appears on several pages of a complex form).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM