pdfrx_web
    Preparing search index...

    Module @pdfrx/engine

    @pdfrx/engine — a typed client for rendering PDF documents.

    The heavy work runs off the main thread in a dedicated worker (a WASM rendering engine); this package speaks a postMessage command protocol to that worker and exposes an idiomatic, Promise-based object model on top of it. The worker is started the way the host runs workers — a Web Worker in a browser, the platform equivalent on Node, Bun and Deno — so the same package works on a server runtime without extra configuration.

    The primary entry point is PdfrxEngine: construct one with the URL of the directory that hosts the bundled WASM assets (pdfium_worker.js and pdfium.wasm), then open documents with PdfrxEngine.openUrl, PdfrxEngine.openData, PdfrxEngine.createNew, or PdfDocument.createPagesFromImages. Opened documents are represented by PdfDocument, their pages by PdfPage, and rendered bitmaps by PdfImage.

    @pdfrx/engine

    Typed TypeScript access to the PDFium WASM worker used by the pdfrx_web viewer packages. Use it directly for PDF rendering, text and link extraction, forms, annotations, page editing, or PDF encoding without a viewer UI. It supports browsers, Node.js, Bun, and Deno.

    npm package · API reference · Detailed guide

    • Worker-backed PDFium rendering keeps PDF processing off the calling thread.
    • Full-page and partial-region rendering supports high-resolution and tiled viewers, with cancellation before queued work starts.
    • Text extraction includes per-character geometry; links, outlines, forms, and annotations are exposed as typed data.
    • Annotation, form, outline, and page-arrangement edits can be encoded back to PDF, including non-destructive copy encoding.
    • Batched page-content authoring creates or inserts pages containing embedded text, raster images, and vector paths in one worker round trip.
    • Mixed-script FreeText preparation handles grapheme-safe wrapping, CJK language hints, and cross-runtime emoji appearances with configurable asset, renderer, and cache services.
    • HTTP range access can avoid downloading an entire remote PDF up front.
    • The same API runs in browsers, Node.js, Bun, and Deno.
    • Password callbacks, custom font registration, and raw PDF-object inspection cover advanced document workflows.
    npm install @pdfrx/engine
    
    import { PdfrxEngine } from '@pdfrx/engine';

    const engine = new PdfrxEngine({
    wasmModulesUrl: 'https://cdn.jsdelivr.net/npm/@pdfrx/engine@0.27.0/assets/',
    });
    const document = await engine.openUrl('/manual.pdf');
    const page = document.pages[0];

    if (page) {
    const image = await page.render({
    fullWidth: page.width * 2,
    fullHeight: page.height * 2,
    });
    if (image) canvasContext.putImageData(image.toImageData(), 0, 0);
    }

    await document.dispose();
    engine.dispose();

    In browsers, wasmModulesUrl must point to a directory containing pdfium_worker.js and pdfium.wasm. Copy both from node_modules/@pdfrx/engine/assets/ or serve the versioned CDN directory shown above. Non-browser runtimes discover the installed assets automatically.

    PdfrxEngine owns the worker and opens PdfDocument instances:

    • openUrl() opens a remote PDF, optionally using HTTP range access and a password callback.
    • openData() opens bytes supplied as an ArrayBuffer, typed array, or compatible binary source.

    The same PdfrxEngine creates new PdfDocument instances, then creates and arranges their pages:

    Documents expose their current page arrangement through PdfDocument.pages. Each PdfPage provides:

    At document scope, loadOutline() reads bookmarks and loadFormFields() reads AcroForm controls and their values.

    Document mutation events report page, annotation, and form changes with origin, transaction, and actor metadata, allowing applications to build persistence, history, or synchronization without polling.

    Server runtimes can explicitly opt into local filesystem fonts:

    const engine = new PdfrxEngine({
    localFonts: {
    systemDirectories: true,
    directories: ['./fonts'],
    },
    fontCache: {
    directory: './.cache/pdfrx-fonts',
    persistRegisteredFonts: true,
    },
    });

    PdfrxLocalFontsOptions controls OS and application font directories. The engine indexes internal font names and lazily loads missing faces. PdfrxFontCacheOptions caches that index and can optionally persist bytes passed to addFontData(). Persisting font bytes is disabled by default so the application can enforce its font licenses and data-handling policy. Deno requires matching filesystem permissions.

    encodePdf() returns PDF bytes. Its copy mode materializes a temporary document so the live document and page proxies remain usable; compact mode rebuilds reachable page-level content with lower retention of document-level structures. The default live-document materialization is an explicit state boundary, so consult the guide before combining it with application Undo/Redo.

    Dispose every document with PdfDocument.dispose() and dispose the engine when finished. In Node.js, the engine worker otherwise keeps the process alive.

    MIT

    PdfErrorCode
    PdfDocument
    PdfImage
    PdfIndexedDbTextAssetCache
    PdfMemoryTextAssetCache
    PdfPage
    PdfPageRenderCancellationToken
    PdfPasswordException
    PdfPermissions
    PdfrxEngine
    FormCalcSpec
    PdfAnnotation
    PdfAnnotationColor
    PdfAnnotationHistoryChange
    PdfAnnotationMutationOptions
    PdfAnnotationObject
    PdfAnnotationPoint
    PdfAnnotationQuad
    PdfAnnotationSnapshot
    PdfAnnotationSpec
    PdfCreatePagesFromImagesOptions
    PdfDefaultEmojiRendererOptions
    PdfDestById
    PdfDestByPageNumber
    PdfDestOptions
    PdfDocumentEventMap
    PdfEmojiAssetSource
    PdfEmojiImage
    PdfEmojiRun
    PdfEncodeOptions
    PdfFontQuery
    PdfFormField
    PdfFormFieldChange
    PdfFormFieldFlags
    PdfFormFieldOption
    PdfFormMutationOptions
    PdfFreeTextAppearanceOptions
    PdfHighlightObject
    PdfImageContent
    PdfLoadAnnotationsOptions
    PdfLoadHighlightsOptions
    PdfMaterializedCopyOptions
    PdfNotoEmojiSourceOptions
    PdfOpenDataOptions
    PdfOpenOptions
    PdfOpenUrlOptions
    PdfOutlineNode
    PdfPageArrangementEntry
    PdfPageContentSpec
    PdfPageMutationOptions
    PdfPageRawText
    PdfPageRenderOptions
    PdfPathContent
    PdfRawCreatedObject
    PdfRawImage
    PdfRawObjectEditOptions
    PdfRawObjectEditor
    PdfRawTarget
    PdfRect
    PdfResolvedDest
    PdfRestoreAnnotationsOptions
    PdfrxEngineOptions
    PdfrxFontCacheOptions
    PdfrxLocalFontsOptions
    PdfStoredAnnotation
    PdfTextAppearanceServices
    PdfTextAssetCache
    PdfTextContent
    PdfTextOrientation
    PdfTextRun
    PdfWorkerLike
    PdfWorkerUrls
    FormCalcOp
    PdfAnnotationChange
    PdfAnnotationChangeOrigin
    PdfAnnotationGeometry
    PdfAnnotationRenderingMode
    PdfAnnotationSubtype
    PdfColor
    PdfDest
    PdfDocumentEventName
    PdfDownloadProgressCallback
    PdfEmojiRenderer
    PdfEncodeMode
    PdfFontCharsetId
    PdfFormChangeOrigin
    PdfFormFieldType
    PdfFormFieldValue
    PdfFreeTextFontResolver
    PdfImageDecoder
    PdfImageDecoderResult
    PdfImageSource
    PdfLinkTarget
    PdfMaterializedCopyCatalog
    PdfMatrix
    PdfPageChangeOrigin
    PdfPageContentObject
    PdfPageId
    PdfPageImageSource
    PdfPageRotation
    PdfPasswordProvider
    PdfPathSegment
    PdfPixelFormat
    PdfRawObject
    PdfRawPatchOperation
    PdfRawPatchValue
    PdfTextMeasureProvider
    PdfTextOrientationBehavior
    defaultNotoEmojiPngBaseUrl
    PdfAnnotationFlag
    PdfFontCharset
    PdfFontPitchFamily
    PdfRect
    annotationRenderingModeToIndex
    canDecodeImages
    createCanvasTextMeasureProvider
    createDefaultEmojiRenderer
    createNotoEmojiPngSource
    decodeFormFieldFlags
    decodeRgbaPng
    deserializeAnnotationSnapshot
    evaluateCalc
    isFixedPitch
    isJpeg
    isRomanFamily
    isScriptFamily
    parseCalcAction
    parseFieldNumber
    pdfAnnotationSubtypeFromName
    pdfFontCharsetName
    pdfFormFieldTypeFromCode
    pdfPageRotationFromIndex
    pdfPageRotationToIndex
    prepareFreeTextAppearance
    readJpegSize
    serializeAnnotationSnapshot