← Back to library

Split one big scanned PDF into its separate documents

Jim Le shares n8n templates that turn each page of a bundled PDF into an image and ask OpenAI's Decisions API, a fast classifier in public beta, whether that page begins a new document. The workflow cuts the bundle at those pages. In his invoice test, 30 invoices came out of a 129-page scan in seconds.

  • OutcomeTurn a bundle of scanned paperwork, such as a stack of invoices saved as one file, into one PDF per document without paging through it to mark where each one ends.
  • SetupAn afternoon+
  • LevelAdvanced
  • CreditJim Le
View original
Works with
n8n

Published Oct 22, 2026Updated Oct 22, 2026AI dry run on sample input: passed Oct 22, 2026Source verified Oct 23, 2026

When should you use it?

  • A supplier, client or scanner hands you many documents merged into a single PDF
  • Documents vary in length, so splitting every fixed number of pages does not work
  • Rule-based text matching keeps failing on scans or changing layouts

Not for: Files with sensitive data you are not allowed to send to OpenAI; One-off bundles small enough to split by hand in a few minutes

What do you need, and what do you get?

You need

  • An n8n instance
  • An OpenAI API key with billing set up (the Decisions API has no free tier)
  • A way to turn PDF pages into images, such as StirlingPDF or your own tool
  • A sample bundle where you already know the right split points

You get

  • One file per document, cut where a new document starts
  • A short list of pages the classifier could not decide, for you to check
  • Optional per-document labels such as an invoice number, if you add an extraction step

How does it work, step by step?

  1. Pick a templateDownload the creator's template that is closest to your case (invoices, admissions packets or legal discovery) from his forum post and import it into n8n.
  2. Connect the servicesAdd your OpenAI key and your PDF-to-image service; the creator uses StirlingPDF, which also has a self-hosted version for more privacy.
  3. Describe a first pageEdit the question the workflow asks about each page so it lists what a first page looks like in your documents, using our prompt below as a starting point.
  4. Test on a known bundleRun it on a file where you already know the right answer and compare every split point.
  5. Add a review stepSend pages the classifier is unsure about to a person instead of guessing, then let the workflow save the split files.

The prompt

Our own prompt, inspired by Jim Le and written to work in n8n. Values in lime are placeholders.

Fill in the blanks (optional; the copied prompt uses your values)

Prompt3 variables
You are looking at a single page taken from a bundle of {document_kind} that were scanned into one file.
Question: is this page the first page of a new {document_kind}?
Count it as a first page when you see {first_page_signals}.
Count it as a later page when you see {continuation_signals}, for example a page number above 1 or a balance carried over.
If the page is blank or you cannot tell, answer unsure rather than guessing.
Reply with three items: first_page (yes, no or unsure), the clue you relied on, and the heading plus any reference number you can read on the page.

Inspired by Jim Le: n8n x OpenAI Decision API: Splitting batched PDFs for invoices, legal discovery and admissions. The prompt above is written by playbooks.bot in our own words; nothing from the original is quoted.

What can go wrong?

  • Every page you process is sent to OpenAI; check your contracts and privacy duties before running client or patient files through it.
  • The creator notes that wording matters a lot for accuracy, so expect to rewrite the page question a few times for your documents.
  • Blank separator pages, rotated scans and pages without numbers are where splits go wrong; test those specifically.
  • The Decisions API is in public beta and its model, pricing and limits may change; recheck OpenAI's documentation before relying on it.

Our take

This solves a genuinely annoying back-office problem with very little machinery: look at each page once, decide whether it is a first page, cut. The creator's numbers are striking (about seven seconds and two cents for his 129-page invoice test), and he backs them with sample files you can rerun yourself. We could not call the Decisions API from our build box, so our dry run checked the decision logic rather than the service. We applied our page prompt to the text of a synthetic 12-page utility bundle with seven documents, a blank separator page, two documents without page numbers, a rotated scan and a final notice mixed in with invoices. All six real boundaries were found, the blank page was sent to review instead of being glued onto a document, and the split matched our answer key. The notice was correctly treated as a new document but nothing labeled it as a different type, so our prompt now asks for the heading as well. Speed and cost figures here come from the creator's post; we did not reproduce them.

Where the time goes back: Finding where each document ends in a long scan is slow page-by-page work; the workflow proposes every split point and leaves you only the uncertain pages.

FAQ

What is the Decisions API?
An OpenAI endpoint, in public beta at the time of writing, that answers yes-or-no, pick-one or scoring questions about text or images and returns probabilities instead of free text. OpenAI describes it as much faster than its general Responses API.
Can I use this for legal discovery?
The creator includes a discovery template that also titles and dates each document. Treat its output as a first pass for a person to review, not as a finished index.
Is the creator selling something?
He runs a company called subworkflow and hosts the templates on its site, but states that the post is not sponsored.

Source and credit

Inspired by Jim Le. We describe the idea in our own words, link to the original, and wrote the prompt ourselves; nothing is quoted.

Inspired by
n8n x OpenAI Decision API: Splitting batched PDFs for invoices, legal discovery and admissions
Creator
Jim Le
Published on
n8n Community
Original date
Oct 12, 2026
License
Not openly licensed (the poster keeps all rights), so we quote nothing and link to the original
Originally for
n8n
AI dry run
Oct 22, 2026: passed. Dry-run tested by our AI test agent on sample input. Decision logic and split rule checked; speed and cost figures are the creator's, not reproduced.
AI dry run on sample data; not run with live connected accounts. The playbooks.bot test agent filled the prompt with synthetic inputs, produced the output and checked it against the page's stated outputs and guardrails.
Verified
Oct 23, 2026: source link resolves to the original, the credited creator published it, our excerpt or prompt matches it, and the license allows our use.

Are you the creator? Claim or correct this page.

More in Finance & Accounting

All 62 Finance & Accounting playbooks →

Related playbooks

Finance & AccountingWorkflow✓ AI dry run

Auto-file emailed invoices by month for your accountant

Every invoice that reaches Gmail is saved as a PDF in a year and month folder in Google Drive and logged in that month's sheet, ready to share with your accountant at month end.

Credit: Ioana Frincu

Under an hour
Finance & AccountingSkill✓ AI dry run

Have Claude build Excel files that recalculate cleanly

Give Claude the xlsx skill so that any spreadsheet it creates or edits keeps live formulas instead of pasted results, passes a full recalculation with zero formula errors before delivery, labels every assumption with its source, and follows standard financial model conventions or the existing file's own styling.

Credit: Anthropic

Minutes
Finance & AccountingRoutine✓ AI dry run

Reconcile orders and draft invoices every night

Scheduled prompts check orders against the CRM, draft invoices for review and file contracts.

Credit: Sunnyvale (@SunnyvaleSBay)

An afternoon+
Finance & AccountingWorkflow✓ AI dry run

Read invoice photos with a reject gate and QR override

Turn uploaded invoice photos and PDFs, including Arabic and handwritten ones, into clean JSON fields in n8n: the model first says whether the file is an invoice at all, code then tidies digits and dates, exact values decoded from the invoice QR code replace the model's reading where available, and anything that fails is refused and removed before it is stored.

Credit: Nour_Aldeen_Tofi

An afternoon+
Finance & AccountingWorkflow✓ AI dry run

Fill invoice templates from approved job data

Invoices go out from a spreadsheet row to a PDF in the client's inbox, and the sheet shows what has been sent.

Credit: u/Ok_Butterscotch_6732 on r/maketemplates

Under an hour