HTML JPG PDF XML DOCX
  Product Family
PDF

Delete Pages from PDF in Node.js SDK

Delete Pages from PDF Document using Cloud Node.js SDK

Get Started

How to Delete PDF Pages via Node.js SDK

In order to delete Pages 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 delete Pages via Cloud Node.js

Aspose.PDF Cloud developers can easily Delete Pages from PDF in just a few lines of code.

  1. Create an object to connect to the Pdf.Cloud API
  2. Upload your document file
  3. Deleting a specific page from that document
  4. Download the result if needed it
 

This sample code shows removing Pages using Node.js


    import credentials from "./credentials.json"  with { type: "json" };
    import fs from 'node:fs/promises';
    import path from 'node:path';
    import { PdfApi } from "asposepdfcloud";

    const configParams = {
        LOCAL_FOLDER: "C:\\Samples\\",
        PDF_DOCUMENT_NAME: "sample.pdf",
        LOCAL_RESULT_DOCUMENT_NAME: "output_sample.pdf",
        PAGE_NUMBER: 2,     // Your document page number...
    };

    const pdfApi = new PdfApi(credentials.id, credentials.key);

    const pdfPages = {
        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);
        },
                    
        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 deletePage () {
            const resultPages = await pdfApi.deletePage(configParams.PDF_DOCUMENT_NAME, configParams.PAGE_NUMBER);

            if (resultPages.body.code == 200) {
                console.log("Page #" + configParams.PAGE_NUMBER + " - deleted!");
                return true;
            }
            else
            console.error("Unexpected error : can't get pages!!!");
        },

    }

    async function main() {
        try {
            await pdfPages.uploadDocument();
            await pdfPages.deletePage();
            await pdfPages.downloadResult();
        } catch (error) {
            console.error("Error:", error.message);
        }
    }
 

Work with the Pages in PDF via Node.js SDK

​​Removing pages from a PDF is a common task that serves multiple purposes, enhancing both the functionality and security of the document. PDFs can become unwieldy when they contain unnecessary or redundant pages, leading to larger file sizes. By removing these superfluous pages, the overall file size is reduced, making the document more manageable for storage and quicker to upload or download. Over time, documents may accumulate outdated or irrelevant information. Removing such pages ensures that the content remains current and pertinent to the intended audience. Removing pages from a PDF is a practical approach to optimize document size, enhance relevance, protect sensitive information, improve navigation, maintain accuracy, and facilitate collaboration. Remove the Pages 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 Apps to test the functionality online.