Click or drag to resize

Sample Client

The primary entry point to the API module is the Processor class. This class is used to run the TessPro processing engine agains a project file that can contain multiple processing job. These jobs can be defined to watch for incomoing files and process them based how the job is configured. The Processor can also load a plugin DLL that you have deveoped to control the processing workflow. The sample code below illustrates a console application which runs the processing engine and prints some output to the console.

C#
/*-------------------------------------------------------------------
A simple Windows console application that loads a project file and
runs it through a processing loop where watched folders are scanned
and qualified source files are converted to searchable PDF documents. 
A custom plugin is also used to receive callback notifications.
--------------------------------------------------------------------*/
using System;
using Opait.TessPro.Api;

namespace OcrProConsole
{
    /// <summary>
    /// A simple console application that uses TessPro API.
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Syntax: TessConsole <project_file>");
                return;
            }
            try
            {
                // Load a project that is stored in an XML file. A project consists 
                // of one or more Jobs. Each job can watch a folder for certain files 
                // and process them after they have been downloaded.
                var project = new Project(args[0]);

                // Create an instance of the processing engine to process the 
                // project that we loaded. Also pass an instance of our custom
                // plugin class. The processor will call back the methods of
                // the plugin as it processes files in the watched folders.
                var processor = new Processor(project, new MyPlugin());

                // Start the processing loop and wait for its completion. The
                // processing engine will create multiple parallel tasks to
                // improve the performance of the Tesseract engine. The number
                // of these parallel tasks can be controlled by an optional
                // parameter to the ProcessAsync() module. By default, the
                // engine will create parallel tasks based on the number of
                // processor cores in the computer.
                processor.ProcessAsync().Wait();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex}");
            }
        }
    }
}

Please note that this sample only shows one way to process files. The Processor class has simplified static interfaces for processing a single file as well as a single job. There are also more flexible methods to allow progress reporting and cancellation of a long-running process.