com.groupdocs.parser.data

Class DocumentData

    • Constructor Detail

      • DocumentData

        public DocumentData(Iterable<FieldData> fields)
        Initializes a new instance of the FieldData class.
        Parameters:
        fields - The collection of fields data.
    • Method Detail

      • getCount

        public int getCount()
        Gets the total number of the fields data.
        Returns:
        An integer value that represents the total number of the fields data.
      • get

        public FieldData get(int index)
        Gets the field data by an index.

        Iteration via all the fields:

        // Print all extracted data
         for (int i = 0; i < data.getCount(); i++) {
             // Print field name
             System.out.print(data.get(i).getName() + ": ");
             // As we have defined only text fields in the template,
             // we cast PageArea property value to PageTextArea
             PageTextArea area = data.get(i).getPageArea() instanceof PageTextArea
                     ? (PageTextArea) data.get(i).getPageArea()
                     : null;
             System.out.println(area == null ? "Not a template field" : area.getText());
         }
         

        FieldData class represents field data. Depending on the field PageArea property can contain any of the inheritors of PageArea class. For example, Parser.parseForm() method extracts only text fields:

        // Create an instance of Parser class
         try (Parser parser = new Parser(Constants.SampleFormsPdf)) {
             // Extract data from PDF document
             DocumentData data = parser.parseForm();
             // Check if form extraction is supported
             if (data == null) {
                 System.out.println("Form extraction isn't supported.");
                 return;
             }
             // Iterate over extracted data
             for (int i = 0; i < data.getCount(); i++) {
                 System.out.print(data.get(i).getName() + ": ");
                 PageTextArea area = data.get(i).getPageArea() instanceof PageTextArea
                         ? (PageTextArea) data.get(i).getPageArea()
                         : null;
                 System.out.println(area == null ? "Not a template field" : area.getText());
             }
         }
         
        Parameters:
        index - The zero-based index of the field.
        Returns:
        An instance of FieldData class.
      • getFieldsByName

        public List<FieldData> getFieldsByName(String fieldName)
        Returns the collection of field data where the name is equal to fieldName.

        Find fields by a field name:

        // Print prices
         System.out.println("Prices:");
         for (FieldData field : data.getFieldsByName("Price")) {
             PageTextArea area = field.getPageArea() instanceof PageTextArea
                     ? (PageTextArea) field.getPageArea()
                     : null;
             System.out.println(area == null ? "Not a template field" : area.getText());
         }
         

        FieldData class represents field data. Depending on the field PageArea property can contain any of the inheritors of PageArea class. For example, Parser.parseForm() method extracts only text fields.

        Parameters:
        fieldName - The name of the field.
        Returns:
        A collection of FieldData objects; empty collection if no field data is found.