How to Create a Script for Export Handling

ABBYY FineReader Server 14 allows you to configure export handling with the help of a script. This script can be used to further process output files and process images and XML results from failed jobs.

Important! Export handling scripts are triggered by the Server Manager. Thus, for the script to work properly with shared resources, you should run the Server Manager under a user account which has necessary rights to access these resources.

Handling successfully published jobs

The script can deliver output documents to the appropriate destination depending on the document type and attributes, job properties, and recognition statistics. The script is run for each output document after it is published to the Output folder.

To use script for output files processing, proceed as follows:

  1. In the 6. Output tab of the Workflow Properties dialog box specify necessary output formats and click the Script... button.
  2. In the Script Editor dialog box that opens select the scripting language and enter the script text. The reference "this" or "Me" refers to the PublishedDocument object.
  3. To check the script click the Check button. To save the script click OK.

Handling failed jobs

The script can deliver images that failed to be processed to appropriate destination depending on job properties, input files properties, and the error description. The script is triggered for each failed job.

To use script for images and XML results processing, do the following:

  1. In the 4. Quality Control tab of the Workflow Properties dialog box, set the Exceptions folder and click Script....
  2. In the Script Editor dialog box that opens, select the scripting language and enter the script text. The reference "this" or "Me" refers to the FailedJob object.
  3. To check the script, click the Check button. To save the script, click OK.

Sample

var attributeToUse = "";
if( DocumentType == "Article" ) {
   attributeToUse = "Customer Name";
} else if( DocumentType == "Resume" ) {
   attributeToUse = "Applicant's Name";
} else if( DocumentType == "Brochure" ) {
   attributeToUse = "Product Name";
}
if( attributeToUse == "" ) {
   return;
}
var attributeValue = retrieveAttributeValue( attributeToUse );
if( attributeValue == "" ) {
   return;
}
var fso = new ActiveXObject("Scripting.FileSystemObject");
for( i = 0; i < OutputFormats.Count; i++ ) {
   var format = OutputFormats.Item( i );
   var folderPath = format.OutputLocation;
   folderPath = fso.BuildPath( folderPath, JobProperties.Subfolder );
   var outputFiles = format.OutputFiles;
   for( j = 0; j < outputFiles.Count; j++ ) {
      var initialName = outputFiles.Item( j );
      var slashPosition = initialName.lastIndexOf( "\\" );
      LogMessage( "slash position: " + slashPosition );
      if( slashPosition != -1 ) {
         var subPath = initialName.substring( 0, slashPosition );
         LogMessage( "subPath: " + subPath );
      }
      var initialExt = fso.GetExtensionName( initialName );
      var sourcePath = fso.BuildPath( folderPath, initialName );
      var sourceFolder = fso.GetParentFolderName( sourcePath );
      var destPath = fso.BuildPath( sourceFolder, attributeValue + "." + initialExt );
      if( fso.FileExists( destPath ) ) {
          fso.DeleteFile( destPath );
      }
      fso.MoveFile( sourcePath, destPath );
   }
}
function retrieveAttributeValue( name )
{
   for( i = 0; i < Attributes.Count; i++ ) {
      var attribute = Attributes.Item( i );
      if( attribute.Name == name ) {
          return attribute.Value;
      }
   }
}

See also

Using Scripts in ABBYY FineReader Server

29.08.2023 11:55:30

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.