How to convert a scanned document into text with location in Salesforce Apex using OCR

Cloudmersive
1 min readJul 11, 2020

--

Optical character recognition can be a powerful productivity tool if implemented properly into your project. It can also be an incredibly difficult and time consuming endeavor if you are not careful. To avoid this second possibility, we will be showing you how to use a Cloudmersive API to get this done fast, while maintaining maximum quality.

First we will need our client, which you can download here:

https://github.com/Cloudmersive/Cloudmersive.APIClient.Apex.OCR/archive/master.zip

Copy the client folder into your project and then call this function:

SwagImageOcrApi api = new SwagImageOcrApi();SwagClient client = api.getClient();// Configure API key authorization: ApikeyApiKeyAuth Apikey = (ApiKeyAuth) client.getAuthentication('Apikey');Apikey.setApiKey('YOUR API KEY');Map<String, Object> params = new Map<String, Object>{'imageFile' => Blob.valueOf('Sample text file\nContents'),'language' => 'language_example','preprocessing' => 'preprocessing_example'};try {// cross your fingersSwagImageToWordsWithLocationResult result = api.imageOcrImageWordsWithLocation(params);System.debug(result);} catch (Swagger.ApiException e) {// ...handle your exceptions}

And there you have it. Super easy.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet