Let’s suppose that the Aspose.Cloud AppSid and AppKey are stored in system environment variables ASPOSE_CLOUD_APPSID and ASPOSE_CLOUD_APPKEY.
Java
importjava.io.IOException;importjava.io.InputStream;importjava.awt.Rectangle;importjava.util.ArrayList;importjava.util.Arrays;importjava.util.List;importorg.apache.commons.lang3.ArrayUtils;importorg.json.JSONArray;importorg.json.JSONObject;importcom.groupdocs.redaction.integration.RecognizedImage;importcom.groupdocs.redaction.integration.TextLine;importcom.groupdocs.redaction.integration.TextFragment;importcom.groupdocs.redaction.integration.IOcrConnector;publicclassAsposeCloudOcrConnectorimplementsIOcrConnector{publicAsposeCloudOcrConnector(){}publicRecognizedImagerecognize(InputStreamimageStream){try{Configuration.setAPP_SID(System.getenv("ASPOSE_CLOUD_APPSID"));Configuration.setAPI_KEY(System.getenv("ASPOSE_CLOUD_APPKEY"));Configuration.setUserAgent("WebKit");finalOcrApiInvokerapi=newApiClient().createService(OcrApiInvoker.class);byte[]payload=readBytes(imageStream);RequestBodyrequestBody=RequestBody.create(MediaType.parse("application/octet-stream"),payload);Call<ResponseBody>call=api.RecognizeFromContent(requestBody,Language.English,ResultType.Internal,DsrMode.DsrAndFilter,DsrConfidence.Default);Response<ResponseBody>res=call.execute();if(res.isSuccessful()){ResponseBodyanswer=res.body();JSONObjectjToken=newJSONObject(answer.string());Stringresult=jToken.getString("text");returncreateDtoFromResponse(newJSONObject(result));}}catch(java.lang.Exceptionex){thrownewRuntimeException("Aspose.OCR for Cloud Recognition failed: "+ex.toString());}returnnewRecognizedImage(newTextLine[0]);}protectedRecognizedImagecreateDtoFromResponse(JSONObjectjToken){// Recursively parse json tree with regions and text lines.
}...}
The RecognizeFromContent() method with ResultType.Internal returns a JSON-serialized tree of text regions and recognized lines, with bounding rectangles. The text line is represented by a single object.
Along with full featured Java library we provide simple, but powerful free Apps.
You are welcome to perform redactions for various document formats like PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, Emails and more with our free online Free Online Document Redaction App.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.