How to Extract Pages from PDF File using Rest API in Node.js

How to Extract Pages from PDF Files using Rest API in Node.js

You may need to extract multiple pages from PDF at once programmatically. By separating PDF pages, you can easily export and save specific pages of PDF documents to share with the stakeholders. As a Node.js developer, you can extract multiple pages from PDF documents on the cloud. In this article, we will demonstrate how to extract pages from PDF file using Rest API in Node.js.

The following topics shall be covered in this article to take pages out of PDF:

PDF Extractor REST API and Node.js SDK

In order to extract pages from PDF adobe acrobat, I will be using the Node.js SDK of GroupDocs.Merger Cloud API. It is an online PDF page extractor free download library. It allows you to split, combine, extract, remove and rearrange a single page or a collection of pages from supported document formats of Word, Excel, PowerPoint, Visio drawings, PDF, and HTML.

You can install GroupDocs.Merger cloud to extract PDF pages from PDF files in your Node.js application using the following command in the console:

npm install groupdocs-merger-cloud

Please get your Client ID and Secret from the dashboard before following the mentioned steps. Once you have your ID and secret, add in the code as shown below:

Extract PDF Pages by Exact Page Numbers using REST API in Node.js

You can export a single page from PDF or export specific pages from PDF files programmatically on the cloud by following the simple steps mentioned below:

  • Upload the PDF file to the Cloud
  • Extract PDF pages using REST API in Node.js
  • Download the separated files

Upload the PDF File

You can start by importing the PDF file to the cloud using the code example given below:

The PDF file will be available when the file is uploaded in the files section of your dashboard on the cloud.

Extract PDF Pages using REST API in Node.js

The steps below will teach you how to programmatically extract pages from PDF file:

  • Firstly, create an instance of the PagesApi.
  • Create an instance of the ExtractOptions.
  • Create an instance of the FileInfo.
  • Then, set the path to the input PDF file.
  • Next, set the path to the extracted PDF file.
  • Set specific page numbers in a comma-separated array to extract PDF files.
  • Create ExtractRequest with ExtractOptions.
  • Finally, call the pagesApi.extract() method with ExtractRequest to get results.

The following code snippet shows how to extract PDF pages into separate files using REST API in Node.js:

Download the Extracted Files

The above code sample will save the separated files on the cloud. You can download them using the following code sample:

Extract Pages from PDF by Page Range using REST API in Node.js

You can extract and save pages from a PDF separately by providing a range of page numbers programmatically by following the steps given below:

  • Firstly, create an instance of the PagesApi.
  • Create an instance of the ExtractOptions.
  • Create an instance of the FileInfo.
  • Then, set the path to the input PDF file.
  • Next, set the path to the extracted PDF file.
  • Set the start page number and the end page number values.
  • Then, set the rangeMode as EvenPages or OddPages
  • Create ExtractRequest with ExtractOptions.
  • Finally, call the pagesApi.extract() method with ExtractRequest to get results.

The following code snippet shows how to extract pages from PDF online using page range and page mode in Node.js:

Similar way, you can extract odd pages from PDF documents.

Try Online

How to extract pages from PDF files online? Please try the following free online PDF extractor tool to extract pages from PDF online free. This PDF page extractor free online tool is developed using the above API.

Conclusion

We are wrapping up this blog post here. In this article, you have learned:

  • how to extract certain pages from PDF or extract one page from PDF online using REST API;
  • how to extract pages from PDF documents using page range and range mode filter;
  • upload PDF file to the cloud to export selected pages from PDF online;
  • download and save certain pages of PDF from the cloud;
  • how to extract pages from PDF free;

Now, you know how to extract one page from a PDF document or how to save certain pages of a PDF. The API also enables you to reorder or replace document pages, change page orientation, manage document passwords and perform other manipulations easily for any supported file format. Besides, you can learn more about GroupDocs.Merge Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser.

Additionally, we advise you to refer to our Getting Started guide.

Additionally, groupdocs.cloud regularly writes articles about new topics. So please stay in touch for the latest updates.

Ask a question

You can ask your queries about how to extract PDF files to export selected pages from PDF, via our Free Support Forum

FAQs

How to extract multiple pages from PDF into one file?

Install JS library for separating PDF files into multiple pages online programmatically. You can visit the documentation for complete API details.

How long does it take to extract specific pages from PDF?

JavaScript HTML to PDF library works very fast and you can extract pages from protected PDF easily in a few seconds.

See Also

For the best reading and information, please visit the following articles: