Remove Tables from Existing PDF Documents
Contents
[
Hide
]
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.
- Open the source PDF Document.
- Visit the target page with TableAbsorber.
- 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.
- Open the source PDF Document.
- Visit the target page with TableAbsorber and copy the detected tables to a list.
- 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());
}
}