How to PDF make searchable API in JavaScript and PDF.co Web API

Write code in JavaScript to PDF make searchable API with this step-by-step tutorial

With this source code sample you may quickly learn how to PDF make searchable 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. It can be used to PDF make searchable API using JavaScript.

This code snippet below for PDF.co Web API works best when you need to quickly PDF make searchable API in your JavaScript application. Just copy and paste the code into your JavaScript application’s code and follow the instruction. Use of PDF.co Web API in JavaScript is also explained in the documentation included along with the product.

Free trial version of PDF.co Web API is available on our website. Documentation and source code samples are included.

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

MakeSearchablePdfFromUrl.js
      
var https = require("https"); var path = require("path"); var fs = require("fs"); // The authentication key (API Key). // Get your own by registering at https://app.pdf.co/documentation/api const API_KEY = "***********************************"; // Direct URL of source PDF file. const SourceFileUrl = "https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/pdf-make-searchable/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 = ""; // OCR language. "eng", "fra", "deu", "spa" supported currently. Ley us know if you need more. const Language = "eng"; // Destination PDF file name const DestinationFile = "./result.pdf"; // Prepare request to `Make Searchable PDF` API endpoint var queryPath = `/v1/pdf/makesearchable?name=${path.basename(DestinationFile)}&password=${Password}&pages=${Pages}&lang=${Language}&url=${SourceFileUrl}&async=True`; 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) { console.log(`Job #${data.jobId} has been created!`); checkIfJobIsCompleted(data.jobId, data.url); } else { // Service reported error console.log(data.message); } }); }).on("error", (e) => { // Request error console.log(e); }); function checkIfJobIsCompleted(jobId, resultFileUrl) { let queryPath = `/v1/job/check?jobid=${jobId}`; let reqOptions = { host: "api.pdf.co", path: encodeURI(queryPath), method: "GET", headers: { "x-api-key": API_KEY } }; https.get(reqOptions, (response) => { response.on("data", (d) => { response.setEncoding("utf8"); // Parse JSON response let data = JSON.parse(d); console.log(`Checking Job #${jobId}, Status: ${data.status}, Time: ${new Date().toLocaleString()}`); if (data.status == "working") { // Check again after 3 seconds setTimeout(function(){ checkIfJobIsCompleted(jobId, resultFileUrl);}, 3000); } else if (data.status == "success") { // Download PDF file var file = fs.createWriteStream(DestinationFile); https.get(resultFileUrl, (response2) => { response2.pipe(file) .on("close", () => { console.log(`Generated PDF file saved as "${DestinationFile}" file.`); }); }); } else { console.log(`Operation ended with status: "${data.status}".`); } }) }); }

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: