Extracting tabular data is a typical use case for importing "digitally born" PDF documents such as invoices. Upon reading an invoice, the recognized data will be matched with the corresponding purchase order data in an ERP system.
Import PDF Documents
Like any other supported file type, TX Text Control can import digitally born Adobe PDF documents. Typically, you can use this approach to search PDF documents for strings in document pages and extract the contents of form fields.
This article shows different ways to extract data from existing PDF documents.
Unlike in the above article, the document is actually loaded into the TX Text Control to loop through recognized tables. Consider the following invoice PDF document.
In this case, the TX Text Control will recognize the table that is highlighted in red.
Looping through Tables
We use the PDFImport
╰ TXTextControl Namespace
╰ TXTextControl Enumerations Enumerations
╰ PDFImportSettings Enumeration Enumeration
Specifies how the document structure is generated when a PDF document is imported. to specify that the TX Text Control should import the content and format it in such a way that tables are recognized as well. The following code loads the PDF document and loops through all of the tables it finds.
The Table2Data method loops through all rows and creates a Dictionary for each row. If the containsTableHeader parameter is set to true, the column name is used from the first row. When finished, the list of dictionaries is returned as a JSON string.
For the example document above, the following JSON is returned.
If the containsTableHeader parameter is set to false, the following JSON will be returned.