Remove Tables from PDF using Java

Delete tables from PDF document using Aspose.PDF for Java Library

How to deleting Tables from PDF document Using Java Library

In order to delete table, we’ll use Aspose.PDF for Java API which is a feature-rich, powerful and easy to use conversion API for Java platform. You can download its latest version directly from Maven and install it within your Maven-based project by adding the following configurations to the pom.xml.

Repository

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java AP</name>
    <url>https://releases.aspose.com/java/repo/</url>
</repository>

Dependency

<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>version of aspose-pdf API</version>
</dependency>

Delete Tables from PDF using Java


You need Aspose.PDF for Java to try the code in your environment.

  1. Load the PDF with an instance of Document.
  2. Create TableAbsorber object to find tables.
  3. Visit first page with absorber.
  4. Get first table on the page.
  5. Remove the table. Save the file.

Delete Tables from PDF - Java

// Load existing PDF document
Document pdfDocument = new Document(DATA_DIR.resolve("Table_input.pdf").toString());

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

// Visit first page with absorber
absorber.visit(pdfDocument.getPages().get_Item(1));

// Get first table on the page
AbsorbedTable table = absorber.getTableList().getFirst();

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

// Save PDF
pdfDocument.save(DATA_DIR.resolve("Table_out.pdf").toString());
pdfDocument.close();