Birch UI v0.1
Pricing

TroubleshootingPDF

Fix a PDF viewer that stays empty, a render worker that does not start, a URL that is refused, Content Security Policy errors, a viewer that is too short, password errors, question marks instead of non-Latin text, unexpected full rewrites, signatures shown as modified, and problems with hot reloading and server-side rendering.

Open .md

Problems with a document are reported through the documentError event and in the page area of the viewer. Warnings and errors in the console start with [Birch UI PDF].

Symptom Jump to
The render worker could not be started; rendering on the main thread in the console, or renderMode is 'main' The render worker does not start
A document given by URL is not fetched unless the host allows it A URL is refused
Ignored removed options in the console Removed options
The viewer is 320 pixels tall, or has no visible pages The viewer has the wrong height
Refused to apply inline style, Refused to create a worker A Content Security Policy blocks something
A password prompt keeps coming back, or PdfPasswordError Password errors
? instead of Greek, Cyrillic, Arabic or CJK text in a saved file Non-Latin text is saved as question marks
Empty boxes instead of text on the page Text on the page is missing or wrong
save() returns mode: 'full', or mode: 'incremental' throws My save became a full rewrite
"The document was changed after signing" A signature shows as modified
Undo is empty after a watermark or a bookmark change Undo history is gone
Two viewers, or a blank one, after a hot reload Hot reloading and framework lifecycles
document is not defined on the server Server-side rendering
"Birch UI PDF · unlicensed copy" in the corner A watermark appears

The render worker does not start#

Cause. The viewer creates its worker with new Worker(new URL('./render-worker.js', import.meta.url), { type: 'module' }). Bundlers that understand this pattern (Vite, webpack 5, Rollup with a plugin, Parcel) emit the worker file. A bundler that does not, a server that does not serve the file with a JavaScript MIME type, or a Content Security Policy without a matching worker-src keeps the worker from starting.

What the viewer does. It renders on the main thread in short time slices, so the document still opens. It logs [Birch UI PDF] The render worker could not be started; rendering on the main thread once when you set worker explicitly; with the default it falls back silently. viewer.getRenderStats().renderMode tells you which mode is in use.

Fix. Create the worker yourself from the @birchui/pdf/render-worker entry, in the way your build resolves a worker script:

TypeScript
import { createPdfViewer } from '@birchui/pdf';

const viewer = createPdfViewer(container, {
  document: bytes,
  worker: () => new Worker(new URL('@birchui/pdf/render-worker', import.meta.url), { type: 'module' }),
});
await viewer.ready;
console.info(viewer.getRenderStats().renderMode);

Without a bundler, copy the dist folder of the package to your static files (render-worker.js imports other files from it) and pass worker: () => new Worker('/static/birchui/render-worker.js', { type: 'module' }). Pass worker: false when you want the main thread on purpose. The worker also needs OffscreenCanvas; in a browser without it the main thread is used.

A URL is refused#

Cause. A document given as { url } is not fetched unless you allow it. The load fails with a PdfRenderError whose code is 'fetch-not-allowed', reported through documentError.

Fix. Pass one of these:

  • allowFetch: true, and the viewer loads the URL with the global fetch;
  • fetchDocument, your own function that returns the bytes, for example to add credentials or to go through your API client;
  • bytes you fetched yourself, or a { rangeLoader } source.
TypeScript
createPdfViewer(container, { document: { url: '/files/annual-report.pdf' }, allowFetch: true });

See URL sources.

Removed options#

Cause. The options that configured the earlier third-party renderer are gone. Each is ignored, and one console warning names the replacement.

Fix. Delete the options that configured the earlier renderer and its worker. worker takes their place for the worker, renderOptions for limits and fonts, and renderer for a renderer of your own. The option that switched on XFA rendering has no replacement: XFA forms are not supported. The release notes list every name.

The viewer has the wrong height#

Cause. The viewer fills the height of its container and has a minimum height of 320 pixels. A container without a height of its own, such as a plain <div> in a page that scrolls, gives it nothing to fill.

Fix. Give the container a height, or pass one:

CSS
#contract {
  height: calc(100vh - 64px);
}
TypeScript
createPdfViewer(container, { document: bytes, height: 720 });

In a flex or grid layout, make sure the container can shrink: min-height: 0 on the flex child is the usual missing piece. The viewer follows later size changes by itself.

A Content Security Policy blocks something#

Cause and fix, by directive:

Directive What needs it What to do
style-src The injected <style> element Set injectStyles: false and import @birchui/pdf/styles.css. The print job also adds a small <style> for the paper size; when it is blocked, printing still works with the browser's default paper size.
worker-src (or script-src) The render worker Allow the origin of the worker script, usually 'self'. When the worker is blocked the viewer renders on the main thread
img-src Printing renders pages to blob: images Add blob:
script-src The rendering engine Nothing extra: the engine does not use eval or WebAssembly, so neither 'unsafe-eval' nor 'wasm-unsafe-eval' is needed
connect-src A { url } document with allowFetch: true Allow the origin of the file

Downloads are started from blob: URLs. Birch UI PDF makes no network request unless you pass a { url } document together with allowFetch: true.

Password errors#

Cause. The file is encrypted and the password is missing or wrong, or it uses an encryption scheme the package does not support.

What you see Meaning Fix
PdfPasswordError with reason: 'password-required' No password was given Use loadPdfDocument(bytes, { password }), or the password option of the viewer
reason: 'password-incorrect' The password is wrong For RC4 and AES-128 files, passwords outside Latin-1 cannot work; such files were encrypted from the Latin-1 form of the password
reason: 'unsupported' Certificate encryption or a non-standard security handler Decrypt the file with the tool that encrypted it
isLocked: true after openPdfDocument The synchronous function cannot decrypt Use loadPdfDocument
"A password is required to open this document" The prompt was cancelled, or onPasswordRequest returned null Expected; viewer.ready rejects and documentError fires
PdfCryptoUnavailableError Web Crypto is missing Serve the page over HTTPS or from localhost; use Node 20 or later

See Encryption and passwords.

Non-Latin text is saved as question marks#

Cause. Text boxes, stamps, typed signatures and field values are saved with the standard Helvetica and Times fonts unless TrueType or OpenType fonts are supplied, and those fonts cover Western European characters only. The text itself is stored correctly; only its drawn appearance shows ?.

Fix. Supply fonts with the fonts option of openPdfDocument or loadPdfDocument. The viewer has no fonts option yet; see Fonts in the viewer for the way around it. If a font is skipped with a console warning, it is probably an OpenType font with CFF outlines or a WOFF file; use a TrueType .ttf.

Text on the page is missing or wrong#

Cause. A font that is not embedded in the file is drawn with a substitute: the bundled Liberation and DejaVu faces for the standard 14 fonts and similar names, and the fonts of the device for CJK fonts that are not embedded. Letter shapes then differ from the typeface the document names; positions and widths do not. Empty boxes can mean that the device has no font for those characters. An embedded font whose predefined CMap is not covered is not drawn; the covered collections are listed under Predefined CMaps.

Fix. Embed the fonts when you control how the file is produced. Otherwise pass renderOptions.substituteFont to supply the bytes of the font yourself; it runs on the main thread. Check that renderOptions.standardFonts and renderOptions.predefinedCMaps are not switched off. If the page looks the same in other viewers, the cause is in the file.

My save became a full rewrite#

Cause. An incremental update is only possible when the page tree of the original file is unchanged. These force a full rewrite: moving, deleting, inserting or merging pages; applied redactions; adding, changing or removing encryption; and a damaged file whose cross-reference table was rebuilt when it was opened. save({ mode: 'incremental' }) throws PdfWriteError in those cases.

Fix. There is nothing to fix if the rewrite is what you want. If you must keep the original bytes, for example under an existing signature:

  • Check pdf.canSaveIncrementally() before saving, and undo the page changes if it is false.
  • Rotate pages instead of reordering them where that is enough; rotation alone is appended.
  • For a damaged original, save it once with mode: 'full' and use that file as the new original, before anyone signs it.

A file saved by the viewer when nothing changed is byte-identical to the original and reported as incremental. See Saving.

A signature shows as modified#

Cause. One of four things:

  1. The file was saved as a full rewrite after it was signed, so the signed bytes are gone. The viewer logs a console warning when it does that.
  2. A change was appended that the signature does not allow: any page content change, or annotations after a certification signature of level 1 or 2. modification.changes on the verification result names the kind of each change.
  3. Another tool changed the bytes inside the signed range, for example a mail gateway or a "repair" on upload.
  4. The signature itself is damaged or was made with the wrong key.

Fix. Look at the details instead of the headline:

TypeScript
const [first] = await viewer.verifySignatures();
console.info(first.integrity, first.signature, first.coversWholeFile);
console.info(first.modification.status, first.modification.changes);
console.info(first.chain.status, first.isCertificateValidAtSigning);

integrity: 'modified' means the signed bytes changed (causes 1 and 3). integrity: 'intact' with modification.status: 'disallowed' is cause 2: the original is still inside the file, and saving the signed revision alone (the first byteRange[2] + byteRange[3] bytes) restores it. A chain status of untrusted, self-signed or incomplete is not a modification: add the issuer to trustedCertificates. Revocation is never checked; see Limitations.

Undo history is gone#

Cause. In the viewer, the menu tools (watermark, header and footer, Bates numbering, crop, flatten), the bookmark commands and signing apply their change by saving the document in memory and loading the result. Loading a document starts a new history.

Fix. Keep a copy of the bytes before such a step if users need a way back:

TypeScript
const before = (await viewer.save()).bytes;
// The user adds a watermark from the menu.
await viewer.load(before, { fileName: 'services-agreement-fabrikam-2026.pdf' });

The same tools on a headless PdfDocument are ordinary undo steps.

Hot reloading and framework lifecycles#

Cause. createPdfViewer appends its element to the container. If a module is re-run by hot module replacement, or a framework runs an effect twice (React Strict Mode does in development), a second viewer is added to the same container while the first one still holds its canvases, its open document and its render worker.

Fix. Create the viewer when the element exists and destroy it in the cleanup:

TypeScript
import { createPdfViewer, type PdfViewerApi } from '@birchui/pdf';

let viewer: PdfViewerApi | undefined;

export function mount(container: HTMLElement, bytes: ArrayBuffer): void {
  viewer?.destroy();
  viewer = createPdfViewer(container, { document: bytes });
  viewer.ready.catch(() => undefined);
}

export function unmount(): void {
  viewer?.destroy();
  viewer = undefined;
}

if (import.meta.hot) import.meta.hot.dispose(unmount);

destroy() can be called while a document is still loading; the load is abandoned and nothing more is drawn. Pass new props with viewer.update() instead of recreating the viewer, and change the document with viewer.load().

Server-side rendering#

Cause. Importing @birchui/pdf on the server is safe, and the headless API works there. createPdfViewer needs a DOM element, and the render worker exists in the browser only.

Fix. Create the viewer only in the browser: in useEffect, onMounted, onMount or an equivalent hook, or in a component that is loaded on the client only. If you pass your own worker, pass a function that creates it, so that new Worker runs in the browser and not when the module is evaluated on the server.

A watermark appears#

Cause. Without a valid license key on a host other than localhost, the viewer shows a small watermark and logs one console warning. Every feature keeps working.

Fix. Pass licenseKey. See Licensing.

↑ ↓ to move, Enter to open, Esc to close