Softbridge Examples
REM ========================================================================
REM
REM Recognition Script: BoxRemoval100
REM
REM Recognition scripts can be utilized to augment or replace the default
REM recognition capabilities provided by Ascent Capture. These scripts provide
REM function calls before and after Kofax recognition. Each of these
REM functions can examine and/or modify the recognition results.
REM
REM ------------------------------------------------------------------------
Option Explicit
REM ========================================================================
REM Kofax script return codes. Do not modify or pass back a different value.
REM ------------------------------------------------------------------------
' Indicates fatal error. Batch is set to error state.
const FatalError = -1
' Indicates successful operation. When returned by the KfxPreRecognition
' function, the application continues to perform Kofax recognition
' (if enabled) and then call the KfxPostRecognition function. When returned
' by the KfxPostRecognition function, processing continues with the next
' recognition area.
const NoError = 0
' When returned from the KfxPreRecognition function, the application saves
' the recognition information and skips the Kofax recognition. The
' KfxPostRecognition function is still called in this case.
const SaveAndSkipOperation = 100
REM ========================================================================
REM Function handling initialization for this module.
REM This function is called the first time the script is referenced in a
REM batch. The script stays loaded until the batch is complete.
REM ------------------------------------------------------------------------
Function KfxLoad( ) As Integer
On Error GoTo Failure
' Insert initialization code here
KfxLoad= NoError
Exit Function
Failure:
KfxLoad= FatalError
Exit Function
End Function
REM ========================================================================
REM Function handling termination of this module.
REM This function is called upon end of processing for the batch. The
REM function is called once per batch and is the last function to be
REM called in this module.
REM ------------------------------------------------------------------------
Function KfxUnload ( ) As Integer
On Error GoTo Failure
' Insert cleanup code here
KfxUnload = NoError
Exit Function
Failure:
KfxUnload = FatalError
Exit Function
End Function
REM ========================================================================
REM Module variables specific to PreRecognition and PostRecognition functions
REM
REM NOTE:
REM These variables are not valid within routines above this point
REM in the module.
REM ------------------------------------------------------------------------
' The TIFF image file representing the zone snippet to be recognized.
' This parameter is read-only. This is a temporary file which is only valid
' while processing this zone. The image contains the zone being processed only
' (not the whole page). Any image processing for the recognition type has already
' been performed. The user should NOT update this image file. Doing so is not
' supported and may have unpredictable consequences.
' Note: This variable is commented for performance reasons. Generating
' the zone tiff file accounts for about 10% of zone execution time. In most
' cases, the zone image does not need to be generated for built-in engine
' execution. Uncommenting and using this variable forces the zone image
' to be created every time. Therefore, do not uncomment this variable
' unless you actually need access to the image.
Dim KfxImageFile as String
' The current recognized value. This value will be null in the PreRecognition
' function. It may be changed in PreRecognition, but will be overwritten
' by the Kofax recognition engine (if any) unless the KfxPreRecognition returns
' SaveAndSkipOperation. The KfxPostRecognition function receives the value
' generated by the KfxPreRecognition function, or the value that has been
' overwritten by the Kofax recognition (if Kofax recognition is enabled).
Dim KfxValue as String
' The confidence as a number between 0 and 100 with 100 being most
' confident. If KfxValue is changed, then the confidence must be set
' to some value as well representing the engine's confidence level
' of the value.
' If the engine has no metric like this, then always set this value to 100.
Dim KfxConfidence as Long
' The search text is the expected search string set in the Administration module
' for a separation, form identification, or registration zone.
' Additionally, if the field type for an index zone has exactly
' one suggested value, and is marked as Force Match, then the search
' text exposes that value. Changes to the KfxSearchText variable are ignored.
Dim KfxSearchText as String
' The following two variables can be used to retrieve and/or modify the registration
' offsets returned by the default engine. These variables define the offset of the lower-left
' pixel for the first character in the search text found in the zone. The offsets are defined
' from the upper-left of the zone and are in 1/1200'ths of an inch (BMU's).
' Registration offsets are only produced by the Kofax OCR and Kofax High Performance OCR/ICR engines.
' If you want to design a custom profile that produces registration offsets, then you must
' derive your custom profile from the profile of one of those engines (if desired, you can skip the default
' engine logic by using the SaveAndSkipOperation return result from the KfxPreRecognition function).
' Registration offsets may be generated with any type of coordinates
' but the values are ignored unless the zone is a registration zone.
' If you are customizing a registration zone and wanting to guarantee success, the script must return
' with the KfxValue set to KfxSearchText, KfxConfidence set to 100, and the two
' offset variables set to a value >= 0.
' Note: These values default to -1 if the default engine has not yet been run, or does not generate
' offsets
Dim KfxRegistrationHorizBMU as Long
Dim KfxRegistrationVertBMU as Long
REM ========================================================================
REM Function handling recognition prior to Kofax recognition
REM
REM NOTE:
REM We recommend returning SaveAndSkipOperation if you actually perform
REM your recognition at this stage. This will cause Kofax recognition to
REM be skipped. The KfxPostRecognition function is still called.
REM ------------------------------------------------------------------------
Function KfxPreRecognition As Integer
On Error GoTo Failure
' Insert user recognition engine here if you want it to be executed
' before the Kofax recognition engine.
KfxPreRecognition = NoError
Exit Function
Failure:
KfxPreRecognition = FatalError
Exit Function
End Function
REM ========================================================================
REM Function handling recognition after Kofax recognition
REM ------------------------------------------------------------------------
Function KfxPostRecognition As Integer
On Error GoTo Failure
' Insert user recognition engine here if you want it to be executed
' after the Kofax recognition engine.
FileCopy KfxImageFile, Left$(KfxImageFile, Len(KfxImageFile) - 4) & ".cpy"
Kill Left$(KfxImageFile, Len(KfxImageFile) - 4) & ".cpy"
KfxPostRecognition = NoError
Exit Function
Failure:
KfxPostRecognition = FatalError
Exit Function
End Function
Sub Split(expression As String, delimiter As String, results() As String)
Dim lMatchedPosition As Long
Dim lStartPosition As Long
Dim lExtractLength As Long
Dim lNewUpperBound As Long
lStartPosition = 1
ReDim results(0)
Do
lMatchedPosition = Instr(lStartPosition, expression, delimiter)
If (lMatchedPosition > 0) And (lMatchedPosition <= Len(expression)) Then
lExtractLength = lMatchedPosition - lStartPosition
results(UBound(results)) = Mid(expression, lStartPosition, lExtractLength)
lNewUpperBound = UBound(results) + 1
ReDim Preserve results(lNewUpperBound)
lStartPosition = lMatchedPosition + Len(delimiter)
End if
Loop While lMatchedPosition >0
results(UBound(results)) = Mid(expression, lStartPosition)
End Sub
Sub Main()
Dim results() As String
Split "Sid|Richard|Scott|Ben", "|", results
Split "Csi;Maturity;12345678;12345678", ";", results
End Sub
REM ========================================================================
REM Remove the specified sub-string from the input string (if it exists),
REM insert the replacement string, and return the result.
REM ------------------------------------------------------------------------
Function Replace(ExpressionString As String, FindString As String, ReplaceString As String) As String
Dim strOutputString As String
Dim iCount As Integer
Dim lMatch As Long
strOutputString = ExpressionString
Do
lMatch = InStr(1, strOutputString, FindString)
If lMatch > 0 Then
strOutputString = Left(strOutputString, lMatch - 1) & ReplaceString & Mid(strOutputString, lMatch + Len(FindString))
End If
Loop While lMatch > 0
Replace = strOutputString
End Function
REM ========================================================================
REM
REM Recognition Script: DataMatrix
REM
REM Recognition scripts can be utilized to augment or replace the default
REM recognition capabilities provided by Ascent Capture. These scripts provide
REM function calls before and after Kofax recognition. Each of these
REM functions can examine and/or modify the recognition results.
REM
REM ------------------------------------------------------------------------
Option Explicit
REM ========================================================================
REM Kofax script return codes. Do not modify or pass back a different value.
REM ------------------------------------------------------------------------
' Indicates fatal error. Batch is set to error state.
const FatalError = -1
' Indicates successful operation. When returned by the KfxPreRecognition
' function, the application continues to perform Kofax recognition
' (if enabled) and then call the KfxPostRecognition function. When returned
' by the KfxPostRecognition function, processing continues with the next
' recognition area.
const NoError = 0
' When returned from the KfxPreRecognition function, the application saves
' the recognition information and skips the Kofax recognition. The
' KfxPostRecognition function is still called in this case.
const SaveAndSkipOperation = 100
REM ========================================================================
REM Function handling initialization for this module.
REM This function is called the first time the script is referenced in a
REM batch. The script stays loaded until the batch is complete.
REM ------------------------------------------------------------------------
Function KfxLoad( ) As Integer
On Error GoTo Failure
' Insert initialization code here
KfxLoad= NoError
Exit Function
Failure:
KfxLoad= FatalError
Exit Function
End Function
REM ========================================================================
REM Function handling termination of this module.
REM This function is called upon end of processing for the batch. The
REM function is called once per batch and is the last function to be
REM called in this module.
REM ------------------------------------------------------------------------
Function KfxUnload ( ) As Integer
On Error GoTo Failure
' Insert cleanup code here
KfxUnload = NoError
Exit Function
Failure:
KfxUnload = FatalError
Exit Function
End Function
REM ========================================================================
REM Module variables specific to PreRecognition and PostRecognition functions
REM
REM NOTE:
REM These variables are not valid within routines above this point
REM in the module.
REM ------------------------------------------------------------------------
' The TIFF image file representing the zone snippet to be recognized.
' This parameter is read-only. This is a temporary file which is only valid
' while processing this zone. The image contains the zone being processed only
' (not the whole page). Any image processing for the recognition type has already
' been performed. The user should NOT update this image file. Doing so is not
' supported and may have unpredictable consequences.
' Note: This variable is commented for performance reasons. Generating
' the zone tiff file accounts for about 10% of zone execution time. In most
' cases, the zone image does not need to be generated for built-in engine
' execution. Uncommenting and using this variable forces the zone image
' to be created every time. Therefore, do not uncomment this variable
' unless you actually need access to the image.
'Dim KfxImageFile as String
' The current recognized value. This value will be null in the PreRecognition
' function. It may be changed in PreRecognition, but will be overwritten
' by the Kofax recognition engine (if any) unless the KfxPreRecognition returns
' SaveAndSkipOperation. The KfxPostRecognition function receives the value
' generated by the KfxPreRecognition function, or the value that has been
' overwritten by the Kofax recognition (if Kofax recognition is enabled).
Dim KfxValue as String
' The confidence as a number between 0 and 100 with 100 being most
' confident. If KfxValue is changed, then the confidence must be set
' to some value as well representing the engine's confidence level
' of the value.
' If the engine has no metric like this, then always set this value to 100.
Dim KfxConfidence as Long
' The search text is the expected search string set in the Administration module
' for a separation, form identification, or registration zone.
' Additionally, if the field type for an index zone has exactly
' one suggested value, and is marked as Force Match, then the search
' text exposes that value. Changes to the KfxSearchText variable are ignored.
Dim KfxSearchText as String
' The following two variables can be used to retrieve and/or modify the registration
' offsets returned by the default engine. These variables define the offset of the lower-left
' pixel for the first character in the search text found in the zone. The offsets are defined
' from the upper-left of the zone and are in 1/1200'ths of an inch (BMU's).
' Registration offsets are only produced by the Kofax OCR and Kofax High Performance OCR/ICR engines.
' If you want to design a custom profile that produces registration offsets, then you must
' derive your custom profile from the profile of one of those engines (if desired, you can skip the default
' engine logic by using the SaveAndSkipOperation return result from the KfxPreRecognition function).
' Registration offsets may be generated with any type of coordinates
' but the values are ignored unless the zone is a registration zone.
' If you are customizing a registration zone and wanting to guarantee success, the script must return
' with the KfxValue set to KfxSearchText, KfxConfidence set to 100, and the two
' offset variables set to a value >= 0.
' Note: These values default to -1 if the default engine has not yet been run, or does not generate
' offsets
Dim KfxRegistrationHorizBMU as Long
Dim KfxRegistrationVertBMU as Long
REM ========================================================================
REM Function handling recognition prior to Kofax recognition
REM
REM NOTE:
REM We recommend returning SaveAndSkipOperation if you actually perform
REM your recognition at this stage. This will cause Kofax recognition to
REM be skipped. The KfxPostRecognition function is still called.
REM ------------------------------------------------------------------------
Function KfxPreRecognition As Integer
On Error GoTo Failure
' Insert user recognition engine here if you want it to be executed
' before the Kofax recognition engine.
KfxPreRecognition = NoError
Exit Function
Failure:
KfxPreRecognition = FatalError
Exit Function
End Function
REM ========================================================================
REM Function handling recognition after Kofax recognition
REM ------------------------------------------------------------------------
Function KfxPostRecognition As Integer
On Error GoTo Failure
Dim hFile As Integer
hFile = FreeFile
Open "C:\ProgramData\Scansation\Recognise.log" For Append Access Write Lock Read Write As #hFile
Print #hFile, KfxValue
Close #hFile
KfxPostRecognition = NoError
Exit Function
Failure:
KfxPostRecognition = FatalError
Exit Function
End Function