[SerializableAttribute()]
public enum OcrImageSharingMode
typedef NS_ENUM(NSInteger, LTOcrImageSharingMode) {
LTOcrImageSharingModeNone,
LTOcrImageSharingModeAutoDispose,
};
public enum OcrImageSharingMode
[SerializableAttribute()]
public enum class OcrImageSharingMode
class OcrImageSharingMode(Enum):
None = 0
AutoDispose = 1
Value | Member | Description |
---|---|---|
0 | None | IOcrPage will not dispose the RasterImage when it is disposed. The page does not own the raster image. |
1 | AutoDispose | IOcrPage will dispose the RasterImage when it is disposed. The page owns the raster image. |
OcrImageSharingMode determines the ownership of the source raster image object passed to IOcrEngine.CreatePage.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Ocr;
using Leadtools.Document.Writer;
private static void CreatePageExample()
{
// Create an instance of the engine
using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD))
{
// Start the engine using default parameters
ocrEngine.Startup(null, null, null, LEAD_VARS.OcrLEADRuntimeDir);
string[] tifFileNames =
{
Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"),
Path.Combine(LEAD_VARS.ImagesDir, "Ocr2.tif"),
Path.Combine(LEAD_VARS.ImagesDir, "Ocr3.tif"),
Path.Combine(LEAD_VARS.ImagesDir, "Ocr4.tif")
};
string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.pdf");
// Create an OCR document to save the result as PDF
// Create the document using file mode since we are not keeping the OCR pages in memory
using (IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument(null, OcrCreateDocumentOptions.None))
{
foreach (string tifFileName in tifFileNames)
{
// Load the TIFF file as image
RasterImage rasterImage = ocrEngine.RasterCodecsInstance.Load(tifFileName, 1);
// Create an IOcrPage instance from this image
using (IOcrPage ocrPage = ocrEngine.CreatePage(rasterImage, OcrImageSharingMode.AutoDispose))
{
// We told the page to dispose the image when no longer needed, so rasterImage should not be used anymore
rasterImage = null;
// Recognize the page
ocrPage.Recognize(null);
// Show the results
string text = ocrPage.GetText(-1);
Console.WriteLine("Recognition text for " + tifFileName);
Console.WriteLine(text);
// Add this recognized page
ocrDocument.Pages.Add(ocrPage);
// The method above took a snapshot of the recognition data of the page and added it to the document
// The page is no longer needed
}
}
// Now we can save the document
ocrDocument.Save(pdfFileName, DocumentFormat.Pdf, null);
}
}
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";
public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS23\Bin\Common\OcrLEADRuntime";
}
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
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.