public IOcrPage CreatePage(RasterImage image,OcrImageSharingMode sharingMode)
Function CreatePage( _ByVal image As RasterImage, _ByVal sharingMode As OcrImageSharingMode _) As IOcrPage
- (nullable LTOcrPage *)createPage:(LTRasterImage *)image sharingMode:(LTOcrImageSharingMode)sharingMode error:(NSError **)error public OcrPage createPage(RasterImage image, OcrImageSharingMode sharingMode) IOcrPage^ CreatePage(RasterImage^ image,OcrImageSharingMode sharingMode)
image
Source raster image. This parameter cannot be null.
sharingMode
Options to determine the ownership of image.
An IOcrPage ready to be used.
Use CreatePage to quickly create an IOcrPage from a RasterImage directly, call the necessary method (such as IOcrPage.Recognize) and then obtain the text directly using IOcrPage.GetText or IOcrPage.GetRecognizedCharacters.
To save the result IOcrPage to a document file such as PDF or Microsoft Word by directly, you must create an IOcrDocument object in file mode and add the page to it using IOcrDocument.Add.
The IOcrPage interface implements IDisposable. It is highly recommended that you call Dispose (or use the using statement in C# or Using statement in VB) after you finish using this IOcrPage instance.
The value of sharingMode determines what happens to the raster image object after it has been used to create the page as follows:
| Option | Description |
|---|---|
| OcrImageSharingMode.None |
The result IOcrPage does not own the image. When IOcrPage is disposed, the image is not disposed. This mode is useful for quickly creating an OCR page (and getting the recognition result) from an image that is already used in other parts of your application. For example, the image is being viewed in the image viewer. Using this option will save memory because you do not have to create a copy of the image and the page will use the same image data when performing recognition. Important: In this mode, it is the user responsibility to keep the raster image object alive for the whole duration the page is alive. Only dispose the raster image after the IOcrPage object is disposed and no longer used. |
| OcrImageSharingMode.AutoDispose |
The result IOcrPage owns the image. When IOcrPage is disposed, the image is disposed as well. This mode is useful when the image is no longer used by other parts of your application. For example, the image is obtained from scanning or the camera and is only to be used for OCRing. Using this option will transfer the ownership of the image object to the page and it will be disposed when the page is disposed. |
This example will load a raster image from disk, OCR it to obtain the results and print it to the console. It will then add the page to a document to create a PDF file.
using Leadtools;using Leadtools.Codecs;using Leadtools.Ocr;using Leadtools.Document.Writer;private static void CreatePageExample(){// Create an instance of the engineusing (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, false)){// Start the engine using default parametersocrEngine.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 memoryusing (IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument(null, OcrCreateDocumentOptions.None)){foreach (string tifFileName in tifFileNames){// Load the TIFF file as imageRasterImage rasterImage = ocrEngine.RasterCodecsInstance.Load(tifFileName, 1);// Create an IOcrPage instance from this imageusing (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 anymorerasterImage = null;// Recognize the pageocrPage.Recognize(null);// Show the resultsstring text = ocrPage.GetText(-1);Console.WriteLine("Recognition text for " + tifFileName);Console.WriteLine(text);// Add this recognized pageocrDocument.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 documentocrDocument.Save(pdfFileName, DocumentFormat.Pdf, null);}}}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS 20\Bin\Common\OcrLEADRuntime";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.OcrImports Leadtools.Document.WriterPrivate Shared Sub CreatePageExample()' Create an instance of the engineUsing ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, False)' Start the engine using default parametersocrEngine.Startup(Nothing, Nothing, Nothing, LEAD_VARS.OcrLEADRuntimeDir)Dim tifFileNames() As String ={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")}Dim pdfFileName As String = 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 memoryUsing ocrDocument As IOcrDocument = ocrEngine.DocumentManager.CreateDocument(Nothing, OcrCreateDocumentOptions.None)For Each tifFileName As String In tifFileNames' Load the TIFF file as imageDim rasterImage As RasterImage = ocrEngine.RasterCodecsInstance.Load(tifFileName, 1)' Create an IOcrPage instance from this imageUsing ocrPage As IOcrPage = ocrEngine.CreatePage(rasterImage, OcrImageSharingMode.AutoDispose)' We told the page to dispose the image when no longer needed, so rasterImage should not be used anymorerasterImage = Nothing' Recognize the pageocrPage.Recognize(Nothing)' Show the resultsDim text As String = ocrPage.GetText(-1)Console.WriteLine("Recognition text for " + tifFileName)Console.WriteLine(text)' Add this recognized pageocrDocument.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 neededEnd UsingNext' Now we can save the documentocrDocument.Save(pdfFileName, DocumentFormat.Pdf, Nothing)End UsingEnd UsingEnd SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"Public Const OcrLEADRuntimeDir As String = "C:\LEADTOOLS 20\Bin\Common\OcrLEADRuntime"End Class
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
