Cloud API - Image To PDF - JavaScript - Convert Images To PDF From URLs (Node.js) - ByteScout

Cloud API – Image To PDF – JavaScript – Convert Images To PDF From URLs (Node.js)

  • Home
  • /
  • Articles
  • /
  • Cloud API – Image To PDF – JavaScript – Convert Images To PDF From URLs (Node.js)

Cloud API to Convert Image To PDF in JavaScript From URLs (Node.js)

Developers of varying skills and experience can appreciate Cloud API’s usefulness in expediting the coding process of converting Image to PDF in JavaScript from URLs (Node.js). Cloud API is the REST API that can tremendously help in doing various software development tasks including data extraction, document manipulation, and PDF transformation.

Cloud API is also equipped with image recognition technology and OCR. It can be utilized in producing and reading barcodes from images, PDFs, and scanned documents.

We provide a sample code for you to try and see how easier and faster it is to implement Image to PDF API in JavaScript from URLs (Node.js). This is an absolute time-saver when it comes to writing and testing the code. Just copy and paste the code into your JavaScript project and let it rip! You may also choose to get this sample code from our GitHub repository.

Download a FREE ByteScout trial version from our website to fully appreciate its functionality. This trial version is packaged with useful source code samples and programming tutorials.


// (!) If you are getting "(403) Forbidden" error please ensure you have set the correct API_KEY

var https = require("https");
var path = require("path");
var fs = require("fs");

// The authentication key (API Key).
// Get your own by registering at
const API_KEY = "***********************************";

// Direct URLs of image files to convert to PDF document
const SourceFiles = [
// Destination PDF file name
const DestinationFile = "./result.pdf";

// Prepare request to `Image To PDF` API endpoint
var queryPath = `/v1/pdf/convert/from/image?name=${path.basename(DestinationFile)}&url=${SourceFiles.join(",")}`;
var reqOptions = {
    host: "",
    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 PDF file
            var file = fs.createWriteStream(DestinationFile);
            https.get(data.url, (response2) => {
                .on("close", () => {
                    console.log(`Generated PDF file saved as "${DestinationFile}" file.`);
        else {
            // Service reported error
}).on("error", (e) => {
    // Request error

  Click here to get your Free Trial version of the SDK