How to PDF text search API in JavaScript and Web API

How to code in JavaScript to PDF text search API with this step-by-step tutorial

The code below will help you to implement an JavaScript app to PDF text search API. Web API: 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 PDF text search API in JavaScript.

JavaScript code samples for JavaScript developers help to speed up coding of your application when using Web API. In order to implement the functionality, you should copy and paste this code for JavaScript below into your code editor with your app, compile and run your application. You can use these JavaScript sample examples in one or many applications.

Download free trial version of Web API from our website with this and other source code samples for JavaScript.

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

var https = require("https"); 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 const API_KEY = "***********************************"; // Source file name 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 = ""; // Search string. const SearchString = '[4-9][0-9].[0-9][0-9]'; // Regular expression to find numbers in format dd.dd and between 40.00 to 99.99 // Enable regular expressions (Regex) const RegexSearch = 'True'; // Execute as async api const Async = 'True'; // Prepare URL for PDF text search API call. // See documentation: var query = ``; let reqOptions = { uri: query, headers: { "x-api-key": API_KEY }, formData: { password: Password, pages: Pages, searchString: SearchString, regexSearch: RegexSearch, file: fs.createReadStream(SourceFile), async: Async } }; // Send request request.get(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, resultFileUrlJson) { let queryPath = `/v1/job/check?jobid=${jobId}`; let reqOptions = { host: "", 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, resultFileUrlJson); }, 3000); } else if (data.status == "success") { request({ method: 'GET', uri: resultFileUrlJson, gzip: true }, function (error, response, body) { // Parse JSON response let respJsonFileArray = JSON.parse(body); for (let index = 0; index < respJsonFileArray.length; index++) { const element = respJsonFileArray[index]; console.log("Found text " + element["text"] + " at coordinates " + element["left"] + ", " + element["top"]); } }); } else { console.log(`Operation ended with status: "${data.status}".`); } }) }); }

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



Get 60 Day Free Trial or Visit Web API Home Page

Explore Web API Documentation

Get Web API Free Training


Get Your Free API Key

Explore Web API Documentation

Related Samples: