2016-04-22 63 views
0

如何獲得PDFBox 2.0.0的字段位置? 與PDFBOX 1.8.11它的工作原理我這個樣子:pdfbox PDFBox 2.0.0獲取字段位置

  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()不要再工作..

感謝 羅恩

回答

0

使用

f.getWidgets().get(0) 

獲得一個字段的第一個部件。大多數時候只會有一個。如果表單字段是「鏡像的」(例如,您輸入了一次您的名字,但它出現在複雜表單的多個頁面上),則可以有幾個字段。