Quick start

This section illustrates the use of the FineReader Server 14 Web Services API using a Visual Studio project as an example.

Preliminary notes

You must first add a reference for the FineReader Server 14 Web Services API into your project. To do this, complete the following steps:

  1. In Microsoft Visual Studio 2015 or later, right-click the name of your project in Solution Explorer and then click Add > Service Reference.
  2. In the Add Service Reference dialog box, in the Address field, enter the URL of the FineReader Server 14 Web Service. For example: http://localhost:8080/FineReaderServer14/WebService.asmx
    In the Namespace field, type FineReaderServer14.
    Click the Advanced button, clear the Allow generation of asynchronous operations option, and click OK.
  3. Click OK in the Add Service Reference dialog box.

Creating a client

  1. At the start of the file, add an alias for the FineReaderServer14 namespace:

using FRS14 = <YourProjectNamespace>.FineReaderServer14;

  1. Create a client object by calling:

var client = new FRS14.WebServiceSoapClient();

  1. Finally, specify the address of the computer where the FineReader Server 14 Server Manager is installed:

var serverLocation = "localhost";

Selecting a workflow

To get a list of available workflows, use:

string[] workflowNames = client.GetWorkflows(serverLocation);

In the following string, we assume that there is a workflow on the server that is intended for converting documents to PDF:

var workflowName = "ConvertToPdf";

Selecting a file

To submit a file for processing, place its name and contents into the FileContainer object:

var inputFilePath = "C:\\Images\\SampleImage.tiff";
var fileContainer = new FRS14.FileContainer();
fileContainer.FileName = System.IO.Path.GetFileName(inputFilePath);
fileContainer.FileContents = System.IO.File.ReadAllBytes(inputFilePath);

Processing the file

Now you can send the file to the selected workflow and get the ID of the created job:

string jobId = client.StartProcessFile(serverLocation, workflowName, fileContainer);

You can use this ID to periodically call the GetJobStateInfo method until the job is in the JS_Complete state:

while (true)
{
   var state = client.GetJobState(serverLocation, jobId);
   if (state == FRS14.JobStateEnum.JS_Complete)
   {
       // The job is complete
       break;
   }
   else if (state == FRS14.JobStateEnum.JS_NoSuchJob)
   {
       // The job was deleted from the server
       throw new Exception("The job was deleted from the server");
   }
   else
   {
       // The job is still in progress, wait
       System.Threading.Thread.Sleep(500);
   }
}

When the job is in the JS_Complete state, you can receive the processing results:

FRS14.XmlResult result = client.GetJobResult(serverLocation, jobId, null);

Note. TheGetJobResult method deletes a job and its files from the server. If you need to get the results of a single job muliple times, use the GetJobResultEx method with the DoNotDeleteJob flag. For optimum performance, call the DeleteJob method after getting the job results.

If the file is processed successfully, you can save the result to file:

varoutputFilePath="C:\\Images\\SampleImage.pdf";
if(!result.IsFailed)
{
   FRS14.FileContainerresultContainer= result.JobDocuments.First().OutputDocuments.First().Files.First();
   System.IO.File.WriteAllBytes(outputFilePath,resultContainer.FileContents);
}
else
{
   varerror=result.Messages.Where(m=>m.Type==FRS14.JobMessageType.JMT_Error).First();
   thrownewException("Recognition failed with the following error: "+error.UnicodeStr);
}

Additional remarks

FineReader Server 14 Web also allows you to:

  • process multiple files in one job
  • process jobs asynchronously (i.e. send jobs, check their state and percent completed while they are still being processed, and get results when jobs are completed)
  • fine-tune processing parameters and output formats for each individual job (by redefining workflow settings)
  • get information about processing results (you can get lists of errors and warnings, recognition statistics, index field values, and other information)

For details, please refer to the latest documentation and the Samples section.

3/26/2024 1:49:49 PM

Please leave your feedback about this article

Usage of Cookies. In order to optimize the website functionality and improve your online experience ABBYY uses cookies. You agree to the usage of cookies when you continue using this site. Further details can be found in our Privacy Notice.