How to Convert PDF to Text in JavaScript
Due to the inability to copy, paste, or edit within a PDF document it can be a frustrating task to manually transcribe a PDF to text. The following API takes away that frustration by automating the PDF to text process using Optical Character Recognition technology. In this quick tutorial, we will provide example code for performing the conversion in JavaScript; the operation supports various quality levels and a wide array of languages, so you can customize it to fit your project’s needs.
Our first step is to install the jQuery library by running this command:
bower install jquery
Now that we have our installation set up, we can call the function with the following code:
var form = new FormData();
form.append("imageFile", fileInput.files[0], "file");var settings = {
"url": "https://api.cloudmersive.com/ocr/pdf/toText",
"method": "POST",
"timeout": 0,
"headers": {
"recognitionMode": "<string>",
"language": "<string>",
"preprocessing": "<string>",
"Content-Type": "multipart/form-data",
"Apikey": "YOUR-API-KEY-HERE"
},
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};$.ajax(settings).done(function (response) {
console.log(response);
});
You will receive an instant result indicating the text from your PDF document in the specified language from your parameters — no further steps necessary!