←Select platform

PageImage Property

Summary
Gets or sets the image used with the current operation.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public RasterImage PageImage { get; set; } 
@property (nonatomic, strong, nullable) LTRasterImage *pageImage; 
public RasterImage getPageImage() 
public void setPageImage(RasterImage value) 
public: 
property RasterImage^ PageImage { 
   RasterImage^ get(); 
   void set (    RasterImage^ ); 
} 
PageImage # get and set (OcrAutoRecognizeJobOperationEventArgs) 

Property Value

An RasterImage instance that specifies the raster image being used in the current operation if any.

Remarks

This member is valid only when the current operation is:

Operation Description
OcrAutoRecognizeManagerJobOperation.LoadPage

When the value of PostOperation is false, then PageImage holds the raster image object to be used to create the IOcrPage. By default this will be null and the engine will load the image from the input document.

You can override this behavior by setting your own RasterImage in this property. The engine will use the supplied image to create the page.

OcrAutoRecognizeManagerJobOperation.SavePage

PageImage holds the raster image to be used with the final document if the page contains graphics zone (to obtain the graphics area) or if the format supports "image over text" such as PDF with Image/Text.

By default this is either the original image of the page (same instance obtained through IOcrPage.GetRasterImage with OcrPageType.Original or the overlay image if the user set a value using IOcrPage.SetOverlayImage.

You can set your own image to be used for this purpose by setting the value in PageImage during this operation when PostOperation is false.

Note that the engine will not dispose this image reference, therefore, it is recommended that the user will call Dispose on PageImage in the next event occurrence (when PostOperation is true).

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Ocr; 
using Leadtools.Document.Writer; 
using Leadtools.Forms.Common; 
using Leadtools.WinForms; 
 
private static void PageExampleExample() 
{ 
   var imageFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"); 
   var outFileName = Path.Combine(LEAD_VARS.ImagesDir, "result.pdf"); 
 
   using (var ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD)) 
   { 
      ocrEngine.Startup(null, null, null, LEAD_VARS.OcrLEADRuntimeDir); 
 
      // Use PDF with image/text option 
      var pdfOptions = ocrEngine.DocumentWriterInstance.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions; 
      pdfOptions.ImageOverText = true; 
      ocrEngine.DocumentWriterInstance.SetOptions(DocumentFormat.Pdf, pdfOptions); 
 
      // Create an OCR AutoRecognize job 
      var jobData = new OcrAutoRecognizeJobData 
      { 
         ImageFileName = imageFileName, 
         FirstPageNumber = 1, 
         LastPageNumber = -1, 
         DocumentFileName = outFileName, 
         Format = DocumentFormat.Pdf 
      }; 
 
      var autoRecognizeManager = ocrEngine.AutoRecognizeManager; 
      var job = autoRecognizeManager.CreateJob(jobData); 
 
      EventHandler<OcrAutoRecognizeJobOperationEventArgs> jobOperation = (sender, e) => 
      { 
         if (e.Operation == OcrAutoRecognizeManagerJobOperation.SavePage) 
         { 
            if (!e.PostOperation) 
            { 
               // We will set a new image that is all white, same size and resolution as the 
               // page 
               var overlayImage = RasterImage.Create( 
                  e.Page.Width, 
                  e.Page.Height, 
                  24, 
                  e.Page.DpiX, 
                  RasterColor.FromKnownColor(RasterKnownColor.White)); 
               e.PageImage = overlayImage; 
            } 
            else 
            { 
               // Dispose the image we created 
               e.PageImage.Dispose(); 
               e.PageImage = null; 
            } 
         } 
      }; 
 
      autoRecognizeManager.JobOperation += jobOperation; 
 
      OcrAutoRecognizeManagerJobStatus status; 
 
      try 
      { 
         status = autoRecognizeManager.RunJob(job); 
      } 
      finally 
      { 
         autoRecognizeManager.JobOperation -= jobOperation; 
      } 
 
      Console.WriteLine(status); 
 
      // The result PDF file will have an overlay image that is all white, with recognition text underneeth 
   } 
} 
 
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.FileNotFoundException; 
import java.io.FileWriter; 
import java.io.FilenameFilter; 
import java.io.IOException; 
import java.nio.file.Files; 
import java.nio.file.Path; 
import java.nio.file.Paths; 
import java.util.ArrayList; 
import java.util.concurrent.ExecutorService; 
import java.util.concurrent.Executors; 
import java.util.concurrent.atomic.AtomicInteger; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.document.writer.*; 
import leadtools.internal.AutoResetEvent; 
import leadtools.ocr.*; 
 
 
public void OcrAutoRecognizeJobPageImageExample() { 
   String LEAD_VARS_ImagesDir = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String LEAD_VARS_OcrLEADRuntimeDir = "C:\\LEADTOOLS23\\Bin\\Common\\OcrLEADRuntime"; 
   String imageFileName = combine(LEAD_VARS_ImagesDir, "Ocr1.tif"); 
   String outFileName = combine(LEAD_VARS_ImagesDir, "result.pdf"); 
 
   var ocrEngine = OcrEngineManager.createEngine(OcrEngineType.LEAD); 
   ocrEngine.startup(null, null, null, LEAD_VARS_OcrLEADRuntimeDir); 
 
   // Use PDF with image/text option 
   var pdfOptions = ocrEngine.getDocumentWriterInstance().getOptions(DocumentFormat.PDF); 
   ocrEngine.getDocumentWriterInstance().setOptions(DocumentFormat.PDF, pdfOptions); 
 
   // Create an OCR AutoRecognize job 
   var jobData = new OcrAutoRecognizeJobData(); 
   jobData.setImageFileName(imageFileName); 
   jobData.setFirstPageNumber(1); 
   jobData.setLastPageNumber(-1); 
   jobData.setDocumentFileName(outFileName); 
   jobData.setFormat(DocumentFormat.PDF); 
 
   var autoRecognizeManager = ocrEngine.getAutoRecognizeManager(); 
   var job = autoRecognizeManager.createJob(jobData); 
 
   autoRecognizeManager.addJobOperationListener(jobOperation); 
 
   OcrAutoRecognizeManagerJobStatus status; 
 
   try { 
      status = autoRecognizeManager.runJob(job); 
   } finally { 
      autoRecognizeManager.removeJobOperationListener(jobOperation); 
   } 
 
   System.out.println(status); 
 
   // The result PDF file will have an overlay image that is all white, with 
   // recognition text underneeth 
   ocrEngine.dispose(); 
} 
 
OcrAutoRecognizeJobOperationListener jobOperation = new OcrAutoRecognizeJobOperationListener() { 
 
   @Override public void onOperation(OcrAutoRecognizeJobOperationEvent e) { 
      if (e.getOperation()==OcrAutoRecognizeManagerJobOperation.SAVE_PAGE) { 
         if (!e.isPostOperation()) { 
            // We will set a new image that is all white, same size and resolution as the 
            // page 
            RasterImage overlayImage=RasterImage.create( 
               e.getPage().getWidth(), 
               e.getPage().getHeight(), 
               24, 
               e.getPage().getDpiX(), 
               RasterColor.fromKnownColor(RasterKnownColor.WHITE) 
            ); 
            e.setPageImage(overlayImage); 
         } else { 
            // Dispose the image we created 
            e.getPageImage().dispose();e.setPageImage(null); 
         } 
      } 
   } 
 
}; 
Requirements

Target Platforms

Help Version 23.0.2024.4.19
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.