How to Create a Script for Document Identification and Indexing
You can configure document identification and indexing using a script. A script can be used to detect document type and populate document attributes based on the recognized text, barcodes, etc. The script will be run separately for each document after the document is assembled.
Important! Document identification and indexing scripts are triggered by a Processing Station. Consequently, for a script to work properly with shared resources, you should run Processing Stations under a user account which has the necessary rights to access these resources.
To create and use a script, do the following:
- On the 5. Indexing tab of the Workflow Properties dialog box, specify the document types. Document indexing is only available if at least one document type is specified.
- To add a new document type, click New.... In the Document Type dialog box that opens, specify a document type name and its attributes. Click OK.
- Click the Script... button. In the Script Editor dialog box that opens, select a scripting language and enter the script text. The reference "this" or "Me" refers to the DocumentToIndex object.
Note. To queue the document for processing on the Indexing Station upon completion of the indexing script, set the value of SkipManualIndexing of the DocumentToIndex object to FALSE.
- To check the script for errors, click the Check button. To save the script, click OK.
For details on using scripts, see Using Scripts in ABBYY FineReader Server.
Sample
The sample script provided below is written in JScript and is intended for indexing of documents based on a recognized text. As a document type the program uses a custom text (the CustomText property of the DocumentToIndex object) assigned to a document when running a document separation script. The program searches for key words in the recognized text on the first page depending on the type of the document. If the key words are found, the program sets the value of a document attribute and skips manual indexing (the SkipManualIndexing property).
Note. This script is used in the Scripting Demo demo processing scenario, whose settings are contained in ScriptingDemoWorkflow.xml in the following folder: Samples (Start > Programs> ABBYY FineReader Server 14 > Examples).
if( CustomText ==""){
return;
}
DocumentType = CustomText;
if( DocumentType =="Brochure"){
var firstPageText = Pages.Item(0).Text;
if( firstPageText.search("FineReader Server")!=-1){
setAttribute("ABBYY FineReader Server");
SkipManualIndexing =true;
}elseif( firstPageText.search("FlexiCapture")!=-1){
setAttribute("ABBYY FlexiCapture");
SkipManualIndexing =true;
}
}
function setAttribute( newValue )
{
for( i =0; i < Attributes.Count; i++){
var attribute = Attributes.Item( i );
if( attribute.Name=="Product Name"){
attribute.Value= newValue;
break;
}
}
}
Event handlers
Event handlers can be set up for each document type. To create or enable an event handler, click the button Scripts... in the Document Type dialog box, select an event, and click the Edit Script... button. The following events are available:
- When Document Type Is Changed
Handlers for this event run when the type of a document is changed. This can occur when a default document type is specified in the workflow settings, when another script changes a document's type, or when a document's type is changed on an Indexing Station. Event handlers for the When Document Type Is Changed event can be used to assign pre-determined values to document fields using the IDocumentAttributes object. Note. Event handlers for the When Document Type Is Changed event are executed on the station where the document's type was changed. An example of an event handler script that assigns a pre-determined value to a Single line attribute is provided below. for( i =0; i < Attributes.Count; i++){ |
- When Document Attribute Value Is Changed
Handlers for this event run on an Indexing Station when an operator changes the value of a field and finalizes the change by moving the cursor to another field. They allow changing the values of fields based on the values of other fields using the IDocumentAttributesChanged object. Handlers for the When Document Attribute Value Is Changed event can also be used to change the possible values of List fields using the PossibleValues property of the Attribute object. This property consists of an editable set of strings. An example of a script that adds a value to a List attribute based on the value of other attributes is provided below. if( ChangedAttributeName =="First name"|| ChangedAttributeName =="Last name"){ |
Handlers for this event type run on an Indexing Station when the indexing of a document is stopped for one of the following reasons:
Handlers for the When Document Indexing Is Finished event use the IDocumentAttributesIndexingFinished object. An example of a script that returns the name of an operator who rejected a document is provided below. if(IndexingResult ==1){ |
See also
26.03.2024 13:49:49