Remove Tables from Existing PDF Documents

Use TableAbsorber when you need to delete one or more detected tables from an existing PDF.

Remove one detected table

Use this example when only the first matched table on a page should be deleted.

  1. Open the source PDF Document.
  2. Visit the target page with TableAbsorber.
  3. Remove the first detected table and save the document.
public static void removeOneTable(Path inputFile, Path outputFile) {
    try (Document document = new Document(inputFile.toString())) {
        TableAbsorber absorber = new TableAbsorber();
        absorber.visit(document.getPages().get_Item(1));
        absorber.remove(absorber.getTableList().get(0));
        document.save(outputFile.toString());
    }
}

Remove all detected tables from a page

Use this example when every matched table on the page should be removed.

  1. Open the source PDF Document.
  2. Visit the target page with TableAbsorber and copy the detected tables to a list.
  3. Remove each detected table and save the updated PDF.
public static void removeAllTables(Path inputFile, Path outputFile) {
    try (Document document = new Document(inputFile.toString())) {
        TableAbsorber absorber = new TableAbsorber();
        absorber.visit(document.getPages().get_Item(1));
        List<AbsorbedTable> tables = new ArrayList<>(absorber.getTableList());
        for (AbsorbedTable table : tables) {
            absorber.remove(table);
        }
        document.save(outputFile.toString());
    }
}