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

How to split PDF from URL (node in JavaScript with easy ByteScout code samples to make PDF splitting API. Step-by-step tutorial

On this page you will learn from code samples for programming in JavaScript. PDF.co Web API was made to help with PDF splitting API in JavaScript. PDF.co Web API is the Web API with a set of tools for documents manipulation, data conversion, data extraction, splitting and merging of documents. Includes image recognition, built-in OCR, barcode generation and barcode decoders to decode bar codes from scans, pictures 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. Open your JavaScript project and simply copy & paste the code and then run your app! Tutorials are available along with installed PDF.co Web API if you’d like to dive deeper into the topic and the details of the API.

PDF.co Web API – free trial version is on available our website. Also, there are other code samples to help you with your JavaScript application included into trial version.

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

SplitPdfFromUrl.js
      
var https = require("https"); var fs = require("fs"); // 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 SourceFileUrl = "https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/pdf-split/sample.pdf"; // Comma-separated list of page numbers (or ranges) to process. Example: '1,3-5,7-'. const Pages = "1-2,3-"; // Prepare request to `Split PDF` API endpoint var queryPath = `/v1/pdf/split?pages=${Pages}&url=${SourceFileUrl}`; var reqOptions = { host: "api.pdf.co", path: encodeURI(queryPath), headers: { "x-api-key": API_KEY } }; // Send request https.get(reqOptions, (response) => { response.on("data", (d) => { // Parse JSON response var data = JSON.parse(d); 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(data.message); } }); }).on("error", (e) => { // Request error console.error(e); });

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: