Exporting Kofax Capture Tables

What grinds my gears is the way standard Kofax Capture handles tables. Imagine you’d want to capture a small table with three columns, this is what you’ll get:

capture-table

That’s right, table columns are arranged in simple index fields, the row items separated by semicolons or whatever you define in the advanced batch class properties. In a custom export connector, you have to a) split the items, and b) transpose the table to get what you were initially looking for. The code below may help.

I usually store my tables in lists of lists. Sounds more complicated than it is. Each item in a row is an element within a list. And each row itself also is an element in another list. So, in essence, this how I see Capture tables:

kc-table-2
This code helps transforming the Capture table to a more bearable object:


    List fields = new List();
    List<List> matrix = new List<List>();
         
    // this is the weird KC export format for tables
    fields.Add("Tulips;Blaster;Monitor");
    fields.Add("Orange;Teal;Black");
    fields.Add("25.99;19.99;239.99");

    // the default separator char is ;
    char separator = ';';

    // make list of list
    foreach (var f in fields)
    {
        matrix.Add(f.Split(separator).ToList());
    }

    matrix = Transpose(matrix);

For the transpose function, I used Rawling’s transpose method that also works quite fine with “jagged” lists (i.e. one list having a different count of items than the others):


public static List<List<T>> Transpose<T>(List<List<T>> lists)
{
    var longest = lists.Any() ? lists.Max(l => l.Count) : 0;
    List<List<T>> outer = new List<List<T>>(longest);
    for (int i = 0; i < longest; i++)
        outer.Add(new List<T>(lists.Count));
    for (int j = 0; j < lists.Count; j++)
        for (int i = 0; i < longest; i++)
            outer[i].Add(lists[j].Count > i ? lists[j][i] : default(T));
    return outer;
}

So, we end up with a beautiful representation of the document table. For the screenshot below, I was just for-eaching through every row and cell and output their data to the console. Feel free to reuse the code for your own export connectors.

transposed-table