How to split scanned PDF into individual files based on identifier?

Request for Help

I work in a manufacturing/warehouse environment and we receive batches of scanned packing slips as single massive PDFs. Nobody on the teams splits these and that’s why I want to automate it.

The problem:

\- PDFs are fully scanned — no embedded text, all image-based

\- Pages are landscape-rotated 90°

\- Each "document" inside the batch belongs to a specific 8-digit PO number (e.g. 20289562)

\- Some pages have no PO number at all (cover sheets, continuation pages)

\- Occasionally the same PO spans multiple consecutive pages

What I'm trying to build:

\- Script reads a folder of PDFs

\- OCRs each page and detects the PO number

\- Groups consecutive pages that share the same PO into one output PDF

\- Pages with no PO detected get flagged separately for manual review — not silently attached to another PO

\- A second script lets a human approve or reject each output file before it gets moved to the final folder

Questions:

\- What's the best way to handle rotation detection before OCR? I was thinking Tesseract OSD but open to other approaches

\- How would you handle pages with no PO — attach to the previous group, flag as unknown, or something else?

\- Any tips on making the OCR results consistent between runs? Right now borderline scans feel non-deterministic

\- Is PyMuPDF + pytesseract the right stack for this or is there something better for scanned documents?

Not a professional developer — just trying to automate something that's eating up hours of manual work every week. Any advice appreciated.

Posted Jul 23, 2026, 5:00 AM UTC

58
Loading comments…