You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Bruno Jullien <br...@moneythumb.com.INVALID> on 2023/06/13 23:49:47 UTC

form fields names and values of some signed PDF

Hi,

I am trying to get the form field names and values of some signed PDF 
(tried with several PDF files) and I cannot see them when using 
getChildren() below.
I only see the signature field!!!

this is the OUTPUT i get from the code below:
FullyQualifiedName: ENVELOPEID_47C2241C2E9B492B892DA48C8ED1BE01
Value: 
org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature@d041cf

Any suggestion is welcome on how to access the form fields.

Here is my code:
=========================
import java.io.File;
import java.io.IOException;
import java.util.List;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
import org.apache.pdfbox.pdmodel.interactive.form.PDField;
import org.apache.pdfbox.pdmodel.interactive.form.PDNonTerminalField;

public class PdfboxGetFormFields {
     public static void main(String[] args) throws IOException {
         PDDocument document = PDDocument.load(new File("myfile.pdf"));
         PDDocumentCatalog docCatalog = document.getDocumentCatalog();
         PDAcroForm acroForm = docCatalog.getAcroForm();

         List<PDField> fields = acroForm.getFields();
         for (PDField field : fields)
         {
             list(field);
         }
         document.close();
     }

     static void list(PDField field)
     {
         System.out.println("FullyQualifiedName: 
"+field.getFullyQualifiedName());
         System.out.println("Value: "+field.getValueAsString());
         if (field instanceof PDNonTerminalField)
         {
             PDNonTerminalField nonTerminalField = (PDNonTerminalField) 
field;
             for (PDField child : nonTerminalField.getChildren())
             {
                 list(child);
             }
         }
     }
}

-- 
Best regards,
Bruno

-- 
Best regards,
Bruno


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: form fields names and values of some signed PDF

Posted by Tilman Hausherr <TH...@t-online.de>.
Hi,
Please share the PDF. (upload to sharehoster)
I also recommend to use getFieldTree() instead of getFields() but your 
approach is also correct. Maybe your file has only field annotations and 
not the actual fields, this happens sometimes.
Tilman

On 14.06.2023 01:49, Bruno Jullien wrote:
> Hi,
>
> I am trying to get the form field names and values of some signed PDF 
> (tried with several PDF files) and I cannot see them when using 
> getChildren() below.
> I only see the signature field!!!
>
> this is the OUTPUT i get from the code below:
> FullyQualifiedName: ENVELOPEID_47C2241C2E9B492B892DA48C8ED1BE01
> Value: 
> org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature@d041cf
>
> Any suggestion is welcome on how to access the form fields.
>
> Here is my code:
> =========================
> import java.io.File;
> import java.io.IOException;
> import java.util.List;
>
> import org.apache.pdfbox.pdmodel.PDDocument;
> import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
> import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
> import org.apache.pdfbox.pdmodel.interactive.form.PDField;
> import org.apache.pdfbox.pdmodel.interactive.form.PDNonTerminalField;
>
> public class PdfboxGetFormFields {
>     public static void main(String[] args) throws IOException {
>         PDDocument document = PDDocument.load(new File("myfile.pdf"));
>         PDDocumentCatalog docCatalog = document.getDocumentCatalog();
>         PDAcroForm acroForm = docCatalog.getAcroForm();
>
>         List<PDField> fields = acroForm.getFields();
>         for (PDField field : fields)
>         {
>             list(field);
>         }
>         document.close();
>     }
>
>     static void list(PDField field)
>     {
>         System.out.println("FullyQualifiedName: 
> "+field.getFullyQualifiedName());
>         System.out.println("Value: "+field.getValueAsString());
>         if (field instanceof PDNonTerminalField)
>         {
>             PDNonTerminalField nonTerminalField = (PDNonTerminalField) 
> field;
>             for (PDField child : nonTerminalField.getChildren())
>             {
>                 list(child);
>             }
>         }
>     }
> }
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org