brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: pdftotext -layout pulls the text out of a PDF and keeps columns

Tools
~/tips/tip-tools-pdftotext-layout

pdftotext -layout invoice.pdf invoice.txt

Turn a PDF into plain text you can search or paste.

Copying a table out of a PDF viewer tends to give a jumble. pdftotext, from the Poppler utilities, usually does better.

pdftotext -layout invoice.pdf invoice.txt

-layout tries to keep the text where it sits on the page, so columns of a statement or a price list stay lined up. Leave it off for running prose, where reading order is what you want.

Use a dash as the output name to send the text straight to the terminal, which makes the PDF searchable from a pipe:

pdftotext -layout invoice.pdf - | grep -i total

For a long document you can limit the pages with -f for the first and -l for the last:

pdftotext -f 3 -l 5 manual.pdf -

I’d reach for this when I want to find one amount in a pile of invoices without opening each one.

The big limit: it reads text that is already in the file. A scanned page is just a picture, so you’ll get nothing or a few stray characters, and you would need OCR for that. Complex layouts can still come out scrambled, so check numbers against the original before you rely on them. On Debian and Ubuntu the package is poppler-utils.

Further reading: pdftotext man page

More Tools tips shuf -n 3 films.txt xmllint --format feed.xml qrencode -t ANSIUTF8 'https://example.com/a/long/path?id=12345' where python ffprobe -v error -show_entries format=duration -of default=nw=1:nk=1 input.mp4 All Tools tips (14) All topics

Link