How to PDF text search API in JavaScript using PDF.co Web API

How to PDF text search API in JavaScript

PDF text search API is easy to implement in JavaScript if you use these source codes below. Want to PDF text search API in your JavaScript app? PDF.co Web API is designed for it. PDF.co Web API is the Rest API that provides set of data extraction functions, tools for documents manipulation, splitting and merging of pdf files. Includes built-in OCR, images recognition, can generate and read barcodes from images, scans and pdf.

The SDK samples like this one below explain how to quickly make your application do PDF text search API in JavaScript with the help of PDF.co 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.

PDF.co Web API free trial version is available on our website. JavaScript and other programming languages are supported.

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

PDFTextSearchFromFile.js
      
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 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'; // Prepare URL for PDF text search API call. // See documentation: https://app.pdf.co/documentation/api/1.0/pdf/find.html var query = `https://api.pdf.co/v1/pdf/find`; let reqOptions = { uri: query, headers: { "x-api-key": API_KEY }, formData: { password: Password, pages: Pages, searchString: SearchString, regexSearch: RegexSearch, file: fs.createReadStream(SourceFile) } }; // Send request request.get(reqOptions, function (error, response, body) { if (error) { return console.error("Error: ", error); } // Parse JSON response let data = JSON.parse(body); for (let index = 0; index < data.body.length; index++) { const element = data.body[index]; console.log("Found text " + element["text"] + " at coordinates " + element["left"] + ", " + element["top"]); } });

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: