←Select platform

PageImage Property

Summary

Gets or sets the image used with the current operation.

Syntax
C#
VB
Objective-C
C++
Java
public RasterImage PageImage { get; set; } 
Public Property PageImage As RasterImage 
@property (nonatomic, strong, nullable) LTRasterImage *pageImage 
public RasterImage getPageImage() 
public void setPageImage(RasterImage value) 
public: 
property RasterImage^ PageImage { 
   RasterImage^ get(); 
   void set (    RasterImage^ ); 
} 

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#
VB
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, false)) 
   { 
      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:\Users\Public\Documents\LEADTOOLS Images"; 
   public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS 20\Bin\Common\OcrLEADRuntime"; 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Ocr 
Imports Leadtools.Document.Writer 
Imports Leadtools.Forms.Common 
Imports Leadtools.WinForms 
 
Private Shared Sub PageExampleExample() 
   Dim imageFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif") 
   Dim outFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "result.pdf") 
 
   Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, False) 
      ocrEngine.Startup(Nothing, Nothing, Nothing, LEAD_VARS.OcrLEADRuntimeDir) 
 
      ' Use PDF with image/text option 
      Dim pdfOptions As PdfDocumentOptions = DirectCast(ocrEngine.DocumentWriterInstance.GetOptions(DocumentFormat.Pdf), PdfDocumentOptions) 
      pdfOptions.ImageOverText = True 
      ocrEngine.DocumentWriterInstance.SetOptions(DocumentFormat.Pdf, pdfOptions) 
 
      ' Create an OCR AutoRecognize job 
      Dim jobData As New OcrAutoRecognizeJobData 
      jobData.ImageFileName = imageFileName 
      jobData.FirstPageNumber = 1 
      jobData.LastPageNumber = -1 
      jobData.DocumentFileName = outFileName 
      jobData.Format = DocumentFormat.Pdf 
 
      Dim autoRecognizeManager As IOcrAutoRecognizeManager = ocrEngine.AutoRecognizeManager 
      Dim job As IOcrAutoRecognizeJob = autoRecognizeManager.CreateJob(jobData) 
 
      Dim jobOperation As EventHandler(Of OcrAutoRecognizeJobOperationEventArgs) = 
         Sub(sender As Object, e As OcrAutoRecognizeJobOperationEventArgs) 
            If e.Operation = OcrAutoRecognizeManagerJobOperation.SavePage Then 
               If Not e.PostOperation Then 
                  ' We will set a new image that is all white, same size and resolution as the 
                  ' page 
                  Dim overlayImage As RasterImage = 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 = Nothing 
               End If 
            End If 
         End Sub 
 
      AddHandler autoRecognizeManager.JobOperation, jobOperation 
 
      Dim status As OcrAutoRecognizeManagerJobStatus 
 
      Try 
         status = autoRecognizeManager.RunJob(job) 
      Finally 
         RemoveHandler autoRecognizeManager.JobOperation, jobOperation 
      End Try 
 
      Console.WriteLine(status) 
 
      ' The result PDF file will have an overlay image that is all white, with recognition text underneath 
   End Using 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
   Public Const OcrLEADRuntimeDir As String = "C:\LEADTOOLS 20\Bin\Common\OcrLEADRuntime" 
End Class 

Requirements

Target Platforms

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

Leadtools.Ocr Assembly