Skip to main content

Group and Merge Table Rows

Docparser offers various tools to extract table data from PDF and scanned documents. The easiest way to extract tables is to use our "Table Data" parsing rule preset, or if you are processing invoices our "Line Items" preset. Both presets let you define the column boundaries of your table with a simple point & click interface. But what if your tables have multiple rows or lines per item as in the example below?

Example of table with multiple lines per item in a PDF document

Using the filter for "Group and Merge Rows" will allow you to combine those description lines into the rows above to gather 4 rows of data. To learn how to do this just follow the steps below.

The first step will be to select Add Parsing Rule and select from either the "Line Items" or "Table Data" parsing rules types.

Selecting 'Line Items' or 'Table Data' parsing rule in Docparser

Line Items parsing rule interface in Docparser

 

Then next step is to then identify the column boundaries and the area where the items are located on the page - to do this simply click the red + buttons on the left or right of the screen to add the column guides and drag those to the correct location on your file. You can then choose to use a crop area selection to identify the location on the page where the line items are, or alternatively, you can use filters such as "Keep Table Section" Or "Keep Rows Where" filters to select the area or rows you would like to keep.

Setting column boundaries using red + icons in Docparser

Once you have isolated only the line item rows within your document, add in the table filter for "Group and Merge Rows"Adding 'Group and Merge Rows' filter to table in Docparser

This filter by default will be set to "Automatic Merge", this setting will look for values in the first column of your table, and merge everything until a value is found in Column 1 again. This works for many documents, however if this setting does not work for you, you can change this from Automatic Merge to "Define Rules"
Switching from 'Automatic Merge' to 'Define Rules' in Group and Merge Rows filter

Once selected the filter will open up the options to allow you to define when a group begins and ends. In the example below many options would work to accomplish this for example


A row group begins when column #2 has a value
A row group begins when column #2 is in integer number
A row group begins when column #3 has a value
A row group begins when column #3 is an amount
*and more
Options to define when a row group begins in Docparser

There are a number of options to select from when defining the beginning of a row group - this will be unique to each PDFExample of defining unique group start condition for PDF tables

Once that has been defined your row groups will merge together. You can then select to define where a row group ends using the unique value of the last row you require by selecting When does a row group end? and selecting either "When cell conditions match" or "After [x] rows"
Setting conditions for when a row group ends in Docparser

By default all rows will merge cell values - however, if your use case requires you can select to Append the values of the additional rows to the end using either of the two options in the image below:
Choosing to append values from additional rows to the right in table filter

These options will add additional columns to the right of the table with the values of the additional rows
Output view of additional columns added from merged rows

Once your table appears in the way you need simply select "SAVE PARSING RULE".

Was this article helpful?
0 out of 1 found this helpful

Still stuck?

Send us your parser name and a sample document.

Submit a request