How to convert PDF to JPEG from URL (node for PDF to image API in JavaScript and PDF.co Web API

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

The sample source codes on this page will demonstrate you how to make PDF to image API in JavaScript. PDF.co Web API was made to help with PDF to image 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.

JavaScript code snippet like this for PDF.co Web API works best when you need to quickly implement PDF to image API in your JavaScript application. 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! You can use these JavaScript sample examples in one or many applications.

Our website provides free trial version of PDF.co Web API that includes source code samples to help with your JavaScript project.

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

ConvertPdfToJpegFromUrl.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 const SourceFileUrl = "https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/pdf-to-image/sample.pdf"; // Comma-separated list of page indices (or ranges) to process. Leave empty for all pages. Example: '0,2-5,7-'. const Pages = ""; // PDF document password. Leave empty for unprotected documents. const Password = ""; // Prepare request to `PDF To JPEG` API endpoint var queryPath = `/v1/pdf/convert/to/jpg?password=${Password}&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 JPEG files var page = 1; data.urls.forEach((url) => { var localFileName = `./page${page}.jpg`; var file = fs.createWriteStream(localFileName); https.get(url, (response2) => { response2.pipe(file) .on("close", () => { console.log(`Generated JPEG file saved as "${localFileName}" file.`); }); }); page++; }, 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: