How to split PDF from file (node for PDF splitting API in JavaScript using PDF.co Web API

Learn how to split PDF from file (node to have PDF splitting API in JavaScript

Every ByteScout tool contains example JavaScript source codes that you can find here or in the folder with installed ByteScout product. PDF splitting API in JavaScript can be implemented with PDF.co Web API. PDF.co Web API is the Rest API that provides set of data extraction functions, tools for documents manipulation, splitting and merging of pdf files. Includes built-in OCR, images recognition, can generate and read barcodes from images, scans and pdf.

This rich sample source code in JavaScript for PDF.co Web API includes the number of functions and options you should do calling the API to implement PDF splitting API. Sample code in JavaScript is all you need. Copy-paste it to your the code editor, then add a reference to PDF.co Web API and you are ready to try it! This basic programming language sample code for JavaScript will do the whole work for you in implementing PDF splitting API in your app.

Trial version of ByteScout is available for free download from our website. This and other source code samples for JavaScript and other programming languages are available.

Try PDF.co Web API today:  60 Day Free Trial (on-premise) or  Web API (on-demand version)

SplitPdfFromFile.js
      
/*jshint esversion: 6 */ var https = require("https"); var path = require("path"); var fs = require("fs"); // `request` module is required for file upload. // Use "npm install request" command to install. var request = require("request"); // The authentication key (API Key). // Get your own by registering at https://app.pdf.co/documentation/api const API_KEY = "***********************************"; // Source PDF file to split const SourceFile = "./sample.pdf"; // Comma-separated list of page numbers (or ranges) to process. Example: '1,3-5,7-'. const Pages = "1-2,3-"; // Prepare URL for `Split PDF` API endpoint var query = `https://api.pdf.co/v1/pdf/split`; let reqOptions = { uri: query, headers: { "x-api-key": API_KEY }, formData: { pages: Pages, file: fs.createReadStream(SourceFile) } }; // Send request request.post(reqOptions, function (error, response, body) { if (error) { return console.error("Error: ", error); } // Parse JSON response let data = JSON.parse(body); if (data.error == false) { // Download generated PDF files var part = 1; data.urls.forEach((url) => { var localFileName = `./part${part}.pdf`; var file = fs.createWriteStream(localFileName); https.get(url, (response2) => { response2.pipe(file) .on("close", () => { console.log(`Generated PDF file saved as "${localFileName}" file.`); }); }); part++; }, this); } else { // Service reported error console.log("Error: " + data.message); } });

Try PDF.co Web API today:  60 Day Free Trial (on-premise) or  Web API (on-demand version)

VIDEO

ON-PREMISE VERSION INFORMATION

Get 60 Day Free Trial or Visit PDF.co Web API Home Page

Explore PDF.co Web API Documentation

Get PDF.co Web API Free Training

WEB API

Get Your Free API Key

Explore Web API Documentation

Related Samples: