Tools,

Convert a PDF to CSV for free, tested

52 of 72

new test tables exact, free, with Docling

Get pdf2csv.py

One script, one CSV per table

pdf2csv.py runs Docling on your computer and writes one CSV file a table.

pip install docling
python pdf2csv.py statement.pdf

You get statement-table-1.csv, and so on. It never overwrites a file. On our Mac, Docling took 3.3 to 5.3 s a page on average. Its Python install was 1.2 GB, not counting its model files.

pdf2csv.py

What does it do with a scanned PDF?

A scan has no text inside, so the script says so and prints the OCRmyPDF command to run first. The scans section below has the scores.

Docling and our Actor lead

72 new test tables, made after our table code was frozen, 6,175 cells
Way Tables exact Cells right
Our Actor's code, then md2csv.py 55 89.4%
Docling (pdf2csv.py) 52 88.5%
camelot hybrid 39 75.0%
camelot stream 36 70.1%
tabula -g -t 25 54.2%
pdftotext -layout, split by Python 13 59.8%
tabula, no flags 4 14.8%

Exact means every cell of the table is right, with no extra column. Every way wrote real CSV files, and we scored the files.

All 12 ways, and our 84 older test tables
Tables exact: 72 new, 84 older
Way 72 new 84 older
Our Actor's code 55 84
Docling 52 61
camelot hybrid 39 42
camelot stream 36 42
camelot network 35 42
tabula -g -t 25 44
pdftotext, split by Python 13 6
tabula -l 11 10
camelot lattice 7 7
tabula, no flags 4 28
tabula -t 0 25
pdftotext, then sed 0 0

Our Actor's table code was built on the 84 older tables on Nov 2, so its 84 is a home score. The 72 new ones were made later that day, after that code was frozen, by a generator written without seeing the code. Later builds changed the code again.

Docling found no table on 18 of the 84 older PDFs. tabula -l and camelot lattice follow drawn lines, so they found nothing on tables without lines.

Add -p all, or lose page 2

The tabula and camelot command lines read page 1 unless you ask for more. On our 2-page test PDF, both left out page 2, with no warning.

java -jar tabula-1.0.5-jar-with-dependencies.jar -g -t -p all -o out.csv statement.pdf
camelot hybrid -p all -o out.csv statement.pdf

tabula writes all tables into one CSV file. camelot writes one file a table, such as out-page-2-table-1.csv. The tabula jar is in the tabula folder that pip install tabula-py makes. It needs Java.

tabula also needs -g -t: 25 of 72 new tables exact, against 4 with no flags.

A sed one-liner breaks the amounts

pdftotext -layout statement.pdf - | sed -E 's/ {2,}/,/g' > out.csv
One bank statement row
In the PDF 10/01, Opening balance, (empty), (empty), 4,218.40
In out.csv 10/01,Opening balance,4,218.40

The two empty cells were gone, and the comma in 4,218.40 made a new column. This line got 0 of 156 tables exact.

Two tools that make no table

Scanned PDF: OCR first

4 scanned tables, 256 cells
Way Cells right
tabula, camelot or Docling (no OCR) on the scan 0
OCRmyPDF, then pdf2csv.py 185
OCRmyPDF, then tabula -g -t 185
OCRmyPDF, then camelot hybrid 165
Our Actor, on the scan 254

The OCRmyPDF ways got no table exact. Our Actor got 2 of 4 exact.

No install: our Actor reads it

Our Apify Actor reads a PDF in the cloud and returns each table as Markdown. Pages with their own text are free. A scanned page costs $0.006, and each run has a $0.00005 start fee.

curl -s -X POST "https://api.apify.com/v2/acts/brasspage~pdf-ocr-to-markdown/run-sync-get-dataset-items" \
  -H "Authorization: Bearer $APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"documentUrls": ["https://example.com/statement.pdf"]}' \
  | jq -r '.[].markdown' > statement.md
python md2csv.py statement.md

md2csv.py needs Python only, and writes one CSV file a table.

Try the Actor md2csv.py

How I tested it
  • New set: 72 one-page PDFs from Chromium, LibreOffice and reportlab, rebuilt from seed 20261104 (first made Nov 2). 36 have no lines, 25 some lines, 11 a full grid.
  • Older set: the 84 test PDFs of our pdfplumber test. Every value in both sets is made up, so we know each true cell.
  • Score: each CSV file read back with Python's csv module. A cell is right when its text matches, with runs of spaces made one.
  • Scans: 4 ruled tables at 300 dpi, blurred, with gray noise, as JPEG. OCRmyPDF 17.13.0 with Tesseract 5.5.4.
  • Versions: Docling 2.143.1 (text only, no OCR), camelot-py 2.0.0, tabula-java 1.0.5 from tabula-py 2.11.0 on OpenJDK 21, pdftotext 26.03.0, our Actor's code at build 0.1.95, run on our Mac.
  • Not tested: online converters (we did not upload files), Excel, Numbers, real bank statements, tables over 2 pages, Windows.

Questions people ask

How do I convert a PDF to CSV on a Mac for free?

Run pip install docling, then python pdf2csv.py statement.pdf. For a smaller install, use pip install camelot-py and camelot hybrid -p all -o out.csv statement.pdf.

Can LibreOffice convert a PDF to CSV?

Not in our test. soffice --headless --convert-to csv stopped with Error: no export filter.

Why does tabula only give me the first page?

Its command line reads page 1 unless you add -p all. camelot does the same. Neither warned us.