0

I am using iText to add and read acrofields. But it runs into issue where page size within document is variable. So for eg. Pdf document with 3 pages -> letter, legal , letter Its unable to get all acrofields. But if all pages legal or all pages letter,works perfectly Here is code which i use to read the acrofields.

            String pdf  = "D:\\1350211.pdf";
    PdfReader reader = new PdfReader( pdf );
    AcroFields fields = reader.getAcroFields();
    Set<String> fldNames = fields.getFields().keySet();
    List<AcrofieldModel> lists = new ArrayList<>();

    for (String fldName : fldNames) {

        List<FieldPosition> position = fields.getFieldPositions(fldName);
        float lowerLeftX = position.get(0).position.getLeft(); 
        float lowerLeftY = position.get(0).position.getBottom();
        float upperRightX = position.get(0).position.getRight();
        float upperRightY = position.get(0).position.getTop();
        float fieldLength = Math.abs(upperRightX-lowerLeftX);

      AcrofieldModel acrofieldModel = new AcrofieldModel(fldName, fields.getField( fldName ), "(X:"+lowerLeftX + " , Y:"+lowerLeftY +") ", fieldLength);
      lists.add(acrofieldModel);
    }


    return lists;
  • 2
    The page size is no factor in AcroForm access. Probably the different sizes in the problem PDFs merely are a symptom of the PDF being assembled from different source PDFs, and probably the assembler somehow did a bad job. The long and the short of it, share an example PDF with that behavior to allow us analyze the issue. – mkl Feb 05 '19 at 19:57
  • 1
    That being said, you are aware that `fields.getFieldPositions(fldName)` might be `null` or empty? Your code would fail in such situations... – mkl Feb 05 '19 at 20:03

0 Answers0