Split a PDF by what's on its pages
The accounting system exported all 73 invoices as one 200-page PDF. Splitting by page count is useless when invoices run 1-4 pages each. split --at starts a new file wherever a pattern appears, and names each file from the page itself.
One file per invoice, named correctly
pip install pdfblah
pdfblah split all.pdf -o invoices/ --at "Invoice #(\S+)" --name "{1}.pdf"
split into 4 file(s) in invoices/
front.pdf (pages 1-1)
ACME-100.pdf (pages 2-3)
BETA-7.pdf (pages 4-4)
ACME-101.pdf (pages 5-6)
- The pattern is a regular expression; whatever it captures becomes the filename:
{1}is the first capture group,{n}the part number,{page}the part's first page. - Pages before the first match (cover sheets, summaries) go to
front.pdfinstead of vanishing. - Deterministic and safe: captured text is neutered before it becomes a filename, duplicates get suffixes, and a pattern that never matches is a clear error pointing scans at OCR first.
And for book scans: cut the spreads apart
Scanned a book two pages at a time? Every PDF page holds a left and a right page. --spread cuts them apart:
pdfblah split book.pdf --spread pages.pdf
pdfblah split manga.pdf --spread pages.pdf --order rl # right-to-left books
The cut is lossless: each half is a crop window over the original content, exactly like a viewer zooming into one page, so nothing is re-rendered and the file stays crisp. Landscape spreads split left/right; portrait ones split top/bottom.
Tips
- Test the pattern first with
pdfblah find: it shows exactly which pages match before you split. - Statements work like invoices:
--at "Account statement" --name "statement-{n}.pdf". - After a spread cut, rotate --auto and Clean scan finish the digitizing chain.