How to extract information from a form photo in Salesforce Apex using OCR

Cloudmersive
1 min readJul 11, 2020

--

If your company deals with high volumes of forms, then OCR is going to quickly become your best friend. In today’s tutorial we will be demonstrating how to use an API that can be set up to easily recognize forms and collect data from their fields. Let’s get started.

First we need to download this zip archive and extract the client files into our project:

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

Now we can go ahead and call this function here:

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'),'formTemplateDefinition' => Object.getExample(),'recognitionMode' => 'recognitionMode_example','preprocessing' => 'preprocessing_example','diagnostics' => 'diagnostics_example','language' => 'language_example'};try {// cross your fingersSwagFormRecognitionResult result = api.imageOcrPhotoRecognizeForm(params);System.debug(result);} catch (Swagger.ApiException e) {// ...handle your exceptions}

Following the example, it should be easy to set up your form specifications, and you will be ready to blast through those stacks of papers in no time!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet