Skip to content
Lamina PDF
0.9.0
GitHub
Open the web app

Troubleshooting, on one page

This page shows every Troubleshooting page in order. Read offline lists every section and the whole guide as one PDF.

Troubleshooting

Each troubleshooting page starts from what you see, such as an error code, an exit code or text in the wrong order, then gives the cause and the fix. Pick the page for what you were doing:

  • JavaScript and TypeScript: installing @laminapdf/sdk, loading its WebAssembly in browsers, bundlers and Cloudflare Workers, and its memory.
  • Rust: the version to depend on, the crate’s features and the Rust version it needs.
  • The command line: exit codes, passwords, files that already exist and output to a terminal.
  • Opening and saving files: passwords, signed files and files over a limit, in every language.
  • Extracting text: empty pages, text in the wrong order, missing characters, and headers that vanish.
  • Rendering pages: PDFium not found, images too large, and pages that draw blank or wrong.

Every error and warning carries a code, and every code has a page that says what it means and what to do. When an entry here doesn’t match, look the code up in the error and warning codes.

Troubleshooting JavaScript and TypeScript

These entries cover @laminapdf/sdk in Node, browsers, bundlers and Cloudflare Workers: loading the WebAssembly modules, and the memory they use. Each entry starts from what you see, then gives the cause and the fix.

Cause: your project is on version 0.0.0, a placeholder that only reserves the name. npm installs the latest tag unless you name a version or another tag, and before 0.2.0 Lamina PDF published only alphas, under the alpha tag, so a plain npm install @laminapdf/sdk picked the placeholder.

Fix: install the version these docs describe: npm install @laminapdf/sdk@0.9.0. See Install.

Cause: a function of @laminapdf/sdk ran before init() finished loading the WebAssembly.

Fix: await init() once, before anything else. After it, every call is synchronous. See not-initialized.

Drawing text throws text-module-not-loaded

Section titled “Drawing text throws text-module-not-loaded”

Cause: the builder lives in the base module, which has no fonts or text. Lamina PDF loads only the modules you ask for, so a page downloads only what it uses.

Fix: load the text module before you create the builder: init({ text: true }), or loadText() after init(). See text-module-not-loaded and Text and fonts.

Reading text throws extract-module-not-loaded

Section titled “Reading text throws extract-module-not-loaded”

Cause: the document was opened in the base module, which can’t extract text.

Fix: load the extract module, with init({ extract: true }) or loadExtract(), or the text module, before you open the document. A Cloudflare Worker can’t fetch it, so import it and pass it: import extract from "@laminapdf/wasm/lamina_pdf_extract.wasm", then await loadExtract(extract). See extract-module-not-loaded.

Cause: the page’s Content Security Policy doesn’t allow compiling WebAssembly.

Fix: add 'wasm-unsafe-eval' to its script-src. Lamina PDF needs nothing else from the policy. See Browser and bundlers.

Cause: Vite pre-bundles dependencies into its own cache, and the .wasm files don’t move with the JavaScript that loads them.

Fix: exclude the package from pre-bundling: optimizeDeps: { exclude: ["@laminapdf/sdk"] } in vite.config.ts. A Web Worker that uses @laminapdf/sdk/worker needs the same setting. See Browser and bundlers.

Cause: Cloudflare Workers can’t compile WebAssembly at run time, so init() can’t build the modules from bytes or a URL.

Fix: let Wrangler bundle the package, and call init() without a URL or bytes. Wrangler picks the package’s entry for Cloudflare Workers, which imports the .wasm files as compiled modules. See Cloudflare Workers.

Cause: documents and builders live in WebAssembly memory, and the garbage collector frees them late: too late for a long-running page or server. WebAssembly memory also never shrinks, so one large file leaves it large.

Fix: free each one when you’re done: using doc = … frees it at the end of the block, and doc.free() at once. A call on a freed one throws disposed. To give grown memory back, call reset() while no document is in use: every module starts afresh, and handles from before throw instance-reset. See You free what you create.

Cause: the WebAssembly module ran out of memory (it may grow to 2 GiB), or it trapped on a bug in Lamina PDF. Either leaves the module’s memory half-written, so Lamina PDF replaces the module’s instance before the next call.

Fix: open the document again from its bytes: documents, pages and builders from the old instance throw instance-reset. For out-of-memory, keep fewer documents open at once and lower the open limits for files you don’t trust. Report a wasm-trap with the file that causes it. See out-of-memory and wasm-trap.

Next: opening and saving files, for passwords, signed files and limits.

Troubleshooting Rust

These entries cover the laminapdf crate: the version Cargo picks, the features that bring each part of the API, and the Rust version it needs. Each entry starts from what you see, then gives the cause and the fix.

Cause: your project is on version 0.0.0, a placeholder that only reserves the name. Every release before 0.2.0 was an alpha, and Cargo never picks an alpha unless you name it, so a plain cargo add laminapdf picked the placeholder.

Fix: add the version these docs describe: cargo add laminapdf@0.9.0. See Install.

Cargo finds no version that matches your requirement

Section titled “Cargo finds no version that matches your requirement”

Cause: Lamina PDF’s releases before 0.2.0 were alphas, whose versions end in -alpha and a number, and Cargo treats them as pre-releases. A requirement such as "0.1" matches only full releases, so Cargo’s error lists the alphas as “candidate versions found which didn’t match”.

Fix: require 0.2.0 or later, as cargo add writes it: laminapdf = "0.9.0". Cargo then takes later releases in the same 0.x line, which the stability policy promises need no change to your code. Read the changelog before you move to a new 0.x line.

Builder or page_text is not found in laminapdf

Section titled “Builder or page_text is not found in laminapdf”

Cause: the crate compiles only the parts of the API its features turn on, so a missing feature gives unresolved import or no method named. With --no-default-features, it only opens, reads, edits and saves documents.

Fix: turn on the feature that brings what you use: build for the builder without text, extract for text extraction, or text for fonts and text, which brings both. The default features include text. Install lists every feature.

Cause: explain returns each code’s page from these docs as text, which adds about 80 KB to your program. The function is behind the explain feature, which is off by default.

Fix: turn the feature on: cargo add laminapdf@0.9.0 --features explain. Or link to the page instead: every error’s docs_url() gives its address.

Cargo says the crate requires a newer rustc

Section titled “Cargo says the crate requires a newer rustc”

Cause: your Rust is older than the oldest release Lamina PDF supports, two behind the newest stable one. The error reads “cannot be built because it requires rustc 1.97 or newer”.

Fix: update Rust with rustup update stable, or pin the project to a newer toolchain in its rust-toolchain.toml. See the stability policy.

Next: opening and saving files, for passwords, signed files and limits.

Troubleshooting the command line

These entries cover the laminapdf tool. Most start from an exit code, because that is what a script sees first. Each entry starts from what you see, then gives the cause and the fix. laminapdf help exit-codes prints every exit code, and Use laminapdf in scripts explains them.

A script stops on exit 3, though the command worked

Section titled “A script stops on exit 3, though the command worked”

Cause: exit 3 means the command succeeded but raised warnings, such as a file that needed repair. A shell with set -e stops on any exit code other than 0, so it treats the warnings as a failure.

Fix: read the warnings on standard error, or in the report’s warnings with --json. If they don’t matter to your script, pass --warnings-ok, which makes the same run exit 0.

The command exits 4 with overwrite-refused

Section titled “The command exits 4 with overwrite-refused”

Cause: the output file already exists, and laminapdf replaces a file only when you pass --force. It checks every output before it writes any, so nothing was written.

Fix: pass --force to replace the file, or write to a new name. --dry-run shows what a command would write without writing it. See overwrite-refused.

Cause: the file needs a password, and the command had none, or the wrong one. The error is password-required or wrong-password. laminapdf never takes a password as an argument, because other users of the machine can see a command’s arguments.

Fix: put the password in a file and pass --password-file FILE, or set the LAMINA_PDF_PASSWORD environment variable. See Passwords and limits and password-required.

The command exits 2 with binary-output-to-terminal

Section titled “The command exits 2 with binary-output-to-terminal”

Cause: the command would write a PDF or an image to standard output, and standard output is your terminal. laminapdf refuses rather than fill the screen with binary.

Fix: name an output file with -o, or send standard output to a file or another command: laminapdf render in.pdf --pages 1 -o - > page-1.png. See binary-output-to-terminal.

The command exits 2 with invalid-page-range

Section titled “The command exits 2 with invalid-page-range”

Cause: the range you gave doesn’t parse, or it names a page the document lacks, such as page 9 of a 5-page file. Page ranges count from 1.

Fix: check the range against the page-range grammar: 3-7, z for the last page, r2 for the second from the end, and x3 for every page but page 3. See invalid-page-range.

Next: opening and saving files, for signed files and files over a limit.

Troubleshooting opening and saving files

These entries apply in every language and on the command line, because they come from the file itself. Each one starts from what you see, then gives the cause and the fix.

Opening a file fails with password-required or wrong-password

Section titled “Opening a file fails with password-required or wrong-password”

Cause: the file is encrypted. password-required means you passed no password, and wrong-password means the one you passed matches neither of the file’s passwords.

Fix: ask your user for the password and open the file again with it. Nothing else has changed. On the command line, pass it with --password-file or LAMINA_PDF_PASSWORD. See Open password-protected files.

Cause: saving would break a signature, so the save fails with would-invalidate-signatures. A signed file saves only incrementally, and only with the edits its signatures allow.

Fix: keep the default save mode and make only edits the signatures allow. To save anyway, ask your user first, then pass invalidateSignatures: true (SaveOptions::with_invalidate_signatures(true) in Rust). See Save a PDF and would-invalidate-signatures.

Opening or reading a file fails with limit-exceeded

Section titled “Opening or reading a file fails with limit-exceeded”

Cause: the file asked for more than a limit allows: a stream that decompresses past its cap, for example, or objects nested deeper than the nesting limit. Lamina PDF reads every file within limits, so a hostile file can’t exhaust your memory or your time.

Fix: the error’s data.limit names the limit as Rust spells it, such as max_stream_decoded. If you trust the file, raise that one limit in the open options (maxStreamDecoded in TypeScript), or on the command line with its flag (--max-stream-decoded N). Leave the limits alone for files you don’t trust. See Open files you don’t trust and limit-exceeded.

Next: extracting text, for pages whose text comes out empty or in the wrong order.

Troubleshooting text extraction

These entries cover text extraction, in TypeScript, Rust and laminapdf extract. A PDF stores where each piece of text is drawn, not the order to read it in, so most surprises come from the file rather than from your code. The options these fixes set are in TypeScript and Rust; laminapdf extract has no flags for them yet. Each entry starts from what you see, then gives the cause and the fix.

A page’s text is empty, with extract-needs-ocr

Section titled “A page’s text is empty, with extract-needs-ocr”

Cause: the page draws no text that extraction can use. A scanned page is one image, and outlined text is drawn as shapes. On the command line, the warning makes laminapdf extract exit 3.

Fix: send the pages the warning names to OCR (optical character recognition) or a vision model. Each page in the JSON has a textLayer whose status is needs-ocr for these pages. See Extract text for an LLM and extract-needs-ocr.

Cause: OCR made the scan searchable by putting invisible text under the image. Extraction leaves text a reader can’t see out of the blocks, so the page’s textLayer status is ocr-layer and the warning is extract-needs-ocr.

Fix: to keep the existing OCR text, set drop: { keepSpans: true } (DropOptions::keep_spans in Rust). The text is then listed under dropped, marked invisible. Or run OCR again, if you don’t trust the old layer. See extract-needs-ocr.

The text runs across two columns, with extract-column-order-uncertain

Section titled “The text runs across two columns, with extract-column-order-uncertain”

Cause: extraction works the reading order out from the layout, and this page left it in doubt. For example, two columns set closer than a font size apart read as one. The blocks in doubt have a confidence of 0.5.

Fix: check those pages by hand, or send them to a layout model, which reads columns from the page’s image. If the file is tagged, its structure tree gives the order, and a page read in the tree’s order never raises this warning. See extract-column-order-uncertain.

A tagged file reads in layout order, with extract-struct-tree-ignored

Section titled “A tagged file reads in layout order, with extract-struct-tree-ignored”

Cause: the file’s structure tree, which gives its reading order, failed extraction’s checks. A tree that covers less than 80% of the page’s visible text, or that jumps back across columns, isn’t trusted, and extraction reads the page by its layout instead.

Fix: nothing, in most cases: the layout order is the best one extraction can find. To use the tree anyway, set readingOrder: "tagged" (ReadingOrder::Tagged in Rust). "layout" and "content-stream", the order the page draws its text, are the other choices. See extract-struct-tree-ignored.

Characters come out as �, with unmapped-glyph

Section titled “Characters come out as �, with unmapped-glyph”

Cause: the font has no map from its glyphs to characters, so extraction can’t tell which letter each glyph draws. Most of these are subset fonts without a ToUnicode map: the table in a font that says which character each glyph draws. Extraction writes U+FFFD, the replacement character, for each glyph.

Fix: only OCR can recover the text, because the file doesn’t hold it. A page with many such glyphs is also needs-ocr. See unmapped-glyph.

Headers, footers and page numbers are missing

Section titled “Headers, footers and page numbers are missing”

Cause: extraction drops page furniture by default: text the file marks as an artifact, and headers, footers and page numbers that repeat across pages. Each one is listed under dropped instead, so a language model doesn’t read the same header on every page.

Fix: to keep them in the text, set drop: { furniture: false } (DropOptions::furniture in Rust).

Next: rendering pages, for PDFium, large images and pages that draw wrong.

Troubleshooting rendering

These entries cover drawing pages as pixels: laminapdf render, and the hayro and PDFium renderers in Rust and on the web. Each entry starts from what you see, then gives the cause and the fix.

PDFium fails to load, with render-backend-unavailable

Section titled “PDFium fails to load, with render-backend-unavailable”

Cause: Lamina PDF loads the native PDFium library when it runs, never when it builds, so the library must be on the machine. It looks only in the folder you name, and found no library there.

Fix: download PDFium for your platform from the pdfium-binaries project, and set LAMINA_PDF_PDFIUM_DIR to the folder that holds libpdfium.so, libpdfium.dylib or pdfium.dll. laminapdf render --backend pdfium and PdfiumBackend::from_env() read that variable; PdfiumBackend::bind(dir) takes the folder itself. See render-backend-unavailable.

A large page or a high resolution fails with render-too-large

Section titled “A large page or a high resolution fails with render-too-large”

Cause: an image may hold at most 16,777,216 pixels (4096 × 4096) and 16,384 pixels on a side, so a hostile file can’t ask for a bitmap of any size. A US Letter page goes over that size above about 420 dots per inch, so laminapdf render --dpi 600 fails on it.

Fix: on the command line, lower --dpi or --scale. In code, draw the visible part of the page as tiles of 256 to 512 pixels, by giving each request a clip, instead of the whole page at once. Raise the limits only when you mean to make the larger image. See render-too-large.

A page draws differently than in a browser

Section titled “A page draws differently than in a browser”

Cause: laminapdf render draws with hayro, a renderer written in Rust, unless you choose another. hayro draws most pages the same as PDFium, the renderer in Chrome, and most of the pages it gets wrong go wrong on fonts or annotations.

Fix: draw the page with PDFium: laminapdf render --backend pdfium, with PDFium installed as above. In Rust, use laminapdf-render-pdfium, and on the web @laminapdf/render-pdfium. See How a page is drawn.

laminapdf render exits 2: two pages would write the same file

Section titled “laminapdf render exits 2: two pages would write the same file”

Cause: -o takes one file-name pattern for every image, and the pattern gives two pages, or two input files, the same name. A pattern without {n} names every page of a document alike. render works out every name before it draws anything, so nothing was written.

Fix: put the page number in the pattern, as in -o 'page-{n}.png', and the input’s name too when you render several files: -o '{stem}-{n:03}.png'. See Images: render and invalid-command-line.

laminapdf render fails with output-unwritable

Section titled “laminapdf render fails with output-unwritable”

Cause: the folder in the -o pattern doesn’t exist, or you can’t write to it. render doesn’t create folders.

Fix: make the folder first, such as mkdir -p pages, then run laminapdf render in.pdf -o 'pages/{n}.png'. See output-unwritable.

Next: the error and warning codes, with what each one means and what to do.