Leadtools.Forms.Ocrアセンブリ > Leadtools.Forms.Ocr名前空間 > IOcrPageCollectionインターフェース > AddPagesメソッド :AddPages(RasterImage、Int32、Int32、OcrProgressCallback)メソッド |
void AddPages( RasterImage image, int imageFirstPageNumber, int imageLastPageNumber, OcrProgressCallback callback )
'Declaration
Overloads Sub AddPages( _ ByVal image As RasterImage, _ ByVal imageFirstPageNumber As Integer, _ ByVal imageLastPageNumber As Integer, _ ByVal callback As OcrProgressCallback _ )
'Usage
Dim instance As IOcrPageCollection Dim image As RasterImage Dim imageFirstPageNumber As Integer Dim imageLastPageNumber As Integer Dim callback As OcrProgressCallback instance.AddPages(image, imageFirstPageNumber, imageLastPageNumber, callback)
void AddPages( RasterImage image, int imageFirstPageNumber, int imageLastPageNumber, OcrProgressCallback callback )
- (BOOL)addPagesWithImage:(LTRasterImage *)image inRange:(NSRange)range error:(NSError **)error
public void addPages(RasterImage image, int imageFirstPageNumber, int imageLastPageNumber, OcrProgressListener callback)
function Leadtools.Forms.Ocr.IOcrPageCollection.AddPages(RasterImage,Int32,Int32,OcrProgressCallback)( image , imageFirstPageNumber , imageLastPageNumber , callback )
void AddPages( RasterImage^ image, int imageFirstPageNumber, int imageLastPageNumber, OcrProgressCallback^ callback )
このメソッドは、新しく作成されたIOcrPageにRasterImageオブジェクト画像データをコピーします。したがって、このメソッドが返ったあと、imageとIOcrPageの関係がOCRドキュメント内部にありません。たとえば、このメソッドを呼び出した後にimageオブジェクトを必要としないならば、このメソッドが返ったあと、それを破棄しなければなりません。
このメソッドは、変化がimageになされないことを保証します。
OCRドキュメントにRasterImageオブジェクトのすべてのページを追加するショートカットは、そうですAddPages(image, 1, -1, callback)
。
RasterImageオブジェクトから単一のページを追加するために、AddPage(RasterImage image、OcrProgressCallbackコールバック)を使うことができます。
このIOcrPageCollectionにおけるページをすでに持っているならば、このメソッドはコレクションの終わりまでページを追加します。
操作進捗を示すか、それを中止するために、OcrProgressCallbackを使うことができます。詳細情報とサンプルについては、「OcrProgressCallback」を参照してください。
LEADTOOLS OCRエンジンは、150 ドット/インチ(DPI)以上のページをサポートします。DPIが150未満のページを追加しようとするとき、このページのデータを認識することができるかもしれません。
注意:設定している「Recognition.ShareOriginalImage」(Advantage OCRエンジンでサポートされるだけの)の値が、このメソッドを呼び出すとき、使われません。画像のコピーが作成され、ページ内に保存されます。ページ上でIOcrPage.GetRasterImage(OcrPageType.Original)を呼び出すと、null参照が返されます。
このメンバはメモリベースのドキュメントで機能して、そうでない場合例外をスローするだけです。詳細については、「LEADTOOLS .NET OCRによるIOcrDocumentManager.CreateDocumentとプログラミング」を参照してください。
このサンプルは複数ページをRasterImageオブジェクトへロードして、そしてOCRエンジンに追加します。
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.Forms.Ocr Imports Leadtools.Forms.DocumentWriters Imports Leadtools.Forms Imports Leadtools.ImageProcessing.Core <TestMethod> Public Sub AddMultiPageRasterImageExample() Dim pdfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.pdf") ' Load the Ocr1.tif, Ocr2.tif, Ocr3.tif and Ocr4.tif to a single RasterImage object Dim codecs As New RasterCodecs() Dim image As RasterImage = Nothing For i As Integer = 0 To 3 Dim pageFileName As String = Path.Combine(LEAD_VARS.ImagesDir, String.Format("Ocr{0}.tif", i + 1)) Dim tempImage As RasterImage = codecs.Load(pageFileName) If image Is Nothing Then image = tempImage Else image.AddPage(tempImage) End If Next Console.WriteLine("RasterImage has {0} pages", image.PageCount) ' 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() ' Add the 2nd and 3rd pages to the document Console.WriteLine("Adding the pages from 2 to 3 to the document") ocrDocument.Pages.AddPages(image, 2, 3, Nothing) Console.WriteLine("Document has {0} pages", ocrDocument.Pages.Count) ' We do not need the image anymore image.Dispose() ' Recognize ocrDocument.Pages.Recognize(Nothing) ' Save ocrDocument.Save(pdfFileName, DocumentFormat.Pdf, Nothing) 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 AddMultiPageRasterImageExample() { string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.pdf"); // Load the Ocr1.tif, Ocr2.tif, Ocr3.tif and Ocr4.tif to a single RasterImage object RasterCodecs codecs = new RasterCodecs(); RasterImage image = null; for (int i = 0; i < 4; i++) { string pageFileName = Path.Combine(LEAD_VARS.ImagesDir, string.Format("Ocr{0}.tif", i + 1)); RasterImage tempImage = codecs.Load(pageFileName); if (image == null) image = tempImage; else image.AddPage(tempImage); } Console.WriteLine("RasterImage has {0} pages", image.PageCount); // 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()) { // Add the 2nd and 3rd pages to the document Console.WriteLine("Adding the pages from 2 to 3 to the document"); ocrDocument.Pages.AddPages(image, 2, 3, null); Console.WriteLine("Document has {0} pages", ocrDocument.Pages.Count); // We do not need the image anymore image.Dispose(); // Recognize ocrDocument.Pages.Recognize(null); // Save ocrDocument.Save(pdfFileName, DocumentFormat.Pdf, null); } // 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"; }