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:

// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();

// Load existing PDF document
Document pdfDocument = new Document(dataDir + "Table_input.pdf");

// Create TableAbsorber object to find tables
TableAbsorber absorber = new TableAbsorber();

// Visit first page with absorber
absorber.Visit(pdfDocument.Pages[1]);

// Get first table on the page
AbsorbedTable table = absorber.TableList[0];

// Remove the table
absorber.Remove(table);

// Save PDF
pdfDocument.Save(dataDir + "Table_out.pdf");

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:

// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();

// Load existing PDF document
Document pdfDocument = new Document(dataDir + "Table_input2.pdf");

// Create TableAbsorber object to find tables
TableAbsorber absorber = new TableAbsorber();

// Visit second page with absorber
absorber.Visit(pdfDocument.Pages[1]);

// Get copy of table collection
AbsorbedTable[] tables = new AbsorbedTable[absorber.TableList.Count];
absorber.TableList.CopyTo(tables, 0);

// Loop through the copy of collection and removing tables
foreach (AbsorbedTable table in tables)
    absorber.Remove(table);

// Save document
pdfDocument.Save(dataDir + "Table2_out.pdf");