IT
OmnvertImage • Document • Network

Getting tables out of a PDF and into Excel

6 min read
A laptop showing a spreadsheet with a small results table, a bar chart and a pie chart, next to a tablet held in one hand.

The table you see in a PDF exists in your eyes, not in the file. Extraction rebuilds it from geometry, and the places where that reconstruction goes wrong are entirely predictable.

A PDF does not contain a table

A PDF page is a list of drawing instructions, not a data structure. The content stream says "pick this font, move to this point, paint these glyphs, stroke a line from here to there". There is no notion of a row, a column or a cell anywhere in that list. What you recognise as a bank statement or a price list is simply text that has been positioned in neat vertical alignment, sometimes with rules drawn around it.

The one exception is tagged PDF. If the producer wrote a logical structure tree, the file really does containTable, TR and TD elements, and extraction becomes reading rather than guessing. In practice most files that come out of a print driver, a legacy reporting engine or a "save as PDF" menu carry no tags at all. So the job an extractor performs is reconstruction: rebuilding a structure that was thrown away at export time, using geometry as the only evidence.

Triage: what kind of file is on your desk

Open the file and try to drag-select one row of the table. That single gesture tells you which route to take.

  • Text selects and the table has ruling lines: the easy case, the lines give you the grid.
  • Text selects but there are no lines: columns will be inferred from whitespace alone.
  • Nothing selects: the page is an image and needs OCR before anything else.
  • Text selects but comes out as gibberish: the embedded font has no usable character mapping, and extraction will inherit exactly that garbage.

Extraction takes one of two routes

1. Follow the ruling lines

The tool collects horizontal and vertical strokes plus thin filled rectangles, finds where they intersect and builds a cell grid from those intersections. Each run of text is then assigned to whichever cell its centre falls into. On a ruled invoice or an audited financial statement this is close to exact. Camelot calls this its lattice mode, and the same idea sits behind most commercial extractors.

2. Follow the whitespace

With no lines to work from, all that remains is coordinates. A text extractor knows the horizontal start and end of every glyph box. The tool looks for vertical corridors that run down the whole page without a single glyph crossing them, and treats those as column boundaries. Rows come from the same logic on the vertical axis, clustering glyphs whose baselines sit within a tolerance of each other. Because it is a heuristic, it is sensitive to thresholds: tighten the corridor test slightly and two columns fuse, loosen it and one column splits in half.

Right-aligned numeric columns are the classic trap. A three-digit figure and an eight-digit figure start at different x positions, so the corridor test sees no clean gap on the left side of the column, while a left-aligned header above it may land in the neighbouring column entirely.

Six things that reliably break it

SymptomCauseWhat to do
One cell's text spills onto its own row belowMulti-line cell: the wrapped second line is read as a separate recordRaise the row tolerance, or merge rows whose key column is empty into the row above
First column empty, everything shifted rightMerged cell: one wide cell spans several grid columnsForward-fill the merged value; most exports write it only into the first column
Header row scattered across single-letter columnsRotated header: the text matrix is turned 90 degrees, so glyph boxes stack verticallyExclude the header band from extraction and type the column names yourself
The same header reappears in the middle of the dataPage break: the table header is reprinted on every pageExtract page by page and concatenate while dropping repeated headers
Numbers land in Excel as textThousands and decimal separators do not match the sheet locale, or a non-breaking space sits inside the numberNormalise separators, strip currency symbols, then convert the column to a number type
Words run together or letters come out spacedThe font applies spacing through positioning operators rather than actual space charactersAdjust the word-separation threshold, or regenerate the PDF from its source if you can

Five of those six come from visual choices in the source document. The prettier the table, the harder it is to rebuild; a plain ruled table with single-line cells extracts correctly in almost any tool.

The target format changes what survives

The same extraction looks different as CSV and as xlsx. CSV carries values only: cell formatting, merges and multi-line content are gone, and a line break inside a cell becomes a quoting problem that can corrupt the whole file. xlsx keeps cell types, so the number-versus-text distinction is visible in the file itself. If the data is heading into a database or a script, CSV is convenient; if a human is going to eyeball it first, xlsx saves work.

Wide reports hide one more trap. Some are printed in landscape by writing a rotation angle onto the page object while the text coordinates stay in the unrotated space, so an extractor may look for columns along the wrong axis. When the output is not merely wrong but nonsensical, try normalising the page rotation and running it again.

Scanned pages are a different problem

If the page is an image there are no glyphs to extract. Characters have to be recognised first, then the recognised boxes have to be grouped into rows and columns. The two steps feed each other: on a page scanned a degree or two off square, baselines drift and the vertical corridors close up, so the table can split wrongly even when every character was read correctly. Run PDF OCR first, and see what actually determines OCR quality before you blame the table extractor.

Verify before you trust the sheet

Table extraction fails quietly. The file opens, the columns look like columns, and two rows have silently merged. A five-minute check catches it.

  1. Row count: compare the number of records in the sheet with the number in the PDF.
  2. Column count: filter for rows that have fewer filled cells than the rest.
  3. Totals: if the document prints a grand total, recompute it in the sheet. A mismatch means a lost row or a number stored as text.
  4. Type check: numeric columns should right-align by default; anything left-aligned is still a string.
  5. Edges: the first and last rows break most often, so read both against the original.

A workflow that holds up

  1. Check whether text selects; if it does not, start with OCR.
  2. In a long report, split out only the pages you need so the extractor has less to guess about.
  3. Run the file through PDF to Excel and apply the five checks above.
  4. If you want flowing text rather than a grid, PDF to Word preserves reading order better.
  5. When the goal is only to show the table, rendering the page to an image is the fastest honest answer.

One caveat worth stating plainly: the PDF tools on this site upload your file to a server for processing. If the document is a payroll run or a signed contract, read how redaction really works before you share it, because drawing a black box over a name does not remove the name.

Frequently asked questions

Why is PDF to Excel flawless on one file and useless on the next?

It depends on the source document. When the table is ruled, the tool builds its grid from the strokes and the result is usually exact. With no ruling lines, columns are inferred from whitespace alone, and merged cells, wrapped cells and rotated headers all break that inference.

Can I extract a table from a scanned PDF?

Not directly, because there is no text on the page. OCR has to recognise the characters first, and then the recognised boxes are grouped into rows and columns. On skewed or low-resolution scans that second step produces more errors than the recognition itself.

Why did my numbers arrive as text?

Usually a separator mismatch: the document prints 1.234,56 while the sheet expects a decimal point. Non-breaking spaces and currency symbols inside the figure do the same thing. Normalise the separators, strip the symbols, then convert the column to a numeric type.

How do I know the extraction is correct?

Compare the row count with the PDF, confirm every row has the same number of filled cells, and recompute any grand total the document prints. If the total does not match, either a row was lost or a value is still a string.

What difference does a tagged PDF make?

In a tagged PDF the producer stored the table structure in a separate logical tree, so extraction is reading rather than guessing and cell boundaries come out right. Documents prepared for accessibility are often tagged; files produced by printing to PDF almost never are.

Tools used in this post

Sources

MethodologyImage credits