scanlayer
Docs / Guides

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.

bash
scanlayer *.jpg -o ./converted/ --batch-workers 2
pythonbatch.py
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

bash
scanlayer a.jpg b.jpg -o combined.pdf --merge
pythonmerge.py
scanlayer.convert_merge(["a.jpg", "b.jpg"], "combined.pdf")

Combines multiple images into one multi-page PDF, in argument order.

PDF-only --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.

bash
scanlayer *.jpg -o combined.pdf --merge --workers 4
python
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 --mergeWithout --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 is not streamed A merge still expands all pages up front and keeps every processed page until the combined PDF is written, so its memory scales with document length. If a large PDF only needs one output per page, run it as a normal batch instead of --merge.
Requires poppler on PATH See Installation. If it is missing, scanlayer raises DependencyError with an actionable message rather than a cryptic subprocess failure.
bash
# 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
pythonpdf_input.py
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,
)