Skip to footer content
USING IRONPDF FOR NODE.JS

How to Split A PDF File in Node.js

This article will use IronPDF, a PDF library which helps to split PDF documents into multiple PDF files within an output folder. This can be done with a few lines of code. IronPDF is a powerful PDF library that allows you to create, open, read, and split PDF files easily.

What is Node.js?

JavaScript code can be run outside of a web browser using the cross-platform, open-source Node.js JavaScript runtime environment. With server-side JavaScript execution enabled, programmers may construct scalable, fast, and efficient network applications. Node.js uses an event-driven, non-blocking I/O paradigm, which makes it perfect for creating real-time applications that handle several concurrent connections.

There are various applications that are commonly built with Node.js, including web servers, APIs, streaming apps, real-time chat apps, Internet of Things (IoT) devices, and more. All things considered, Node.js is becoming more and more popular due to its efficiency, speed, and back-end and front-end compatibility with JavaScript, offering a single language for full-stack development. To know more about Node.js, please refer to the Wiki page.

How to split PDF in Node.js

  1. To split PDFs, download the Node.js package.
  2. Install the IronPDF for Node.js library.
  3. Create a new PDF or import an existing one.
  4. Use the duplicate function in the IronPDF for Node.js library.
  5. Pass the page number as a parameter to the duplicate function.
  6. Use the saveAs function to save the individual pages into a PDF file.

IronPDF for Node.js

IronPDF was primarily a .NET library designed to function within the .NET Framework, allowing developers to work with PDF documents using C# or VB.NET. Nevertheless, IronPDF did not have a native or direct version created just for Node.js. This probably indicates that IronPDF for Node.js now offers features for generating, modifying, and processing PDF documents in Node.js applications.

Features of IronPDF

If IronPDF has extended its product line to include a Node.js version, this might offer developers creating Node.js apps a method to incorporate IronPDF's features for PDF manipulation. Developers who would rather work with a library that provides features similar to those of IronPDF in the .NET environment could find this useful.

For the most up-to-date and accurate information about IronPDF's features, compatibility, and support for Node.js, always consult the official documentation, release notes, or updates from the IronPDF team. To know more about IronPDF, refer to the documentation pages.

Package Requirement

  • The IDE is Visual Studio Code.
  • Node.js
  • Installing packages requires package management, which you can use using Yarn or npm.

Install IronPDF package Node

Open Terminal or the Command Prompt: Launch the terminal or command prompt. You can access it in several ways depending on your OS:

  • Windows: Command Prompt or PowerShell
  • MacOS X Terminal
  • Linux's Terminal

Install the package: Use the package name with the npm install command to install the package. For example, run the following command to install the @ironsoftware/ironpdf package:

npm install @ironsoftware/ironpdf
npm install @ironsoftware/ironpdf
SHELL

How to Split A PDF File in Node.js, Figure 1: Install IronPDF Install IronPDF

Split PDF using IronPDF

It merely takes a few lines of code to split PDF documents into multiple files. Check out this sample to incorporate it into your project. Dividing a single PDF document into several documents is a fairly simple process when using IronPDF. Every document has just one page.

const { PdfDocument } = require("@ironsoftware/ironpdf");

const pdfprocess = async () => {
  console.log("Start split Process");
  // Load the existing PDF document
  const pdf = await PdfDocument.fromFile("Demo.pdf");

  // Get the total number of pages in the PDF
  const pagecount = await pdf.getPageCount();

  // Iterate over each page and create a separate PDF file
  for (let i = 0; i < pagecount; i++) {
    // Duplicate a single page into a new PDF document
    const spdf = await pdf.duplicate(i);

    // Save each duplicated page as a separate PDF file
    await spdf.saveAs(`split_${i}.pdf`);
  }
  console.log("End Split Process");
};

// Initiate the PDF splitting process
pdfprocess();

The code sample above demonstrates how to use IronPDF's PdfDocument.fromFile method to open an existing PDF file. By passing a document password to the fromFile method as a second argument, you can also open a password-protected file. The code is quite basic and easy to use to split a PDF file. Using the duplicate method to easily copy multiple pages from the original document, as demonstrated above.

By providing the index number as a parameter to the duplicate method, the PDF file is divided. Each page is then saved in a different file. A PDF can also be divided into a range of pages by duplication. For that, we are using the function getPageCount which will allow us to get the page count of the PDF input file path. Then by using the duplicate method to split the PDF file into multiple PDF files.

How to Split A PDF File in Node.js, Figure 2: NPM NPM

IronPDF will load the input PDF file and then split PDF files into separate files.

How to Split A PDF File in Node.js, Figure 3: PDF Files PDF Files

To know more about the IronPDF for Node.js library code, refer to the sample page to convert HTML to a PDF file.

Conclusion

Strong security protections are provided by the IronPDF library to reduce threats and guarantee data safety. It is not restricted to any specific browser and works with all common ones. The library provides many licensing options, including a free developer license and additional development licenses that can be purchased, to meet the varying needs of developers.

Upgrade options are included in the $749 Lite bundle, which also comes with a permanent license, one year of software maintenance, and a thirty-day money-back guarantee. During the watermarked trial period, users can assess the product in real-world application scenarios. The licensing page provides additional information regarding IronPDF's pricing and licensing options, and also allows users to try IronPDF for free for 30-days.

Frequently Asked Questions

What is the tool used for handling PDFs in Node.js applications?

IronPDF for Node.js is a library that allows Node.js applications to generate, modify, and process PDF documents. It offers features like PDF splitting, merging, and more.

How do I install the PDF processing library for Node.js?

To install IronPDF for Node.js, open a terminal or command prompt and run the command `npm install @ironsoftware/ironpdf`.

How can I split a PDF in Node.js?

To split a PDF using IronPDF in Node.js, load the PDF using `PdfDocument.fromFile`, then use the `duplicate` method to copy pages into separate files, and save them using the `saveAs` function.

What are the main features of the PDF library for Node.js?

IronPDF provides features like HTML to PDF generation, text and image manipulation, PDF modification (combining, extracting, splitting, encrypting), form handling, and PDF security through digital signatures and encryption.

What are the system requirements to use the PDF library in Node.js?

You need Node.js installed on your system along with a package manager like npm or Yarn. An IDE like Visual Studio Code can be used for development.

Is there a trial version available for the PDF processing tool?

Yes, IronPDF offers a free developer license during a watermarked trial period, which allows users to evaluate the product in real-world applications.

Can the PDF library handle password-protected PDF files?

Yes, IronPDF can handle password-protected PDF files by passing a document password to the `fromFile` method as a second argument.

What is Node.js used for?

Node.js is used for constructing scalable, fast, and efficient network applications, such as web servers, APIs, streaming apps, real-time chat apps, and IoT devices.

Where can I find more information about the PDF library for Node.js?

For the most up-to-date information about IronPDF for Node.js, consult the official documentation, release notes, or updates from the IronPDF team.

What licensing options does the PDF library offer?

IronPDF offers several licensing options, including a free developer license, a Lite bundle with a permanent license, and various development licenses to meet different needs.

Darrius Serrant
Full Stack Software Engineer (WebOps)

Darrius Serrant holds a Bachelor’s degree in Computer Science from the University of Miami and works as a Full Stack WebOps Marketing Engineer at Iron Software. Drawn to coding from a young age, he saw computing as both mysterious and accessible, making it the perfect medium for creativity and problem-solving.

At Iron Software, Darrius enjoys creating new things and simplifying complex concepts to make them more understandable. As one of our resident developers, he has also volunteered to teach students, sharing his expertise with the next generation.

For Darrius, his work is fulfilling because it is valued and has a real impact.

Talk to an Expert Five Star Trust Score Rating

Ready to Get Started?