How do I get all the fields and value from a PDF file using iText?

前端 未结 2 521
情话喂你
情话喂你 2020-12-10 23:02

Using the code below, I\'m trying to get all the fields and their values, but it\'s only returning the field values. What do I need to do to get both?

   pa         


        
2条回答
  •  醉酒成梦
    2020-12-10 23:31

    To get all the fields and their values with iText:

    // you only need a PdfStamper if you're going to change the existing PDF.
    PdfReader reader = new PdfReader( pdfPath );
    
    AcroFields fields = reader.getAcroFields();
    
    Set fldNames = fields.getFields().keySet();
    
    for (String fldName : fldNames) {
      System.out.println( fldName + ": " + fields.getField( fldName ) );
    }
    

    Beyond that, it would help if we could see a PDF that is giving you trouble.

提交回复
热议问题