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

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:

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!

Image for post

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

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