Remove Tables from existing PDF
Contents
[
Hide
]
Aspose.PDF for Python via .NET offers the capabilities to insert/create Table inside PDF document while its being generated from scratch or you can also add the table object in any existing PDF document. However you may have a requirement to Manipulate Tables in existing PDF where you can update the contents in existing table cells. However you may come across a requirement to remove table objects from existing PDF document.
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)