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

The tutorial below will demonstrate how to PDF make searchable API in JavaScript

Sample source code below will show you how to cope with a difficult task like PDF make searchable API in JavaScript. Want to PDF make searchable API in your JavaScript app? PDF.co Web API is designed for it. 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.

Fast application programming interfaces of PDF.co Web API for JavaScript plus the instruction and the code below will help you quickly learn how to PDF make searchable API. Just copy and paste the code into your JavaScript application’s code and follow the instruction. Code testing will allow the function to be tested and work properly with your data.

ByteScout free trial version is available for download from our website. It includes all these programming tutorials along with source code samples.

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

MakeSearchablePdfFromFile_AsyncAPI.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 const SourceFile = "./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. Let us know if you need more. const Language = "eng"; // Destination PDF file name const DestinationFile = "./result.pdf"; // Prepare request uri to `Make Searchable PDF` API endpoint var query = `https://api.pdf.co/v1/pdf/makesearchable`; let reqOptions = { uri: query, headers: { "x-api-key": API_KEY }, formData: { name: path.basename(DestinationFile), password: Password, pages: Pages, lang: Language, async: 'True', 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); console.log(`Job #${data.jobId} has been created!`); checkIfJobIsCompleted(data.jobId, data.url); }); 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, DestinationFile);}, 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: