Remove Tables from existing PDF
In order to remove the tables, we need to use TableAbsorber class to get hold of tables in existing PDF and then call remove().
Remove Table from PDF document
We have added new function i.e. remove() to the existing TableAbsorber Class in order to remove table from PDF document. Once the absorber successfully finds tables on the page, it becomes capable to remove them. Please check following code snippet showing how to remove a table from PDF document:
import aspose.pdf as ap
# Load existing PDF document
pdf_document = ap.Document(input_file)
# Create TableAbsorber object to find tables
absorber = ap.text.TableAbsorber()
# Visit first page with absorber
absorber.visit(pdf_document.pages[1])
# Get first table on the page
table = absorber.table_list[0]
# Remove the table
absorber.remove(table)
# Save PDF
pdf_document.save(output_file)
Remove Multiple Tables from PDF document
Sometimes a PDF document may contain more than one table and you may come up with a requirement to remove multiple tables from it. In order to remove multiple tables from PDF document, please use the following code snippet:
import aspose.pdf as ap
# Load existing PDF document
pdf_document = ap.Document(input_file)
# Create TableAbsorber object to find tables
absorber = ap.text.TableAbsorber()
# Visit second page with absorber
absorber.visit(pdf_document.pages[1])
# Get copy of table collection
tables = absorber.table_list
# Loop through the copy of collection and removing tables
for table in tables:
absorber.remove(table)
# Save document
pdf_document.save(output_file)