stringdocFileName="c:\\MyData\\MyDocument.pdf";vartext=awaitOCRManager.Instance.ExtractTextFromDocumentAsync(docFileName);// or extract from a specific page//int pageIdx = 1;//var text = await OCRManager.Instance.ExtractTextFromDocumentAsync(deedFileName, pageIdx);
Extract text from a document using a CancellationTracker
stringdocFileName="c:\\MyData\\MyDocument.pdf";vartext="";boolcanceled=false;using(CancelableProgressorSourcecps=newCancelableProgressorSource("Reading document","Canceled")){canceled=awaitQueuedTask.Run<bool>(async()=>{try{text=awaitArcGIS.Core.OCR.OCRManager.Instance.ExtractTextFromDocumentAsync(docFileName,cps.Progressor.CancellationToken);}catch(OperationCanceledExceptioncex){returntrue;}catch(Exceptionex){}returnfalse;},cps.Progressor);}if(canceled){// to do - some cancel action}else{// to do - something with text}
Extract text from a document using OCROptions
stringdocFileName="c:\\MyData\\MyDocument.tiff";varocrOptions=newOCROptions(docFileName);ocrOptions.OutputType=OCROutputType.Text;// set a specific page if necessary// (if not set, then all pages are scanned)// ocrOptions.Page = pageIdx;// set the resolution if necessary// ocrOptions.Resolution = 400;varoutput=awaitOCRManager.Instance.ExtractFromDocumentAsync(ocrOptions);vartextOutput=outputasOCRTextOutput;vartext=textOutput.Text;
Extract text from a document using a different model
stringdocFileName="c:\\MyData\\MyDocument.jpg";varocrOptions=newOCROptions(docFileName);ocrOptions.OutputType=OCROutputType.Text;// set a specific page if necessary// (if not set, then all pages are scanned)// ocrOptions.Page = pageIdx;// set the resolution if necessary// ocrOptions.Resolution = 400;// set the language// (de.traineddata should be installed at (arcgis_install_folder)\Resources\OCR)// if file cannot be found an exception is thrownocrOptions.Model="de";try{varoutput=awaitOCRManager.Instance.ExtractFromDocumentAsync(ocrOptions);vartextOutput=outputasOCRTextOutput;vartext=textOutput.Text;}catch(ArcGIS.Core.OCR.Exceptions.OCRExceptionex){}
Extract TSV output from a document
stringdocFileName="c:\\MyData\\MyDocument.bmp";varocrOptions=newOCROptions(docFileName);ocrOptions.OutputType=OCROutputType.TSV;// set a specific page if necessary// (if not set, then all pages are scanned)// ocrOptions.Page = pageIdx;// set the resolution if necessary// ocrOptions.Resolution = 400;varoutput=awaitOCRManager.Instance.ExtractFromDocumentAsync(ocrOptions);if(outputisOCRTSVOutputocr_tsvOutput){// process the tsv outputforeach(varpageinocr_tsvOutput.Pages){foreach(varblockinpage.Blocks){foreach(varparainblock.Paragraphs){foreach(varlineinpara.Lines){foreach(varwordinline.Words){varcontent=word.Content;varconfidence=word.Confidence;// process content according to confidence}}}}}}