Technical 10 August 2026 5 min read

Why One Multi-Page Document Kept Splitting Into Separate Files — And How a Reader Helped Us Fix It

A user emailed us a scanned file that PaperSweep was handling wrong, and offered it to us purely so we could test against it. That one file led to a real fix — and a smaller, quieter fix right after it. Here's the whole story, including the part we almost missed.

TL;DR — A reader noticed that a multi-page insurance document was coming out of PaperSweep as several single-page PDFs instead of one, and sent us the file to reproduce it. We built a new page-boundary detection step that reads page numbers, reference numbers, and sender information to figure out where one document ends and the next begins, even without blank separator pages. While reviewing that change, we also caught — and fixed — a subtler bug it had introduced for the cases that already worked. Both are live now.

The report

Someone using PaperSweep to sort a batch of scanned mail got in touch to say that a document — a multi-page insurance policy, several pages long — had come back split into individual single-page files instead of staying together as one. Rather than just describing the problem, they sent us the actual scan, entirely so we could reproduce the bug and confirm the fix. That's an unusual level of trust to extend to a tool that processes your paperwork, and it's the reason this fix exists at all. We're genuinely grateful for it.

The file itself was handled exactly like any other upload: processed to reproduce the issue, then deleted on our normal schedule. We're not naming the sender or reproducing anything from the document here — this post is about what we learned from the shape of the problem, not the contents of anyone's mail.

Why blank pages weren't a reliable signal

Before this fix, PaperSweep decided where one document ended and the next began mostly by looking for blank pages between them — the way a scanner operator naturally separates documents when feeding a stack through a scanner. That works well when the person scanning remembers to insert a blank sheet between documents.

It falls apart the moment they don't — which, in practice, is often. A multi-page insurance policy, letter, or contract scanned back-to-back with no separator looks, to a blank-page detector, exactly like several unrelated single pages. That's what happened here: a document that was clearly one continuous filing — same sender, same reference number, sequential page numbering — got treated as N separate ones, each landing in its own file.

Teaching PaperSweep to read the page, not just count it

The fix was to stop relying solely on blank-page gaps and instead look at what's actually printed on each page. Most multi-page documents already carry the information needed to reconstruct their own structure, if you know where to look:

  • Page counters — phrases like "Page 3 of 5" or its equivalents in German, French, Italian, and Spanish, which directly state how many pages a document has and where a given page sits in it.
  • Reference numbers — policy numbers, invoice numbers, IBANs, customer numbers — the kind of identifier that repeats across every page of the same document and almost never matches between two unrelated ones.
  • Sender signatures — letterhead and layout cues that suggest a page is the first page of a new document rather than a continuation.

PaperSweep now reads each page for these signals and clusters pages into documents accordingly — languages included, since a scanned batch is rarely all in one language. The same pass also handles two related problems that come up in real-world scanning: pages fed through a scanner out of order (common with duplex scanning, where a page's front and back end up separated from its neighbours), and documents scanned with a page missing entirely, which now get flagged rather than silently passed through incomplete.

What changed in practice

Run against the file that started this — nine scanned pages with no blank separators — the new logic grouped them into four correct documents instead of nine incorrect ones, reconstructing exactly the structure a human sorting the same stack by hand would have produced. As a side effect, because whole documents are now classified in a single pass instead of page-by-page, the number of AI calls needed to classify a typical multi-page batch dropped by roughly 84%.

In the results view, documents that were reordered or that appear to be missing a page now carry a small badge, so it's obvious at a glance when a scan is worth a second look rather than a silent guess.

The part we almost got wrong

Here's the honest part of this post. Wiring the new page-reading logic into the pipeline fixed the case the reader reported — but a follow-up code review turned up something it had quietly broken: documents that did already have blank pages between them, which used to be sorted correctly, could end up with garbled text feeding into classification. The root cause was a small one — a page's OCR text was in one case being duplicated across its neighbours instead of staying scoped to the page it came from — but the effect was real, and it would have shipped invisibly if we hadn't gone back over the change deliberately.

We tested the fix against a synthetic multi-document file built specifically to reproduce that scenario, confirmed it now behaves correctly, and re-ran the original reported file to confirm nothing regressed there either. Both cases — documents with blank separators and documents without them — now go through the same, correctly-scoped pipeline.

Send us your weird PDFs

If PaperSweep gets something wrong on one of your files, the most useful thing you can do is exactly what this reader did: tell us, and if you're comfortable with it, share the file so we can reproduce the problem rather than guess at it. Any file sent to us for testing is treated with the same privacy handling as a normal upload — processed and then deleted, not kept, not read for any purpose beyond fixing the bug.

Thank you to the reader who sent us that file. It made the product better for everyone who scans a document without remembering to add a blank page in between — which, honestly, is most of us.