Remove Tables from PDF in Node.js SDK
API for working with Tables in PDF documents using Cloud Node.js SDK
Get StartedHow to remove Tables from PDF via Node.js SDK
To remove Tables from PDF, we’ll use Aspose.PDF Cloud Node.js SDK. This Cloud SDK assists Node.js programmers in developing cloud-based PDF creator, annotator, editor, and converter apps using Node.js programming language via Aspose.PDF REST API. Simply create an account at Aspose for Cloud and get your application information. Once you have the App SID & key, you are ready to give the Aspose.PDF Cloud Node.js SDK.
Package Manager Console Command
npm install asposepdfcloud --save
Steps to remove Tables from PDF via Cloud Node.js
Aspose.PDF Cloud developers can easily load & remove Tables from PDF in just a few lines of code.
- Read the local PDF file.
- Upload a local PDF to Aspose Cloud.
- Get All Tables in the Document
- Delete a Specific Table
- Get Tables After Deleting One
- Delete All Tables from a Specific Page
- Get Tables After Deleting All
- Download the Resulting PDF
Delete Tables from PDF using Node.js
import credentials from "../../../../Credentials/credentials.json" with { type: "json" };
import fs from 'node:fs/promises';
import path from 'node:path';
import { PdfApi } from "../../../src/api/api.js"
const configParams = {
LOCAL_FOLDER: "C:\\Samples\\",
PDF_DOCUMENT_NAME: "sample.pdf",
LOCAL_RESULT_DOCUMENT_NAME: "output_sample.pdf",
PAGE_NUMBER: 1, // Your document page number...
TABLE_ID: "GE5TCOZSGAYCYNRQGUWDINZVFQ3DGMA", // Your table id...
};
const pdfApi = new PdfApi(credentials.id, credentials.key);
const pdfTables = {
async uploadDocument () {
const fileNamePath = path.join(configParams.LOCAL_FOLDER, configParams.PDF_DOCUMENT_NAME);
const pdfFileData = await fs.readFile(fileNamePath);
await pdfApi.uploadFile(configParams.PDF_DOCUMENT_NAME, pdfFileData);
console.log("File '" + configParams.PDF_DOCUMENT_NAME + "' successfully uploaded!");
},
async downloadResult () {
const changedPdfData = await pdfApi.downloadFile(configParams.PDF_DOCUMENT_NAME);
const filePath = path.join(configParams.LOCAL_FOLDER, configParams.LOCAL_RESULT_DOCUMENT_NAME);
await fs.writeFile(filePath, changedPdfData.body);
console.log("Downloaded: " + filePath);
},
async getAllTables (prefix) {
const resultTabs = await pdfApi.getDocumentTables(configParams.PDF_DOCUMENT_NAME);
if (resultTabs.body.code == 200 && resultTabs.body.tables) {
if (!Array.isArray(resultTabs.body.tables.list) || resultTabs.body.tables.list.length === 0)
console.log(prefix + " => Unexpected error : tables is null or empty!!!");
else
this.showTablesInfo(resultTabs.body.tables.list, prefix);
}
else
console.error(prefix + " => Unexpected error : can't get tables!!!");
},
async deleteTable () {
const resultTabs = await pdfApi.deleteTable(configParams.PDF_DOCUMENT_NAME, configParams.TABLE_ID);
if (resultTabs.body.code == 200) {
console.log("Table #" + configParams.TABLE_ID + " deleted!");
return true;
}
else
console.error("Unexpected error : can't delete table!");
},
async deleteTables () {
const resultTabs = await pdfApi.deletePageTables(configParams.PDF_DOCUMENT_NAME, configParams.PAGE_NUMBER);
if (resultTabs.body.code == 200) {
console.log("Tables on page #" + configParams.PAGE_NUMBER + " deleted!");
return true;
}
else
throw new Error("Unexpected error : can't get tables!!!");
},
showTablesInfo (tables, prefix) {
if (Array.isArray(tables) && tables.length > 0)
{
tables.forEach(function(table) {
console.log(prefix +" => id: '" + table.id + "', page: '" + table.pageNum + "', rows: '" + table.rowList.length + "', columns: '" + table.rowList[0].cellList.length + "'");
});
}
else
console.error("showTablesInfo() error: array of tables is empty!")
},
}
async function main() {
try {
await pdfTables.uploadDocument();
await pdfTables.getAllTables("All tables");
await pdfTables.deleteTable();
await pdfTables.getAllTables("Tables after drop one");
await pdfTables.deleteTables(configParams.PAGE_NUMBER);
await pdfTables.getAllTables("Tables after drop all");
await pdfTables.downloadResult();
} catch (error) {
console.error("Error:", error.message);
}
}
Remove Tables from PDF
Deleting tables from PDF documents is often necessary to clean up content, simplify layout, or prepare documents for presentation, redaction, or data migration. Removing unnecessary or outdated tables improves readability, reduces file size, protects sensitive information, and ensures only relevant data is retained. This process is also useful when customizing reports, generating templates, or preparing files for regulatory compliance. Delete Tables from PDF documents with Aspose.PDF Cloud Node.js SDK.
With our Node.js library you can:
- Add PDF document’s header & footer in text or image format.
- Add tables & stamps (text or image) to PDF documents.
- Append multiple PDF documents to an existing file.
- Work with PDF attachments, annotations, & form fields.
- Apply encryption or decryption to PDF documents & set a password.
- Delete all stamps & tables from a page or entire PDF document.
- Delete a specific stamp or table from the PDF document by its ID.
- Replace single or multiple instances of text on a PDF page or from the entire document.
- Extensive support for converting PDF documents to various other file formats.
- Extract various elements of PDF files & make PDF documents optimized.
- You can try out our free App to extract Table into PDF files online and test the functionality.
- Learning Resources
- Documentation
- Source Code
- API References
- Product Support
- Free Support
- Paid Support
- Blog
- Why Aspose.PDF Cloud for Node.js?
- Customers List
- Security