Error processing SSI file
LEADTOOLS OCR (Leadtools.Forms.Ocr assembly)

Show in webframe

PageImage Property








Gets or sets the image used with the current operation.
Syntax
public RasterImage PageImage {get; set;}
'Declaration
 
Public Property PageImage As RasterImage
'Usage
 
Dim instance As OcrAutoRecognizeJobOperationEventArgs
Dim value As RasterImage
 
instance.PageImage = value
 
value = instance.PageImage
public RasterImage PageImage {get; set;}
@property (nonatomic, strong, nullable) LTRasterImage *pageImage
public RasterImage getPageImage()
public void setPageImage(RasterImage value)
            
 <br/>get_PageImage();<br/>set_PageImage(value);<br/>Object.defineProperty('PageImage'); 
public:
property RasterImage^ PageImage {
   RasterImage^ get();
   void set (    RasterImage^ value);
}

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
Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Forms.Ocr
Imports Leadtools.Forms.DocumentWriters
Imports Leadtools.Forms
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.Advantage, False)
      ocrEngine.Startup(Nothing, Nothing, Nothing, LEAD_VARS.OcrAdvantageRuntimeDir)

      ' 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 underneeth
   End Using
End Sub

Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
Public Const OcrAdvantageRuntimeDir As String = "C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime"
End Class
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Forms.Ocr;
using Leadtools.Forms.DocumentWriters;
using Leadtools.Forms;
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.Advantage, false))
   {
      ocrEngine.Startup(null, null, null, LEAD_VARS.OcrAdvantageRuntimeDir);

      // 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 OcrAdvantageRuntimeDir = @"C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime";
}
Requirements

Target Platforms

See Also

Reference

OcrAutoRecognizeJobOperationEventArgs Class
OcrAutoRecognizeJobOperationEventArgs Members
Programming with LEADTOOLS .NET OCR

Error processing SSI file
Leadtools.Forms.Ocr requires a Recognition or Document Imaging Suite license and unlock key. For more information, refer to: LEADTOOLS Toolkit Features