Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Forms.Ocr
Imports Leadtools.Forms.DocumentWriters
Imports Leadtools.Forms
Imports Leadtools.ImageProcessing.Core
<TestMethod>
Public Sub ExportPagesToRasterImageExample()
Dim tifFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "OcrMultiPage.tif")
Dim codecs As New RasterCodecs()
' Create an instance of the engine
Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, False)
' Since we have a RasterCodecs object, re-use it in the OCR engine. Although
' this demo will not use it, it is always a good practice
ocrEngine.Startup(codecs, Nothing, Nothing, LEAD_VARS.OcrAdvantageRuntimeDir)
' Create an OCR document
Using ocrDocument As IOcrDocument = ocrEngine.DocumentManager.CreateDocument()
' Loop through the images, add them to the document
For i As Integer = 0 To 3
Dim pageFileName As String = Path.Combine(LEAD_VARS.ImagesDir, String.Format("Ocr{0}.tif", i + 1))
ocrDocument.Pages.AddPage(pageFileName, Nothing)
Next
Console.WriteLine("OCR Document contains {0} pages", ocrDocument.Pages.Count)
' Export the pages from index 1 to 3 to a RasterImage object
Dim image As RasterImage = ocrDocument.Pages.ExportPages(1, 3)
Console.WriteLine("Image contains {0} pages", image.PageCount)
' Save this image to multi-page TIF file
codecs.Save(image, tifFileName, RasterImageFormat.Tif, 1, 1, -1, _
1, CodecsSavePageMode.Overwrite)
End Using
' Shutdown the engine
' Note: calling Dispose will also automatically shutdown the engine if it has been started
ocrEngine.Shutdown()
End Using
codecs.Dispose()
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.ImageProcessing.Core;
public void ExportPagesToRasterImageExample()
{
string tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "OcrMultiPage.tif");
RasterCodecs codecs = new RasterCodecs();
// Create an instance of the engine
using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false))
{
// Since we have a RasterCodecs object, re-use it in the OCR engine. Although
// this demo will not use it, it is always a good practice
ocrEngine.Startup(codecs, null, null, LEAD_VARS.OcrAdvantageRuntimeDir);
// Create an OCR document
using (IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument())
{
// Loop through the images, add them to the document
for (int i = 0; i < 4; i++)
{
string pageFileName = Path.Combine(LEAD_VARS.ImagesDir, string.Format("Ocr{0}.tif", i + 1));
ocrDocument.Pages.AddPage(pageFileName, null);
}
Console.WriteLine("OCR Document contains {0} pages", ocrDocument.Pages.Count);
// Export the pages from index 1 to 3 to a RasterImage object
RasterImage image = ocrDocument.Pages.ExportPages(1, 3);
Console.WriteLine("Image contains {0} pages", image.PageCount);
// Save this image to multi-page TIF file
codecs.Save(image, tifFileName, RasterImageFormat.Tif, 1, 1, -1, 1, CodecsSavePageMode.Overwrite);
}
// Shutdown the engine
// Note: calling Dispose will also automatically shutdown the engine if it has been started
ocrEngine.Shutdown();
}
codecs.Dispose();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
public const string OcrAdvantageRuntimeDir = @"C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime";
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Forms.Ocr;
using Leadtools.Forms.DocumentWriters;
using Leadtools.Forms;
using Leadtools.ImageProcessing.Core;
public async Task ExportPagesToRasterImageExample()
{
string tifFileName = "OcrMultiPage.tif";
RasterCodecs codecs = new RasterCodecs();
// Create an instance of the engine
IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false);
// Since we have a RasterCodecs object, re-use it in the OCR engine. Although
// this demo will not use it, it is always a good practice
ocrEngine.Startup(codecs, null, String.Empty, Tools.OcrEnginePath);
// Create an OCR document
IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument();
// Loop through the images, add them to the document
for(int i = 0; i < 4; i++)
{
string pageFileName = string.Format(@"Assets\Ocr{0}.tif", i + 1);
StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(pageFileName);
using (RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile)))
ocrDocument.Pages.AddPage(image, null);
}
Debug.WriteLine("OCR Document contains {0} pages", ocrDocument.Pages.Count);
// Export the pages from index 1 to 3 to a RasterImage object
RasterImage exportedImage = ocrDocument.Pages.ExportPages(1, 3);
Debug.WriteLine("Image contains {0} pages", exportedImage.PageCount);
// Save this image to multi-page TIF file
StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(tifFileName);
await codecs.SaveAsync(exportedImage, LeadStreamFactory.Create(saveFile), RasterImageFormat.Tif, 1, 1, -1, 1, CodecsSavePageMode.Overwrite);
// Shutdown the engine
ocrEngine.Shutdown();
codecs.Dispose();
}