com.aspose.pdf

Interfaces

Classes

Enums

Exceptions

com.aspose.pdf

Class TableAbsorber



  • public class TableAbsorber
    extends Object

    Represents an absorber object of table elements. Performs search and provides access to search results via TableAbsorber.TableList collection.


     The example demonstrates how to find table on the first PDF document page and replace the text in a table cell.
    
            // Open document
     Document doc = new Document("D:\\Tests\\input.pdf");
     // Create TableAbsorber object to find tables
     TableAbsorber absorber = new TableAbsorber();
     // Visit first page with absorber
     absorber.visit(doc.getPages().get_Item(1));
     // Get access to first table on page, their first cell and text fragments in it
     TextFragment fragment = absorber.getTableList().get_Item(0).getRowList().get_Item(0).getCellList().get_Item(0)
     .getTextFragments().get_Item(1);
     // Change text of the first text fragment in the cell
     fragment.setText("hi world");
     // Save document
     doc.save("D:\\Tests\\output.pdf");
     
    • Constructor Summary

      Constructors 
      Constructor and Description
      TableAbsorber()
      Initializes a new instance of the TableAbsorber.
      TableAbsorber(TextSearchOptions textSearchOptions)
      Initializes a new instance of the TableAbsorber with text search options.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      List<AbsorbedTable> getTableList()
      Returns readonly IList containing tables that were found
      TextSearchOptions getTextSearchOptions()
      Gets text search options.
      void remove(AbsorbedTable table)
      Removes an AbsorbedTable from the page.
      void replace(Page page, AbsorbedTable oldTable, Table newTable)
      Replaces an AbsorbedTable with Table on the page.
      void setTextSearchOptions(TextSearchOptions value)
      Gets or sets text search options.
      void visit(Page page)
      Extracts tables on the specified page The example demonstrates how to extract table on the first PDF document page. // Open document Document doc = new Document(@"D:\Tests\input.pdf"); // Create TableAbsorber object to find tables TableAbsorber absorber = new TableAbsorber(); // Visit first page with absorber absorber.visit(pdfDocument.getPages.get_item(1)); // Get access to first table on page, their first cell and text fragments in it TextFragment fragment = absorber.getTableList().get_item(0).getRowList.get_item(0).getCellList().get_item(0) .getTextFragments.get_item(1); // Change text of the first text fragment in the cell fragment.setText ("hi world"); // Save document doc.save(@"D:\Tests\output.pdf");
    • Constructor Detail

      • TableAbsorber

        public TableAbsorber(TextSearchOptions textSearchOptions)

        Initializes a new instance of the TableAbsorber with text search options.

        Parameters:
        textSearchOptions - Text search options
        Performs searching for tables and provides access to the tables via TableList object.
      • TableAbsorber

        public TableAbsorber()

        Initializes a new instance of the TableAbsorber.


        Performs searching for tables and provides access to the tables via TableList object.
    • Method Detail

      • getTextSearchOptions

        public TextSearchOptions getTextSearchOptions()

        Gets text search options.


        Allows to define several options that will be used during search text containing in tables.
        Returns:
        TextSearchOptions object
      • setTextSearchOptions

        public void setTextSearchOptions(TextSearchOptions value)

        Gets or sets text search options.


        Allows to define several options that will be used during search text containing in tables.
        Parameters:
        value - TextSearchOptions object
      • getTableList

        public List<AbsorbedTable> getTableList()

        Returns readonly IList containing tables that were found

        Returns:
        IGenericList<AbsorbedTable> object
      • visit

        public void visit(Page page)

        Extracts tables on the specified page


         The example demonstrates how to extract table on the first PDF document page.
        
         // Open document
         Document doc = new Document(@"D:\Tests\input.pdf");
         // Create TableAbsorber object to find tables
         TableAbsorber absorber = new TableAbsorber();
         // Visit first page with absorber
         absorber.visit(pdfDocument.getPages.get_item(1));
         // Get access to first table on page, their first cell and text fragments in it
         TextFragment fragment = absorber.getTableList().get_item(0).getRowList.get_item(0).getCellList().get_item(0)
         .getTextFragments.get_item(1);
         // Change text of the first text fragment in the cell
         fragment.setText ("hi world");
         // Save document
         doc.save(@"D:\Tests\output.pdf");
         
        Parameters:
        page - Pdf pocument page object.
      • remove

        public void remove(AbsorbedTable table)

        Removes an AbsorbedTable from the page.


        Please take into account it changes TableList collection. In case removing/replacing tables in loop please use copy of TableList collection.

        Parameters:
        table - AbsorbedTable to remove.
      • replace

        public void replace(Page page,
                            AbsorbedTable oldTable,
                            Table newTable)

        Replaces an AbsorbedTable with Table on the page.


        Please take into account it changes TableList collection. In case removing/replacing tables in loop please use copy of TableList collection.

        Parameters:
        page - Pdf pocument page object.
        oldTable - AbsorbedTable to be replaced.
        newTable - Table to replace old table.