Operation to be performed on an OCR runtime file.
public enum OcrRuntimeFileMode public:enum class OcrRuntimeFileMode sealed
class OcrRuntimeFileMode(Enum):Exists = 0Open = 1Close = 2
| Value | Member | Description |
|---|---|---|
| 0 | Exists | Check to see if the file exists |
| 1 | Open | Open the file for reading |
| 2 | Close | Close the file after reading |
Refer to IOcrEngine.RuntimeFileCallback for more information.
using Leadtools;using Leadtools.Codecs;using Leadtools.Ocr;using Leadtools.Document.Writer;public static void OcrRuntimeFileCallbackExample(){// This example assumes that some or all of the OCR runtime files are copied into "C:\MyDir" folder and simulates// an environment where the runtime files can be obtained through helper methods HasResource and GetResourceStream.// Create an OCR engine instanceIOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD);// Install a OCR file runtime handlerocrEngine.RuntimeFileCallback = MyRuntimeFileCallback;// Startup the engineocrEngine.Startup(null, null, null,null /* startupParameters is null*/);// Perform OCR operationocrEngine.AutoRecognizeManager.Run(@"C:\LEADTOOLS22\Resources\Images\ocr1.tif",@"C:\LEADTOOLS22\Resources\Images\out.pdf",DocumentFormat.Pdf,null,null);// ShutdownocrEngine.Shutdown();// Remove the handlerocrEngine.RuntimeFileCallback = null;// Dispose the engineocrEngine.Dispose();}private static RasterExceptionCode MyRuntimeFileCallback(IOcrEngine engine, OcrRuntimeFile runtimeFile){// Called by the OCR engine for each runtime file operationRasterExceptionCode result = RasterExceptionCode.Success;// Check the operation:switch (runtimeFile.Mode){case OcrRuntimeFileMode.Exists:Debug.WriteLine($"MyRuntimeFileCallback does '{runtimeFile.FileName}' exist");// The engine is checking if a certain file exists, call our HasResource helperif (!HasResource(runtimeFile.FileName))result = RasterExceptionCode.FileNotFound;break;case OcrRuntimeFileMode.Open:Debug.WriteLine($"MyRuntimeFileCallback open '{runtimeFile.FileName}'");// The engine requested to open the file for reading, call our GetResourceStream helper// and set the Stream property accordinglyruntimeFile.Stream = GetResourceStream(runtimeFile.FileName);break;case OcrRuntimeFileMode.Close:Debug.WriteLine($"MyRuntimeFileCallback close '{runtimeFile.FileName}'");// The engine requested to close the file after reading.// Dispose our streamruntimeFile.Stream.Dispose();break;}return result;}private static bool HasResource(string resourceName){// Do we have this resource?// In our simulation, we will simply check if the file exist on disk// In an Android application, this can check if a resource with this name was embeddedreturn System.IO.File.Exists(Path.Combine(@"C:\MyDir", resourceName));}private static Stream GetResourceStream(string resourceName){// Get a stream that can read from resource// In our simulation, we will simply check if the file exist on disk// In an Android application, this can call the appropriate platform API to obtain// a stream to the resourcereturn System.IO.File.OpenRead(Path.Combine(@"C:\MyDir", resourceName));}
import java.io.File;import java.io.IOException;import java.nio.file.Files;import java.nio.file.Path;import java.nio.file.Paths;import org.junit.*;import org.junit.runner.JUnitCore;import org.junit.runner.Result;import org.junit.runner.notification.Failure;import static org.junit.Assert.assertTrue;import leadtools.*;import leadtools.codecs.*;import leadtools.document.writer.*;import leadtools.ocr.*;public void IOcrRuntimeFileCallbackExample() {final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images";final String OCR_LEAD_RUNTIME_DIR = "C:\\LEADTOOLS23\\Bin\\Common\\OcrLEADRuntime";// Create an OCR engine instanceOcrEngine ocrEngine = OcrEngineManager.createEngine(OcrEngineType.LEAD);// Install a OCR file runtime handlerocrEngine.setRuntimeFileCallback(MyRuntimeFileCallback);// Startup the engineocrEngine.startup(null, null, null, OCR_LEAD_RUNTIME_DIR);assertTrue(ocrEngine.isStarted());// Perform OCR operationocrEngine.getAutoRecognizeManager().run(combine(LEAD_VARS_IMAGES_DIR, "ocr1.tif"),combine(LEAD_VARS_IMAGES_DIR, "out.pdf"),DocumentFormat.PDF, null);// ShutdownocrEngine.shutdown();assertTrue(!ocrEngine.isStarted());// Remove the handlerocrEngine.setRuntimeFileCallback(null);// Dispose the engineocrEngine.dispose();System.out.println("OCR operation completed successfully");}OcrRuntimeFileCallbackListener MyRuntimeFileCallback = new OcrRuntimeFileCallbackListener() {@Overridepublic RasterExceptionCode onCallback(OcrEngine arg0, OcrRuntimeFile runtimeFile) {// Called by the OCR engine for each runtime file operationRasterExceptionCode result = RasterExceptionCode.SUCCESS;System.out.println(runtimeFile.getFileName());// Check the operation:switch (runtimeFile.getMode()) {case EXISTS:System.out.println("MyRuntimeFileCallback does " + runtimeFile.getFileName() + " exist");// The engine is checking if a certain file exists, call our HasResource helperif (!hasResource(runtimeFile.getFileName()))result = RasterExceptionCode.FILE_NOT_FOUND;break;case OPEN:System.out.println("MyRuntimeFileCallback open " + runtimeFile.getFileName());// The engine requested to open the file for reading, call our GetResourceStream// helper// and set the Stream property accordinglyruntimeFile.setStream(getResourceStream(runtimeFile.getFileName()));break;case CLOSE:System.out.println("MyRuntimeFileCallback close " + runtimeFile.getFileName());// The engine requested to close the file after reading.// Dispose our streamruntimeFile.getStream().dispose();break;}return result;}};private boolean hasResource(String resourceName) {final String OCR_LEAD_RUNTIME_DIR = "C:\\LEADTOOLS23\\Bin\\Common\\OcrLEADRuntime";// Do we have this resource?// In our simulation, we will simply check if the file exist on disk// In an Android application, this can check if a resource with this name was// embeddedFile file = new File(combine(OCR_LEAD_RUNTIME_DIR, resourceName));return file.exists();}private ILeadStream getResourceStream(String resourceName) {final String OCR_LEAD_RUNTIME_DIR = "C:\\LEADTOOLS23\\Bin\\Common\\OcrLEADRuntime";// Get a stream that can read from resource// In our simulation, we will simply check if the file exist on disk// In an Android application, this can call the appropriate platform API to// obtain// a stream to the resourcereturn LeadStreamFactory.create(combine(OCR_LEAD_RUNTIME_DIR, resourceName));}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
