Multi-Page and Merge
Two related but different things: converting many separate files in one call (batch), and combining several pages into a single multi-page PDF (merge). A native PDF as input touches both.
Batch conversion
Multiple inputs plus a folder as -o converts each file independently,
one output per input.
scanlayer *.jpg -o ./converted/ --batch-workers 2
result = scanlayer.convert_batch(
["*.jpg"], "./converted/", batch_workers=2,
)
Converting several files at once
Separate files in a non-merge batch are converted concurrently, 2 at a time by default,
with --batch-workers N / batch_workers=N /
configure(batch_workers=N). 1 restores the original sequential
behavior. The value is capped by the number of inputs and your CPU count, results stay in
input order whatever order they finish in, and a single process-wide OCR ceiling
(ocr_max_concurrency, default CPU count) still limits how many Tesseract passes
run at once. --workers/workers= remains merge-only; the two options
are independent.
A single bad file does not abort the batch. CLI exit code 5 signals a
partial failure; in the library, check BatchResult.failures. See
Library API → convert_batch().
--merge: one PDF from many pages
scanlayer a.jpg b.jpg -o combined.pdf --merge
scanlayer.convert_merge(["a.jpg", "b.jpg"], "combined.pdf")
Combines multiple images into one multi-page PDF, in argument order.
--merge only supports --format pdf / output_format="pdf", since there is no single sensible multi-page schema for txt/json/tsv/hocr. -o / output_path must be a file path, not a folder, when merging.
Processing pages in parallel
A merge processes up to 3 pages at the same time by default, so one page's OCR can overlap
another page's preprocessing. Page order in the output is always the input order, and the OCR
result is the same whatever the setting: it only changes speed. The maximum is 4, and the value
is also capped by your CPU count and the number of pages. 1 processes one page at a
time.
scanlayer *.jpg -o combined.pdf --merge --workers 4
scanlayer.convert_merge(pages, "combined.pdf", workers=4)
# or as the default for every merge in this process:
scanlayer.configure(merge_workers=4)
Expect a modest speedup: in our tests, roughly 15% to 50% faster than one page at a time. Most of the time per page goes to image preprocessing, which does not speed up much when pages run side by side, so more pages in flight help less than you might hope.
If a page fails (for example a blank page without --force), the first bad page in
input order is the one reported, and pages that have not started yet are skipped.
Native PDF input
A .pdf file given as input is automatically rasterized page by page
(via pdf2image/poppler) before OCR. In a normal non-merge batch, pages are
enumerated during planning and rasterized incrementally as workers free up, so peak memory
is bounded by the active workers instead of the whole document.
| With --merge | Without --merge |
|---|---|
| Re-runs OCR over an existing PDF and gets one PDF back out. | Gets one output file per source page, rasterized incrementally while the batch runs. |
--merge.
DependencyError with an actionable message rather than a cryptic subprocess failure.
# one output file per page
scanlayer scanned-report.pdf -o ./pages/
# re-OCR the whole document into a single merged PDF
scanlayer scanned-report.pdf -o ocred-report.pdf --merge
scanlayer.convert_batch(["scanned-report.pdf"], "./pages/")
# merge=True on convert_batch goes straight from a PDF's pages
# to one merged, re-OCR'd PDF:
scanlayer.convert_batch(
["scanned-report.pdf"], "ocred-report.pdf", merge=True,
)