Skip to main content
Kofax

Revert to Zonal OCR When Locator Produces No Result

17609
3010944

Question / Problem: 

Revert to Zonal OCR When Locator Produces No Result

Answer / Solution: 

Suppose that a field is usually extracted via a locator, but if that locator produces no result then the field should fall back to OCR of a particular zone.

The preferred way to accomplish this is to use a Standard Evaluator configured to use a "First of" evaluation. The original locator would be used as the first locator and the subfield of the Advanced Zone Locator would be the second. If the first produced no alternatives, then the zone would be used.

An alternate way to do this is to run a Script Locator which calls the following function after the other locators. If the field is blank, it will be set to the OCR of the subfield.

' if the field 'fieldname' is not filled, then
'  copy the original OCR values and position from zone 'zonename'
Private Sub CopyResult(pXDoc As CASCADELib.CscXDocument, FieldName As String, LocatorName as String, ZoneName As String)

   Dim ZoneLoc As CscXDocField
   Dim Field As CscXDocField
   Dim Subfield As CscXDocSubField

   Set ZoneLoc = pXDoc.Locators.ItemByName(LocatorName)
   Set Field = pXDoc.Fields.ItemByName(FieldName)
   If Len(Field.Text) = 0 Then
      If ZoneLoc.Alternatives.Count > 0 Then
         If ZoneLoc.Alternatives(0).SubFields.Exists(ZoneName) Then
            Set Subfield = ZoneLoc.Alternatives(0).SubFields.ItemByName(ZoneName)
            Field.InitFromSubField(Subfield)
         End If
      End If
   End If
End Sub

 

Applies to:  

Product Version Category
KTM 6.3 Scripting
KTM 6.2 Scripting

 

  • Was this article helpful?