To extract a table from a PDF, software first finds where the table is, then works out its rows and columns from the position of lines and words on the page. A PDF stores no table object, only text and shapes at coordinates, so every detection is an informed guess that can fail.
Ruled tables vs whitespace tables in a PDF
A ruled table has printed lines between its cells, and a whitespace table has none. Ruled tables are easier for software, because the lines mark exactly where each cell begins and ends. Whitespace tables, also called borderless tables, force the software to infer the grid from the gaps between words.
Why a PDF has no table to read
A PDF is a set of drawing instructions: put this word at this spot on the page, draw this line from here to there. The word "Widgets" is not marked as belonging to row 3, column 2. Anything that looks like a table to a human is a pattern of words and lines that software has to recognise. That is why two tools can return different tables from the same file.
How ruled tables are read
For a ruled table, the software collects the horizontal and vertical lines and intersects them. Each rectangle the lines enclose is a cell. It then assigns each word to the cell that contains it. When the lines are complete, this works well, and the result matches the grid you see.
It fails in predictable ways:
- Lines that do not quite meet leave gaps, so two cells merge.
- Only horizontal lines are printed (a common style with a line under each row), so the software sees rows but has to guess the columns.
- Shaded rows with no outline are drawn as filled rectangles, which can look like lines or like nothing.
How whitespace tables are read
Without lines, the software looks at the words. Words that line up vertically across many rows suggest a column. A gap of empty space running down the page suggests a boundary between two columns. Words that share a baseline, the invisible line they sit on, suggest one row.
This works when the columns are clean and the gaps are wide. It stumbles when text is left-aligned in one column and right-aligned in the next, since the gap between two words may be larger inside a column than between two columns.
A side-by-side diagram brief
If you were drawing this for a guide, two panels placed next to each other would show it best. Both panels use the same four-row, three-column table of example data (Item, Qty, Price).
- Left panel, ruled table. Draw the printed grid in black. Over it, draw the detected column boundaries as dashed blue vertical lines that sit exactly on the printed vertical rules. Label it "Boundaries come from the lines."
- Right panel, whitespace table. Draw only the words, with no grid. Over them, draw dashed blue vertical lines in the empty gaps between columns, and shade the gaps pale blue. Label it "Boundaries come from the gaps."
- A caption underneath both. "The same table. The ruled version has one answer, and the whitespace version has an estimate."
Add one detail to the right panel: a long word in the Item column that reaches close to the Qty column, with the boundary pushed to a different place. It shows why a narrow gap is the weak point.
How are table rows found in a PDF?
Software finds table rows by grouping words that sit at about the same height on the page. One row is a set of words sharing a baseline, within a small tolerance. A new row starts when the vertical position moves down by more than that tolerance.
Baselines and tolerance
Each word in a PDF has coordinates. The software sorts words from top to bottom and clusters those whose vertical positions fall within a small range of one another. The range matters. Set it too tight, and a number with a slightly smaller font ends up in its own row. Set it too wide, and two lines of text packed close together merge into one.
What counts as a row in the sheet
A row on the page and a row in the data are not always the same thing. A table printing one record on two lines, say a name on the first line and an address on the second, holds two printed rows for one record. The software sees two rows unless something tells it otherwise.
Three signs usually separate a true new record from a continuation line:
- The new record starts with a value in the first column, such as a date or a reference number.
- A continuation line has an empty first column and indented text.
- A new record often carries a number, while a continuation line holds text only.
These are heuristics, not rules. A converter built around one document type can use stronger signals than a general tool can. For statements, the approach is covered in how a bank statement parser finds the transaction table.
Header rows and total rows
The header row is the first row of the table and holds names, not data. The software usually recognises it by position, by bold text or by a line beneath it. A total row at the bottom looks exactly like a data row with a label in the first column and a number in the last. Whether it belongs in your table is a decision for you. Include it in the extraction, then remove it before you sum the column, or the total will be counted twice.
Column boundaries when PDF table text wraps
Wrapped text creates extra rows because the software sees a second line of words below the first and has no way to know it belongs to the same cell. The second line sits at a new baseline, so it is treated as a new row, usually with most of its cells empty.
What a wrapped cell looks like
Take a description column that prints "Monthly subscription for office" on one line and "software, annual plan" on the next. The numbers in the other columns appear only on the first line. The extraction returns two rows. The first holds the first half of the text and all the numbers. The second holds the rest of the text and nothing else.
This example is made up, but the shape is common:
| Row | Description | Qty | Amount |
|---|---|---|---|
| 1 | Monthly subscription for office | 12 | 480.00 |
| 2 | software, annual plan |
Row 2 has an empty quantity and an empty amount. That pattern, text in one column and blanks everywhere else, is the sign of a wrapped cell.
Repairing wrapped rows
Merge each row that has only a description into the row above it, with a space between the two pieces of text. In Excel, a helper column that flags rows with an empty amount shows you where to look. After you merge, delete the leftover row.
Why wrapping also moves boundaries
Wrapped text changes where the whitespace gaps are. A column that is mostly short entries but has one long wrapped entry can push the detected boundary into the next column's territory. When one page of a table comes out with shifted columns and the others do not, look for a long wrapped cell on that page.
Why does table extraction pick up page numbers?
Extraction picks up page numbers because it reads every word on the page, and a page number is a word that lines up with something. A number centred at the foot of the page, or a short title repeated at the top, can fall in the same column as the table and get treated as a table row.
Where the junk comes from
Headers and footers repeat on every page: page numbers, report titles, dates, confidentiality notes. They sit outside the table, but software that assigns words to the nearest column will place them in one. The result is a row of mostly blank cells with "14" or "Page 14 of 212" in the first column, every time the table crosses a page.
How to spot it
Three symptoms show up in the output:
- A row appears at every page break with one filled cell.
- The same text repeats at regular intervals down a column.
- A numeric column contains a small whole number out of sequence with its neighbours.
A numeric page number in a numeric column is the worst case, since it adds itself to a sum without any error.
How to remove it
Filter the first column for the page-number pattern and delete those rows. If your tool lets you set a table area, drawing the region tightly around the table keeps headers and footers out. Some tools can also ignore text in the top and bottom margins of every page.
For a one-off job, choosing the page range and cleaning by filter is quicker than trying to configure a region. For files that repeat each month, set up a rule so the clean-up is automatic. The post on what changes when a PDF becomes a spreadsheet lists the other things that tend to differ.
PDF charts and pictures that look like tables
A chart cannot be extracted as a table, because the numbers behind it are not in the file as text. A bar chart is a set of rectangles, and the heights of those rectangles are drawing instructions, not values. Only the words printed on the chart, such as axis labels and any data labels, can be read as text.
Three things that look like tables but are not
- A chart with data labels. The labels are real text, so a tool may extract them, but without the structure that tied them to bars or categories.
- An image of a table. A screenshot or a scan pasted into a PDF is a picture. No words exist to read until optical character recognition (OCR) turns the pixels into text. If your page is one of these, start with converting a scanned PDF to Excel, since the first problem is recognising characters, not finding columns.
- A table drawn as vector shapes. Some design tools convert the text to outlines, so the letters are shapes. They look like text and cannot be selected.
The select-and-drag test
Try to select a single word in the table. If it highlights, the page has real text and extraction can work; if nothing does, the ten-second test for image PDFs confirms it and points to OCR.
What to do with a chart
If you need the numbers behind a chart, look for a table elsewhere in the same document, often in an appendix. Some reports print the data next to the chart or at the back. If there is none, you can read the values from the chart by eye or estimate them from the axis, and that is an estimate, so record it as one.
Choosing your next step
Once you know how the software sees your table, the right approach for the job usually follows. For a short table, copying it straight into Excel may be all you need. If you want only a few values from the page, not the whole grid, extracting individual fields from a PDF is a smaller job.
FastBankConvert reads the layout of bank statements, a narrower job than finding any table in any report. It is not open yet, and you can register your interest on the get-started page.