←Select platform

SetOcrEngineInstance Method

Summary

Sets the engine instance to use when converting documents using OCR.

Syntax
C#
C++/CLI
Java
Python
public void SetOcrEngineInstance( 
   IOcrEngine instance, 
   bool autoDispose 
) 
public:  
   void SetOcrEngineInstance( 
      IOcrEngine^ instance, 
      bool autoDispose 
   ) 
public void setOcrEngineInstance(OcrEngine instance, boolean autoDispose) 
def SetOcrEngineInstance(self,instance,autoDispose): 

Parameters

instance

The OCR engine instance to use when converting documents. If this is not null, then the engine must be initialized and started.

autoDispose

true to transfer ownership of instance to this document converter and automatically dispose it when the DocumentConverter is disposed; otherwise, false to not transfer ownership and not dispose instance when this DocumentConverter is disposed.

Remarks

The IOcrEngine instance passed to this method will be used when the DocumentConverter uses OCR for the conversion. This DocumentConverter does not create its own IOcrEngine and will throw an error if the user instruct it to use OCR without a previously set instance.

OcrEngineInstance will return the same value passed for instance.

The previously set IOcrEngine is removed and optionally disposed if it was set with autoDispose value of true. If instance is null, the previously set instance is removed and this DocumentConverter will not have an IOcrEngine instance.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Document.Writer; 
using Leadtools.Svg; 
using LeadtoolsExamples.Common; 
using Leadtools.Document; 
using Leadtools.Caching; 
using Leadtools.Annotations.Engine; 
using Leadtools.Ocr; 
using Leadtools.Document.Converter; 
using Leadtools.Annotations.Rendering; 
 
public void DocumentConverterOptionsExample() 
{ 
   using (DocumentConverter documentConverter = new DocumentConverter()) 
   { 
      //use options to force ocr conversion (disable SVG) 
      documentConverter.Options.EnableSvgConversion = false; 
      //abort job at first error (in any page) 
      documentConverter.Options.JobErrorMode = DocumentConverterJobErrorMode.Abort; 
 
      var ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD); 
      var rasterCodecs = new RasterCodecs(); 
      var documentWriter = new DocumentWriter(); 
      ocrEngine.Startup(rasterCodecs, documentWriter, null, LEAD_VARS.OcrLEADRuntimeDir); 
      documentConverter.SetOcrEngineInstance(ocrEngine, true); 
      documentConverter.Diagnostics.EnableTrace = true; 
 
      var inFile = Path.Combine(ImagesPath.Path, @"Leadtools.docx"); 
      var outFile = Path.Combine(ImagesPath.Path, @"output.pdf"); 
      var format = DocumentFormat.Pdf; 
      var jobData = DocumentConverterJobs.CreateJobData(inFile, outFile, format); 
      jobData.JobName = "conversion job"; 
 
      var job = documentConverter.Jobs.CreateJob(jobData); 
      documentConverter.Jobs.RunJob(job); 
 
      if (job.Status == DocumentConverterJobStatus.Success) 
      { 
         Console.WriteLine("Success"); 
      } 
      else 
      { 
         Console.WriteLine("{0} Errors", job.Status); 
         foreach (var error in job.Errors) 
         { 
            Console.WriteLine("  {0} at {1}: {2}", error.Operation, error.InputDocumentPageNumber, error.Error.Message); 
         } 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS23\Bin\Common\OcrLEADRuntime"; 
} 
 
import static org.junit.Assert.assertTrue; 
 
import java.io.File; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.net.URI; 
import java.util.concurrent.Executors; 
import java.util.logging.ConsoleHandler; 
import java.util.logging.Handler; 
import java.util.logging.Level; 
import java.util.logging.Logger; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
 
import leadtools.*; 
import leadtools.annotations.rendering.AnnJavaRenderingEngine; 
import leadtools.caching.FileCache; 
import leadtools.codecs.*; 
import leadtools.document.DocumentFactory; 
import leadtools.document.DownloadDocumentOptions; 
import leadtools.document.LEADDocument; 
import leadtools.document.LoadDocumentOptions; 
import leadtools.document.LoadFromCacheOptions; 
import leadtools.document.UploadDocumentOptions; 
import leadtools.document.converter.DocumentConverter; 
import leadtools.document.converter.DocumentConverterEmptyPageMode; 
import leadtools.document.converter.DocumentConverterJob; 
import leadtools.document.converter.DocumentConverterJobData; 
import leadtools.document.converter.DocumentConverterJobError; 
import leadtools.document.converter.DocumentConverterJobErrorMode; 
import leadtools.document.converter.DocumentConverterJobStatus; 
import leadtools.document.converter.DocumentConverterJobs; 
import leadtools.document.writer.DocumentFormat; 
import leadtools.document.writer.DocumentWriter; 
import leadtools.ocr.OcrEngine; 
import leadtools.ocr.OcrEngineManager; 
import leadtools.ocr.OcrEngineType; 
 
 
public void documentConverterOptionsExample() { 
   DocumentConverter documentConverter = new DocumentConverter(); 
   documentConverter.getOptions().setEnableSvgConversion(false); 
   documentConverter.getOptions().setJobErrorMode(DocumentConverterJobErrorMode.ABORT); 
 
   OcrEngine ocrEngine = OcrEngineManager.createEngine(OcrEngineType.LEAD); 
   RasterCodecs codecs = new RasterCodecs(); 
   DocumentWriter documentWriter = new DocumentWriter(); 
   ocrEngine.startup(codecs, documentWriter, null, "C:\\LEADTOOLS23\\Bin\\Common\\OcrLEADRuntime"); 
   documentConverter.setOcrEngineInstance(ocrEngine, true); 
   documentConverter.getDiagnostics().setEnableTrace(true); 
 
   String LEAD_VARS_ImagesDir = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String inFile = combine(LEAD_VARS_ImagesDir, "Leadtools.pdf"); 
   String outFile = combine(LEAD_VARS_ImagesDir, "output.tif"); 
   RasterImageFormat format = RasterImageFormat.TIF; 
   DocumentConverterJobData jobData = DocumentConverterJobs.createJobData(inFile, outFile, format); 
   jobData.setJobName("Conversion Job"); 
 
   DocumentConverterJob job = documentConverter.getJobs().createJob(jobData); 
   documentConverter.getJobs().runJob(job); 
   assertTrue(job.getStatus() == DocumentConverterJobStatus.SUCCESS); 
   if (job.getStatus() == DocumentConverterJobStatus.SUCCESS) { 
      System.out.println("Success!"); 
   } else { 
      for (DocumentConverterJobError error : job.getErrors()) { 
         System.out.println(error.getError().toString()); 
      } 
   } 
} 
Requirements

Target Platforms

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

Leadtools.Document.Converter Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.