pdfbox PDFBox 2.0.0 获取字段位置
pdfbox PDFBox 2.0.0 get field position
如何使用 PDFBox 2.0.0 获取字段位置?
在 Pdfbox 1.8.11 中,我是这样工作的:
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();
现在,f.getWidget() 不再工作了..
谢谢
罗恩
使用
f.getWidgets().get(0)
获取字段的第一个小部件。大多数时候只有一个。如果表单字段是 "mirrored",则可以有多个(例如,您输入一次姓名,但它会出现在复杂表单的多个页面上)。
如何使用 PDFBox 2.0.0 获取字段位置? 在 Pdfbox 1.8.11 中,我是这样工作的:
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();
现在,f.getWidget() 不再工作了..
谢谢 罗恩
使用
f.getWidgets().get(0)
获取字段的第一个小部件。大多数时候只有一个。如果表单字段是 "mirrored",则可以有多个(例如,您输入一次姓名,但它会出现在复杂表单的多个页面上)。