- Introducing ABBYY FlexiCapture
- ABBYY FlexiCapture architecture
-
Using scripts in ABBYY FlexiCapture
- Specifics of scripts written in .Net languages
- External assemblies
- Script editor
- Object model
-
Scripts for customizing processing stages
-
Types of scripts
- Script rule
- Autocorrection script
- Export script
- User script (custom action)
- Document assembly script
- Custom recognition script
- Stage rule
- Processing scripts
- Data set update script
- Data set validation scripts
- Document classification script
-
Event handlers
- Batch created
- Batch deleted
- Batch parameter change
- Batch structure change (page added/page deleted/document added/document deleted)
- Pages moved
- Batch opened/closed
- Batch integrity check
- Document parameter changed
- Document state changed
- Export completed
- Script that is run after rule checks
- Before matching
- Field verification request
-
Objects
- IActionResult
- IAssemblingError
- IAssemblingErrors
- IBatch
- IBatchCheckResults
- IBatchItem
- IBatchItems
- IBatchTypeClassifier
- IBatchTypeClassifierResult
- IBinarizationParams
- IBoxedBoolean
- ICharacterParams
- ICharactersParams
- ICheckmarkGroupValue
- ICheckmarkValue
- IDataSet
- IDataSetQuery
- IDataSetRecord
- IDocument
- IDocuments
- IDocumentExportResults
- IDocumentsExportResults
- IDocumentDefinitionInfo
- IDocumentDefinitionInfoArray
- IEditablePictureObject
- IExportFieldsToRedact
- IExportImageSavingOptions
- IField
- IFieldRegion
- IFieldRegions
- IFields
- IFlexiCaptureTools
- ILocalContrastParams
- IMatchedSectionInfo
- IMatchingInfo
- IPage
- IPageClassificationResult
- IPages
- IPictureObject
- IPictureObjectsInfo
- IPrincipal
- IPrincipals
- IProcessingCallback
- IProject
- IProperties
- IProperty
- IPropertyModificationInfo
- IRecordCheckResult
- IRecordset
- IRect
- IRects
- IRoutingRuleResult
- IRuleContext
- IRuleError
- IRuleErrors
- IRuleTag
- IRuleTags
- IScriptBinaryAttributes
- IScriptDefinitionContext
- ISectionDefinitionInfo
- ISectionDefinitionInfoArray
- IShadowsHighlightsParams
- IStageInfo
- IUserAttachment
- IUserAttachments
- IUserSessionInfo
- IValue
- IVARIANTArray
- TAssemlingErrorType
- TBatchItemType
- TColorToFilter
- TExportFieldType
- TExportType
- TImageCompressionType
- TPageClassificationType
- TPdfAVersion
- TPdfDocumentInfoType
- TPdfTextSearchAreaType
- TPrincipalType
- TProcessingPriority
- TPropertyType
- TRuleErrorType
- TStateType
- Sample scripts
- Internal names of recognition languages
-
Types of scripts
-
Scripts for processing interface events
-
Event handlers
- On Document Closed
- On Project Closed
- On Activate Document
- On Field Control Activate
- On Return From Task
- On User Command
- On Field Control Deactivate
- On Closing Document
- On Task Close
- On Closing Project
- On Region Change
- On Task Window Mode Changed
- On Open Document
- On Task Window Create
- On Task Reject
- On Region Control Draw
- On Task Send To Stage
- On Text Field Validating
-
Objects
- IBoolean
- IBoxedFieldControl
- IDocumentEditor
- IDocumentItem
- IDocumentItems
- IDocumentsCollection
- IDocumentsWindow
- IDrawContext
- IErrorControl
- IErrorControls
- IErrorsWindow
- IFieldControl
- IFieldRegionControl
- IFieldRegionControls
- IFormWindow
- IImageWindow
- IMainMenu
- IMainWindow
- IMenu
- IMenuItem
- IPageControl
- IPageItem
- IPageItems
- IPagesCollection
- IPoint
- ISelection
- IShellRational
- IShellRect
- IShellRects
- ITaskWindow
- ITextEditor
- IToolbar
- IToolbarButton
- IToolbars
- TCommandBarType
- TCommandID
- TDockingType
- TDocumentState
- TErrorType
- TSelectionType
- TTaskWindowMode
- TTextSize
- TUserRole
- TWorkWindowType
-
Event handlers
- User script for Web Verification Station
-
Application Programming Interface (API)
- About the ABBYY FlexiCapture Application Server Web Services API
- Using the Web Services API of the ABBYY FlexiCapture Application Server
-
References
- API Methods
- Data types
- Working with files
- Web Services Mobile API
- Web Services for user account management
- Examples of API Use
- Integrating Web Stations into third-party systems
- Configuring additional settings and customizing Web Stations
- Custom reports
-
Appendix
- Supported recognition languages
- Fonts for correct characters rendering
- Supported text types
- Supported barcode types
- Supported input formats
- Export file formats
- Date formats
- Alphabet used in regular expressions
- Protecting Document Definitions and additional modules
- Glossary
- Patents
- Third-party technologies
- Technical support
- End-User License Agreement (EULA)
Sample scripts for creating custom rules
Automation rule
This example demonstrates a table data check. The rule checks whether the table data matches the value in the resulting field. The table has columns with prices and quantities of certain goods. The rule has been written at the level of a section containing the table and the resulting field.
[VBScript] dim autoRule set autoRule = CreateObject( "AutomationRule.CheckDoc" ) autoRule.CheckResult me.FIELD("cost"), me.FIELD("number"), me.FIELD("Result"), me [JScript] var autoRule = new ActiveXObject( "AutomationRule.CheckDoc" ); autoRule.CheckResult( Field("cost"), Field("number"), Field("Result"), this );
Code of an ActiveX component
The code provided here is a CheckDoc class code from the AutomationRule project, which is used in the scripts mentioned above.
Option Explicit ' Checks whether table data matches the result ' column1 - price column ' column2 - quantity column ' resultField - resulting field (<Total> or equivalent) ' docObj - document node being checked Public Sub CheckResult(ByRef column1 As Object, ByRef column2 As Object, _ ByRef resultField As Object, ByRef docObj As Object) On Error GoTo err_h Dim costItems AsObject, numItems AsObject Dim curCost AsDouble, curNum AsLong, sum AsDouble Dim result AsDouble Dim i AsLong Set costItems = column1.Items Set numItems = column2.Items ' summing up table data sum = 0 For i = 0 To costItems.Count - 1 curCost = costItems.Item(i).Value curNum = numItems.Item(i).Value sum = sum + curNum * curCost Next ' comparison accuracy result rounded to the 2nd digit after the decimal point result = resultField.Value If (Round(result, 2) = Round(sum, 2)) Then docObj.CheckSucceeded = True Else docObj.CheckSucceeded = False docObj.ErrorMessage = "Table data does not match the resulting value" resultField.Suggest sum End If Exit Sub err_h: docObj.ErrorMessage = Err.Description docObj.CheckSucceeded = False End Sub
Search in the variants list
The rule code provided below checks whether the field value matches one of the values in the list. If not, a rule error flag appears, and the field receives a list of suggested values. Depending on the check result, the field is marked as certainly or uncertainly recognized.
[VBScript] 'remember field value Dim fieldValue fieldValue = me.Field("Field6").Value 'create list of values for check Dim list(5) dim i for i = 0 to 4 list(i) = "2" & i next dim success success = false 'check whether field value matches values in the list for i = 0 to 4 if list(i) = fieldValue Then success = true exit for end if next 'depending on the check result, set a corresponding certainly status for the field me.Field("Field6").IsVerified = success 'fill the list of suggestions for the field a suggestion can be any of the 'suitable values if success = false then for i = 0 to 4 me.Field("Field6").Suggest( list(i) ) next end if 'place an error flag me.CheckSucceeded = success [JScript] // remember field value var fieldValue = Field("Field6").Value; // create list of values for check var list = new Array(5); for( i = 0; i < 5; i++ ) { list[i] = "2" + i } var success = false; // check whether field value matches values in the list for( i = 0; i < 5; i++ ) { if( list[i] == fieldValue ) { success = true; break; } } // depending on the check result, set a corresponding certainly status for the field Field("Field6").IsVerified = success; // fill the list of suggestions for the field a suggestion can be any of the // suitable values if( !success ) { for( i = 0; i < 5; i++ ) { Field("Field6").Suggest( list[i] ); } } // place an error flag CheckSucceeded = success;
Field match check
The rule code provided below checks whether the checked field has matched.
[VBScript] if me.Field("InvoiceNumber").IsMatched then me.CheckSucceeded = true else me.CheckSucceeded = false me.ErrorMessage = "Field InvoiceNumber is not matched" end if [JScript] if( Field("InvoiceNumber ").IsMatched ) { CheckSucceeded = true; } else { CheckSucceeded = false; ErrorMessage = "Field InvoiceNumber is not matched"; }
Checkmark check
The rule code provided below checks whether the checkmark has been selected or not
[VBScript] if me.Field("Page status").Value then me.CheckSucceeded = true else me.CheckSucceeded = false me.ErrorMessage = "Page status is not checked" me.FocusedField = me.Field(Page status) "" end if [JScript] if( Field("Page status").Value ) { CheckSucceeded = true; } else { CheckSucceeded = false; ErrorMessage = "Page status is not checked"; FocusedField = Field("Page status"); }
Checkmark group check
The rule code provided below iterates all the checkmarks in the group and if none are selected, selects the first one. The rule is written for the checkmark group level. All the checkmarks in the group have been added to the list of fields included into the rule. The group itself has been excluded from the list. For the default checkmark (the first one), the ReadOnly flag has been disabled. If there are no checkmarks in the group, a rule error flag is enabled.
This sample code iterates all the fields included in the rule. Since field names are not specified in the code, this code can be used for any checkmark group.
[VBScript] if me.Fields.Count = 0 then me.CheckSucceeded = false me.ErrorMessage = "There are no checkmarks in the group" else dim isChosen, i isChosen = false for i = 0 to me.Fields.Count - 1 if me.Fields.Item( i ).Value then isChosen = true exit for end if next if Not isChosen then me.Fields.Item(0).Value = true end if me.CheckSucceeded = true end if [JScript] if( Fields.Count == 0 ) { CheckSucceeded = false; ErrorMessage = "There are no checkmarks in the group"; } else { var isChosen = false; var i; for( i = 0; i < Fields.Count; i++ ) { if( Fields.Item( i ).Value ) { isChosen = true; break; } } if( !isChosen ) { Fields.Item(0).Value = true; } CheckSucceeded = true; }
Field reliability check
The rule code provided below checks the number of uncertain characters in the field and clears the field if the number of uncertain characters is greater than or equals three. This is an Autocorrection script.
[VBScript] Dim totQty, suspQty Dim i totQty = me.Symbols.Count suspQty = 0 for i = 0 to totQty - 1 if me.Symbols.Item(i).IsSuspicious = true then suspQty = suspQty + 1 end if next if suspQty >= 3 then me.Text = "" end if [JScript] var susp, qty, strpos, i, SC, strposPrev strposPrev = 1 qty = 0 SC = "1" susp = SuspiciousSymbols for ( i = 0; i < susp.length; i++) { strpos = susp.indexOf (SC,i) if ((strpos != strposPrev) && (strpos != -1)) { qty = qty + 1 strposPrev = strpos } } if (qty >= 3) { text = "" }
Character replacement without loosing regions and verification flags
The script replaces "+" with "&" without loosing information about regions and verification flags. This is an Autocorrection script.
[VBScript] Dim totQty Dim i totQty = me.Symbols.Count for i = 0 to totQty - 1 if me.Symbols(i).Symbol = "+" then me.Symbols(i).Symbol = "&" end if next
Batch integrity check
Checks if the number of documents specified on the control page coincides with the inventory in the batch and with the number of documents actually processed. If the numbers do not match, an error is returned.
[VBScript] dim DQty dim i for i = 0 to me.Batch.Documents.Count - 1 if me.Batch.Documents.Item(i).DefinitionName = "Inv" then DQty = me.Batch.Documents.Item(i).IndexedItemValue("DocQty") exit for end if next dim AcQty AcQty = me.Batch.Documents.Count if acqty <> DQty then me.CheckSucceeded = false me.ErrorMessage = "Incorrect number of documents in the batch:" & " " & AcQty& ". " & "Expected number:" & " " & DQty & "!" end if [JScript] for ( i = 0; i < [Batch.Documents.Count - 1]; i++ ) { var TemplName = Batch.Documents.Item(0).DefinitionName; if (TemplName = "Inv") { var DQty = Batch.Documents.Item(i).IndexedItemValue("DocQty"); break ; } } var AcQty = Batch.Documents.Count -1 if (AcQty != DQty) { CheckSucceeded = false; ErrorMessage = "Incorrect number of documents in the batch:" + " " + AcQty + "." + "Expected number:" + " " + DQty +"!" ; }
Counting the number of documents and pages in a document set
This script counts the number of pages in a document set section and throws an error if the set contains an element of an unknown type.
int subDocumentsCount = 0; int pagesCount = 0; IBatchItem asBatchItem = Context.Document.AsBatchItem; IBatchItems items = asBatchItem.ChildItems; foreach (IBatchItem item in items) { if ( item.Type == TBatchItemType.BIT_Page ) { pagesCount ++; } else if( item.Type == TBatchItemType.BIT_Document ) { subDocumentsCount ++; } else { Context.CheckSucceeded = false; Context.ErrorMessage = "Unknown type of element in set"; } } Context.Field("Field").Text = subDocumentsCount.ToString() + " " + pagesCount.ToString();
14.01.2021 14:17:18