Convert a Photo of a Document into Text using JavaScript

These days it’s common for people to upload important physical documents to the internet (including tax forms, medical records, etc.) by taking a photo of the document, rather than by scanning it in a traditional scanner. If your website is accumulating that type of content from your users, you’ve probably noticed that people don’t always take perfect images, which makes the process of using OCR to pull text from that document rather difficult. Our Photo to Text OCR API is designed specifically to handle such photographed documents, and with its help your application will be able to work around various imperfections in the shot.

To structure your API call with JavaScript, start by installing the jQuery Library. Let’s run the below command:

bower install jquery

After that, let’s include the code snippets to call the OCR API:

var form = new FormData();
form.append("imageFile", fileInput.files[0], "file");
var settings = {
"url": "",
"method": "POST",
"timeout": 0,
"headers": {
"recognitionMode": "<string>",
"language": "<string>",
"Content-Type": "multipart/form-data",
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
$.ajax(settings).done(function (response) {

And that’s it — no further code required.

Make sure to include your API key where indicated in the documentation — if you don’t have one currently, register for a free account on our website (Home — Cloudmersive APIs) and you’ll receive one shortly thereafter.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store