pdftotext is the Poppler tool for pulling text out of a PDF, and its -layout flag keeps the physical layout as far as possible, so columns stay columns and tables stay readable. It only works when the PDF already has a text layer, so a scan must be OCRed first. This guide runs it on one OCRed PDF.
Prerequisites
Poppler installed, which provides pdftotext, and an OCRed PDF. Work on a copy.
Steps
1. Check the PDF has a text layer
Run pdftotext on the first page and read the output. Expected result: the output holds the page text, not an empty file.
2. Run pdftotext with the layout flag
Run pdftotext -f 1 -l 3 -layout input.pdf output.txt. Expected result: output.txt is created with the text of pages 1 to 3.
3. Check the columns stayed in place
Open output.txt and read the first table. Expected result: the columns line up as they do on the printed page.
4. Search the output for a word
Search output.txt for the word harvest. Expected result: the word is found once, on page 1.
Practice check: fictional three-page OCRed letter with a table
The table below is fictional practice material. It lists the four checks for the pdftotext output.
| Check | Expected result |
|---|---|
| Text layer present | Text extracted |
| Output created | output.txt exists |
| Columns aligned | Table columns line up |
| Word found | harvest once, page 1 |
Expected result. the output file is created, the table columns line up as on the printed page, and the word harvest is found once on page 1.
Limits
- pdftotext reads the text layer, not the image, so a scan without OCR gives an empty file; the -layout flag preserves layout, not meaning.
- UNTESTED – no OCR tool or AI tool was run; all results above are expected results. The practice file is fictional.
Sources
- Table extraction from PDFs: pdfplumber, Camelot, Tabula, and scans – Check the PDF has selectable text first with pdftotext -layout; scanned PDFs need OCR before these tools. Checked 2026-11-29.
- Tesseract OCR Documentation, output formats – Tesseract supports plain text, searchable PDF, hOCR, TSV, ALTO and PAGE output; –psm sets the page segmentation mode. Checked 2026-11-29.
