Blog

Process Orchestration

KTA : How to make DB locator to be dynamic

Challenge:

We might get the requirement to extract the multiple similar kinds of data using the DB locator in the semi/unstructured document. Best example is address extraction from an invoice. Invoice contains multiple addresses like vendor address, Ship to or Bill To. 

We may need to extract one or more addresses from the extraction. For our example, let’s assume that we need to collect Ship To and Bill To address.

Solution:

The below procedure will help to achieve this,

  1. First, create anchor locators for each address using the format LocatorThis should extract the keywords like (Bill to, Ship to or deliver to) around the address.
  2. Next, Create the script locator which will set the regions for the DB locator based on the anchor locator results.
  • Add the reference Kofax Cascade Database Locator 4.0 to the script.
  • In the script locator, Get the left and top position of the anchor locator.
    Dim iLeft, iTop, iHeight, iWidth as integer
    Dim oBillToAlt as CscXdocFieldAlternative
    Set oBillToAlt = pXDoc.Locators.ItemByName("FL_BillToAnchor").Alternatives(0)
    iLeft = oBillToAlt.Left
    iTop = oBillToAlt.Top
  • Then, set the height and width for the address region. For this example, we can just simply set static values.
    iHeight= 200
    iWidth = 400

But, All these coordinates can be calculated exactly to focus only address. That’s not included here. We will post in another post.

  • Now, we got all the value, Just need to set the DB Locator Regions.Before that, need to convert these pixel coordinates to the millimetre.
Dim oImage As CscImage
Dim dXRes, dYRes As Double
Set oImage = pXDoc.CDoc.Pages(0).GetImage
dXRes = oImage.XResolution
dYRes = oImage.YResolution
Public Function PixelsToMm(dPixels As Double, dResolution As Double) As Double
PixelsToMm = dPixels * 25.4 / dResolution
End Function
Now, set the regions
Dim oRegionsBillTo,oRegionsShipTo As CscLocatorRegions
Set oRegionsBillTo = Project.ClassByName("YourClassName").Locators.ItemByName("DB_BillTo").LocatorRegions
oRegionsBillTo.Clear
oRegionsBillTo.SetBackgroundAccessibility(CscLocRegionBackgroundDeny)
oRegionsBillTo.AddRegion("Region", PixelsToMm(liLeft,dXRes) , PixelsToMm(liTop, dYRes), PixelsToMm(liwidth, dXRes), PixelsToMm(liheight, dYRes), 0, 1)

3. Finally, Create the DB Locator DB_BillTo.

Note: We need to create the locators in the above specified order so that DB locator will get the dynamic region.

Leave a Reply

Your email address will not be published.