←Select platform

AddPage(string,OcrProgressCallback) Method

Summary
Adds a page from a disk file.
Syntax
C#
Objective-C
C++/CLI
Python
public IOcrPage AddPage( 
   string fileName, 
   OcrProgressCallback callback 
) 
- (nullable LTOcrPage *)addPageWithFile:(NSString *)fileName  
                                  error:(NSError **)error 
def AddPage(self,fileName,callback): 

Parameters

fileName
The name of the file containing the image.

callback
Optional callback to show operation progress.

Return Value

The IOcrPage object that define the newly added page.

Remarks

This method will load the first page from a raster image file on disk and adds it to the OCR document.

To add all or specific range of the pages of a multipage image file to the OCR document, use the AddPages(string fileName, int imageFirstPageNumber, int imageLastPageNumber, OcrProgressCallback callback) method.

This method will add the page to the end of the collection if you already have pages in this IOcrPageCollection.

If you passed a RasterCodecs object to the IOcrEngine.Startup, then this method will use the same RasterCodecs object to load the raster image file. If you did not pass a RasterCodecs object, the engine will create an instance the first time one of the add or export page methods is called.

The image file in  fileName can be any of the file formats supported by LEADTOOLS. For more information, refer to Summary of All Supported Image File Formats.

You can use the OcrProgressCallback to show the operation progress or to abort it. For more information and an example, refer to OcrProgressCallback.

The LEADTOOLS OCR engine supports pages of dots per inch (DPI) values of 150 and greater. If you try to add a page with a DPI of less than 150 then the engine might be able to recognize any data from this page.

Note: The value of the "Recognition.ShareOriginalImage" (only supported by the LEADTOOLS OCR Module - LEAD Engine) setting is not used when calling this method. The engine loads the image(s) and sets them in the pages internally. The original image reference can be obtained from the page using IOcrPage.GetRasterImage(OcrPageType.Original). Sharing the original image minimizes the memory used during OCR operations.

This member only works with memory-based documents and will throw an exception otherwise. For more information, refer to IOcrDocumentManager.CreateDocument and Programming with the LEADTOOLS .NET OCR.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Ocr; 
using Leadtools.Document.Writer; 
 
public void OcrEngineExample() 
{ 
   // 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 tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"); 
      string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.pdf"); 
 
      // Create an OCR document 
      using (IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument()) 
      { 
         // Add a page to the document 
         IOcrPage ocrPage = ocrDocument.Pages.AddPage(tifFileName, null); 
 
         // Recognize the page 
         // Note, Recognize can be called without calling AutoZone or manually adding zones. The engine will 
         // check and automatically auto-zones the page 
         ocrPage.AutoZone(null); 
         ocrPage.Recognize(null); 
 
         // Save the document we have as PDF 
         ocrDocument.Save(pdfFileName, DocumentFormat.Pdf, null); 
      } 
 
      // Shutdown the engine 
      // Note: calling Dispose will also automatically shutdown the engine if it has been started 
      ocrEngine.Shutdown(); 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
   public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS23\Bin\Common\OcrLEADRuntime"; 
} 
 
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 IOcrEngineExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   final String OCR_LEAD_RUNTIME_DIR = "C:\\LEADTOOLS23\\Bin\\Common\\OcrLEADRuntime"; 
   // Create an instance of the engine 
   OcrEngine ocrEngine = OcrEngineManager.createEngine(OcrEngineType.LEAD); 
   // Start the engine using default parameters 
   String pdfFileName = combine(LEAD_VARS_IMAGES_DIR, "Ocr1.pdf"); 
   ILeadStream leadStream = LeadStreamFactory.create("C:\\LEADTOOLS23\\Resources\\Images\\Ocr1.tif"); 
 
   ocrEngine.startup(null, null, null, OCR_LEAD_RUNTIME_DIR); 
   assertTrue(ocrEngine.isStarted()); 
 
   // Create an OCR document 
   OcrDocument ocrDocument = ocrEngine.getDocumentManager().createDocument(); 
 
   // Add a page to the document 
   OcrPage ocrPage = ocrDocument.getPages().addPage(leadStream, null); 
 
   // Recognize the page 
   // Note, Recognize can be called without calling AutoZone or manually adding 
   // zones. The engine will check and automatically auto-zones the page 
   ocrPage.autoZone(null); 
   ocrPage.recognize(null); 
 
   // Save the document we have as PDF 
   ocrDocument.save(pdfFileName, DocumentFormat.PDF, null); 
 
   // Shutdown the engine 
   // Note: calling Dispose will also automatically shutdown the engine if it has 
   // been started 
   ocrEngine.shutdown(); 
   assertTrue("File unsuccessfully saved", new File(pdfFileName).exists()); 
   System.out.println("Command run, file saved to " + combine(LEAD_VARS_IMAGES_DIR, "Ocr1.pdf")); 
} 
Requirements

Target Platforms

Help Version 23.0.2024.3.3
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Ocr Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.