OCR Images and PDFs using Google Docs
This guide has been revived and updated following a website reshuffle when the original guide was completely lost! The basics have not changed since the original was written in February 2019, but the methods have been improved. Google Docs does a very good job of OCRing images with text, even those taken with a phone or tablets camera, and it can also extract the text from PDF files. This method does rely on an internet connection.
Example image of text to be OCR'd (this is the lorem.png image in the app)
Example of OCr'd text
The demo app shows how this is done, returning the text to a label, and allowing the user to save this text to a tinydb. A google apps script web app provides the magic of handling the uploaded image (in base64) opening this up in a google doc for OCRing, then returning the text. Both the image/pdf and the created google doc are deleted from Google Drive on success. The demo app tests two different types of image and a sample pdf containing text, and allows for the user to take photos or written text with the device camera for OCR. A standalone google apps script project is used for this demo. You can use a project bound to a spreadsheet if you find this easier, but the spreadsheet is not needed for this. The demo app was developed and tested in companion and compiled versions on Android 10 and 11, the file paths used reflect this. There is no block coding to handle earlier Android versions.
What do we need?
Google Apps Script Web App
Setup a project in the usual way
Copy the script code below into the project
Enter your own folder ID in the correct place
Publish as a web app, executing as "you" and accessible by "anyone, even anonymous"
Get the script url for use in the App Inventor App
Make a note also of the filename you give to your project (you can't find it again using just the script url!). I have included mine in the demo app for safekeeping....
App Inventor App
The blocks and the demo app aia are provided below
The very basics required are as follows:
I have added more elements for usability:
A few procedures to extract the filename and the file extension
A hard coded procedure to create the mimetype required (there are only a few filetypes that can be used)
Note the need to modify the Camera image path for use in FIley
A tinydb and listview to store and display the OCR texts