Copy using Aspose.OCR.Cloud.SDK.Api ;
using Aspose.OCR.Cloud.SDK.Model ;
using System.Text ;
namespace Example
{
internal class Program
{
static void Main ( string [] args )
{
RecognizeTableApi recognizeTableApi = new RecognizeTableApi ( "<Client Id>" , "<Client Secret>" );
byte [] tableImage = File . ReadAllBytes ( "table.png" );
OCRSettingsRecognizeTable recognitionSettings = new OCRSettingsRecognizeTable {
Language = Language . English ,
ResultTypeTable = ResultTypeTable . Csv
};
OCRRecognizeTableBody source = new OCRRecognizeTableBody ( tableImage , recognitionSettings );
string taskID = recognizeTableApi . PostRecognizeTable ( source );
OCRResponse result = recognizeTableApi . GetRecognizeTable ( taskID );
Console . WriteLine ( Encoding . UTF8 . GetString ( result . Results [ 0 ]. Data ));
}
}
}
Visit our GitHub repository for a working code and sample files: https://github.com/aspose-ocr-cloud/aspose-ocr-cloud-dotnet
Copy
import Aspose.OCR.Cloud.SDK.RecognizeTableApi ;
import Aspose.OCR.Cloud.SDK.model.* ;
import java.nio.file.Files ;
import java.nio.file.Path ;
import java.nio.file.Paths ;
public class Example {
public static void main ( String [] args ) {
RecognizeTableApi api = new RecognizeTableApi ( "<Client Id>" , "<Client Secret>" );
byte [] tableImage = Files . readAllBytes ( Path . of ( "table.png" ));
OCRSettingsRecognizeTable settings = new OCRSettingsRecognizeTable ();
settings . setLanguage ( Language . ENGLISH );
settings . setResultTypeTable ( ResultTypeTable . CSV );
OCRRecognizeTableBody requestBody = new OCRRecognizeTableBody ();
requestBody . setTable ( tableImage );
requestBody . setSettings ( settings );
String taskId = api . postRecognizeTable ( requestBody );
OCRResponse apiResponse = api . getRecognizeTable ( taskId );
System . out . println ( new String ( apiResponse . getResults (). get ( 0 ). getData (), StandardCharsets . UTF_8 ) + "\n\n" );
}
}
Visit our GitHub repository for a working code and sample files: https://github.com/aspose-ocr-cloud/aspose-ocr-cloud-java
Copy
RecognizeTableApi api = new RecognizeTableApi ( "<Client Id>" , "<Client Secret>" );
String tableFileName = "table.png" ;
InputStream inputStream = context . getAssets (). open ( tableFileName );
int size = inputStream . available ();
byte [] tableImage = new byte [ size ];
inputStream . read ( tableImage );
inputStream . close ();
OCRSettingsRecognizeTable settings = new OCRSettingsRecognizeTable ();
settings . setLanguage ( Language . ENGLISH );
settings . setResultTypeTable ( ResultTypeTable . CSV );
OCRRecognizeTableBody requestBody = new OCRRecognizeTableBody ();
requestBody . setTable ( tableImage );
requestBody . setSettings ( settings );
String taskId = api . postRecognizeTable ( requestBody );
OCRResponse apiResponse = api . getRecognizeTable ( taskId );
System . out . println ( new String ( apiResponse . getResults (). get ( 0 ). getData (), StandardCharsets . UTF_8 ) + "\n\n" );
Visit our GitHub repository for a working code and sample files: https://github.com/aspose-ocr-cloud/aspose-ocr-cloud-android
Copy const AsposeOcrCloud10040Api = require ( 'aspose_ocr_cloud_5_0_api' );
const path = require ( "path" );
const fs = require ( "fs" );
const request = require ( 'aspose_ocr_cloud_5_0_api/node_modules/request' );
var api ;
function connect ( ) {
return new Promise ( function ( resolve , reject ) {
request . post ({
headers : { "ContentType" : "application/x-www-form-urlencoded" , "Accept" : "application/json;charset=UTF-8" },
url : "https://api.aspose.cloud/connect/token" ,
form : JSON . parse ( '{"client_id": "<Client Id>", "client_secret": "<Client Secret>", "grant_type": "client_credentials"}' )
}, ( err , res , body ) => {
if ( err ) {
reject ( err );
}
resolve ( body );
});
});
}
function callPostTableRecognizeFunction ( body , img_path ) {
return new Promise ( function ( resolve , reject ) {
api = new AsposeOcrCloud10040Api . RecognizeTableApi ();
api . apiClient . basePath = "https://api.aspose.cloud/v5.0/ocr" ;
var body_res = JSON . parse ( body );
api . apiClient . authentications = {
'JWT' : {
type : 'oauth2' ,
accessToken : body_res [ 'access_token' ]
}
}
api . apiClient . defaultHeaders = {
"User-Agent" : "OpenAPI-Generator/1005.0/Javascript"
}
var filePath = path . normalize ( img_path );
var buffer = Buffer . alloc ( 1024 * 50 );
var fileData = fs . readFileSync ( filePath , buffer );
let settings = new AsposeOcrCloud10040Api . OCRSettingsRecognizeTable ();
settings . Language = "English" ;
settings . ResultType = "Text" ;
let requestData = new AsposeOcrCloud10040Api . OCRRecognizeTableBody ( fileData . toString ( 'base64' ), settings );
api . postRecognizeTable ( requestData , ( err , res , body ) => {
if ( err ) {
reject ( err );
}
resolve ( res );
});
});
}
function callGetTableFunction ( id ) {
return new Promise ( function ( resolve , reject ) {
api . getRecognizeTable ( id , ( err , res , body ) => {
if ( err ) {
reject ( err );
}
resolve ( body );
})
})
}
function processResult ( body ) {
console . log ( 'Processing results...' )
const json_res = JSON . parse ( body [ 'text' ]);
for ( const key in json_res [ 'results' ]){
console . log ( atob ( json_res [ 'results' ][ key ][ 'data' ]))
}
}
connect (). then (
access_token => callPostTableRecognizeFunction ( access_token , "source.png" )
). then (
x => new Promise ( resolve => setTimeout (() => resolve ( x ), 1000 ))
). then (
id => callGetTableFunction ( id )
). then (
body => processResult ( body )
)
Visit our GitHub repository for a working code and sample files: https://github.com/aspose-ocr-cloud/aspose-ocr-cloud-nodejs