HTML JPG PDF XML DOCX
  Product Family
PDF

Split PDF in Node.js SDK

Split PDF files in Node.js Cloud SDK

Get Started

How to Split PDF files Using Using Node.js SDK

Why do I need to split PDF documents? Splitting PDFs with PHP can be necessary when managing and organizing large documents or working in a data processing environment. Sometimes a larger document requires only a separate section or set of pages. The PDF split allows you to highlight and extract the corresponding pages without the rest of the document.

Also, sending or sharing all of the PDFs may be inefficient, especially if the document is large and contains more information than necessary. When splitting PDFs, you only need to separate the corresponding pages, which makes the process faster and saves bandwidth.

Splitting PDF into smaller sections can reduce the file size, which is useful when you are having storage problems or loading documents onto systems with size restrictions.

Package Manager Console Command


     
    npm install asposepdfcloud --save
     
     

Steps for Splitting PDF via Cloud Node.js

A basic splitting pdfs programmatically with Aspose.PDF Cloud Node.js SDK APIs can be done with just few lines of code.

  1. Load your Application Secret and Key from the JSON file or set credentials in another way
  2. Create an object to connect to the Cloud API
  3. Upload your document file
  4. Splits the uploaded PDF document using the PDF API.
  5. Download each split page as a separate PDF file and saves them locally.
 

Split single PDF Files 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";

    async function splitSingle() {
        try {
            // The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/
            const pdfApi = new PdfApi(credentials.id, credentials.key);

            const buffer = await fs.readFile(LOCAL_FILE_NAME);
            await pdfApi.uploadFile(STORAGE_FILENAME, buffer);
            const result = await pdfApi.postSplitDocument(STORAGE_FILENAME);

            console.log(result.body.status);
            await Promise.all(
                result.body.result.documents.map(async (document, index) => {
                    const downloadRes = await pdfApi.downloadFile(document.href);
                    await fs.writeFile(`page${index + 1}.pdf`, downloadRes.body);
                })
            );
        } catch (error) {
            console.error(error.message);
        }
    }
 

With our Node.js tool 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 split PDF files online and test the functionality.