Available SDKs Aspose offers software development kits (SDKs) for popular programming languages that make interaction with Aspose.OCR cloud services much easier. It allows you to focus on business logic rather than the technical details.
SDKs handle all the routine operations such as establishing connections, sending API requests, and parsing responses, wrapping all these tasks into a few simple methods. The following programming languages are supported:
All SDKs are open-source distributed under MIT License . You can freely use them for any projects, including commercial and proprietary applications, as well as modify any part of the code.
The provided code is fully tested and ready to run out of the box.
SDK usage examples
See the examples below for a quick overview of how SDKs can make your development easier.
C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-ocr-cloud/aspose-ocr-cloud-dotnet/
string name = "10.png";
OcrApi api = new OcrApi(conf);
FileApi fileApi = new FileApi(conf /* or AppSid & AppKey*/);
fileApi.UploadFile(new UploadFileRequest(name, System.IO.File.OpenRead(name)));
GetRecognizeDocumentRequest request = new GetRecognizeDocumentRequest(name);
OCRResponse response = api.GetRecognizeDocument(request);
return response.Text;
Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-ocr-cloud/aspose-ocr-cloud-java/
String filename = "sample_ocr.png";
Helper.uploadFile(fileName, folder);
Call<ResponseBody> call = api.RecognizeFromStorage(fileName, folder, storage);
Response<ResponseBody> res = call.execute();
assertTrue(res.isSuccessful());
ResponseBody answer = res.body();
assertNotNull("Answer is null, ", answer);
String text = answer.string();
assertNotNull("Text is empty" + res.toString(), text);
out.println(text);
Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For complete examples and data files, please go to https://github.com/aspose-ocr-cloud/aspose-ocr-cloud-python/
import asposeocrcloud.api.storage_api
from asposeocrcloud.configuration import Configuration
from asposeocrcloud.api.ocr_api import OcrApi
from asposeocrcloud.models import OCRRect, OCRRegion, OCRRequestData, OCRRequestDataStorage, LanguageGroup
import json as json
class RecognizeFromStorage(object):
def __init__(self):
# Setup CAD and Storage API clients
with open("config.json") as f:
server_file_info = json.load(f)
config = Configuration( apiKey=server_file_info['AppKey'],
appSid=server_file_info['AppSid'])
self.ocr_api = OcrApi(config)
self.storage_api= asposeocrcloud.api.storage_api.StorageApi(config)
def recognize_text(self):
self.storage_api.upload_file("5.png", r"data\5.png")
res = self.ocr_api.get_recognize_from_storage("5.png")
return res.text
obj=RecognizeFromStorage()
print(obj.recognize_text())
Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-ocr-cloud/aspose-ocr-cloud-android/
try {
Helper.uploadFile(fileName, folder);
Call<ResponseBody> call = api.RecognizeFromStorage(fileName, folder, storage);
Response<ResponseBody> res = call.execute();
assertTrue(res.isSuccessful());
ResponseBody answer = res.body();
assertNotNull("Answer is null, ", answer);
String text = answer.string();
assertNotNull("Text is empty" + res.toString(), text);
out.println(text);
} catch (Exception e) {
e.printStackTrace();
fail();
}
Go
Copy package main
import (
"context"
"encoding/base64"
"fmt"
"io/ioutil"
asposeocrcloud "github.com/aspose-ocr-cloud/aspose-ocr-cloud-go"
)
func main () {
clientId := "YOUR_CLIENT_ID"
clientSecret := "YOUR_CLIENT_SECRET"
configuration := asposeocrcloud . NewConfiguration ( clientId , clientSecret )
apiClient := asposeocrcloud . NewAPIClient ( configuration )
filePath := "../samples/latin.png"
fileBytes , err := ioutil . ReadFile ( filePath )
if err != nil || fileBytes == nil {
fmt . Println ( "Read file error:" , err )
return
}
fileb64Encoded := base64 . StdEncoding . EncodeToString ( fileBytes )
recognitionSettings := * asposeocrcloud . NewOCRSettingsRecognizeImage ()
recognitionSettings . Language = asposeocrcloud . LANGUAGE_ENGLISH . Ptr ()
recognitionSettings . DsrMode = asposeocrcloud . DSRMODE_NO_DSR_NO_FILTER . Ptr ()
recognitionSettings . DsrConfidence = asposeocrcloud . DSRCONFIDENCE_DEFAULT . Ptr ()
* recognitionSettings . MakeBinarization = false
* recognitionSettings . MakeSkewCorrect = false
* recognitionSettings . MakeUpsampling = false
* recognitionSettings . MakeSpellCheck = false
* recognitionSettings . MakeContrastCorrection = false
recognitionSettings . ResultType = asposeocrcloud . RESULTTYPE_TEXT . Ptr ()
recognitionSettings . ResultTypeTable = asposeocrcloud . RESULTTYPETABLE_TEXT . Ptr ()
requestBody := * asposeocrcloud . NewOCRRecognizeImageBody (
fileb64Encoded ,
recognitionSettings ,
)
taskId , httpRes , err := apiClient . RecognizeImageApi . PostRecognizeImage ( context . Background ()). OCRRecognizeImageBody ( requestBody ). Execute ()
if err != nil || httpRes . StatusCode != 200 {
fmt . Println ( "API error:" , err )
return
}
fmt . Printf ( "File successfully sent. Your TaskID is %s \n" , taskId )
ocrResp , httpRes , err := apiClient . RecognizeImageApi . GetRecognizeImage ( context . Background ()). Id ( taskId ). Execute ()
if err != nil || httpRes . StatusCode != 200 || ocrResp == nil {
fmt . Println ( "API error:" , err )
return
}
if * ocrResp . TaskStatus == asposeocrcloud . OCRTASKSTATUS_COMPLETED {
if ! ocrResp . Results [ 0 ]. Data . IsSet () {
fmt . Println ( "Response is empty" )
return
}
decodedBytes , err := base64 . StdEncoding . DecodeString ( * ocrResp . Results [ 0 ]. Data . Get ())
if err != nil {
fmt . Println ( "Decode error:" , err )
return
}
resultFilePath := "../results/" + taskId + ".txt"
err = ioutil . WriteFile ( resultFilePath , decodedBytes , 0644 )
if err != nil {
fmt . Println ( "Write file error:" , err )
return
}
fmt . Printf ( "Task result successfully saved at %s \n" , resultFilePath )
} else {
fmt . Printf ( "Sorry, task %s is not completed yet. You can request results later. Task status: %s\n" , taskId , * ocrResp . TaskStatus )
}
}