public RasterImage PageImage { get; set; }
An RasterImage instance that specifies the raster image being used in the current operation if any.
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). |
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";
}