Skip to content

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub

Architecture ​

ComPDFKit Web SDK is organized in clear layers. Understanding the boundaries between these layers is essential for customizing the UI and extending the SDK.

The layers ​

Integrator's page
  └─ webviewer.js / webviewer.global.js   (bootstrap, no Vue and no Core inside)
       └─ <iframe src="{path}webviewer/index.html">   (WebViewer UI)
            └─ instance assembly (src/instance/)
                 ├─ apis/          → instance.UI
                 ├─ stores/        Pinia: viewer / document / settings (one set per instance)
                 ├─ components/    Vue views (modular headers, panels, popups, modals …)
                 ├─ event-listeners/ + helpers/   Core events → store updates
                 └─ core/          thin wrappers over @compdfkit/core
                      └─ @compdfkit/core  (DocumentViewer, AnnotationManager, Document …)
                           └─ Web Worker (PDFWorker.js) + WASM (ComPDFKit.wasm)
LayerLocationRoleOpen source?
Bootstrapwebviewer.js (ES module) / webviewer.global.js (UMD)Creates the iframe, passes the options, resolves with instance.Yes
UIwebviewer/Vue 3 + Pinia application; owns all UI state.Yes
Core@compdfkit/core, bundled in the UIDocument rendering, annotations, forms, content editing, measurement.No
Enginewebviewer/lib/Web Worker and WASM.No

1. Bootstrap — ComPDFKitViewer(options, element) ​

The bootstrap script is small and does not contain the UI or Core. It validates the options, creates an <iframe> that loads {path}webviewer/index.html, passes the options to the UI, and resolves with the instance object when the UI is ready. See Getting Started.

2. UI — webviewer/ ​

A Vue 3 + Pinia application. It owns all UI state (which panels are open, the active toolbar group, theme, language, the modular components) and renders the entire interface. Everything that belongs to one viewer — stores, i18n, hotkeys, event bindings, saved settings — is created per instance.

Subsystems:

  • src/apis/ — the public API surface assembled onto instance.UI.
  • src/core/ — thin wrappers over @compdfkit/core that every API and component goes through.
  • src/components/ — the Vue components.
  • src/stores/ — Pinia stores (viewer, document, settings).
  • src/event-listeners/, src/helpers/, src/composables/, src/constants/.

3. Core — @compdfkit/core ​

The object model of the SDK: DocumentViewer, Document, AnnotationManager, Annotations, Tools, ContentEditManager and more. It is exposed to integrators as instance.Core. See Core Bridge.

4. Engine — Worker and WASM ​

The Core talks to a Web Worker (PDFWorker.js) that runs the WASM engine (ComPDFKit.wasm). The files are loaded from workerPath (default {path}webviewer/lib/).

Bootstrap flow ​

1. Integrator: ComPDFKitViewer(options, element)
2. Bootstrap: check options and browser → create <iframe src="{uiPath}index.html?version=…#docId=…[&css=…&header=…&theme=…&lang=…]">
3. iframe: read the options from the host page → create the instance
     stores (viewer / document / settings) + i18n + hotkeys
     Core: set worker path, license, fonts → DocumentViewer
     assemble instance = { Core, UI } → window.instance
4. iframe: run the config script (if options.config is set)
5. iframe: mount the Vue app → fire UI.Events.VIEWER_LOADED
6. Bootstrap: resolve the promise with instance
7. iframe: load options.initialDoc → documentViewer fires 'documentLoaded'

The instance object ​

text
instance = {
  Core: {
    ...CoreNamespace,       // Annotations, Tools, Actions, Document, SaveOptions, PageRotation, createDocument, …
    documentViewer,         // the main DocumentViewer of this viewer
    annotationManager,      // documentViewer.getAnnotationManager()
    getDocumentViewers,     // () => DocumentViewer[]
  },
  UI: {
    // every API in src/apis/, bound to this instance
    // constants: Events, Feature, ToolbarGroup, LayoutMode, FitMode, Theme, Panels, Languages, …
    // Components: classes for modular components
    dispose,                // destroy the instance
  },
};

Both objects are frozen. After UI.dispose(), calls to instance.UI methods only print a warning.

Multiple viewers ​

  • Several WebViewers on one page. Call ComPDFKitViewer() once per container element. Each call creates its own iframe and instance; nothing is shared. Use instanceId (or a distinct element id) so their saved settings do not mix.
  • Several document viewers in one WebViewer. The document comparison feature uses additional DocumentViewer objects. instance.Core.getDocumentViewers() returns all of them; instance.Core.documentViewer is always the main one (key 1). APIs such as UI.getDocumentViewer(documentViewerKey) and UI.setActiveDocumentViewerKey(key) work with the other viewers.

Key design patterns ​

  • One-way dependency rule: apis/ → core/ → @compdfkit/core. Components and APIs reach the Core only through src/core/.
  • Per-instance state: every API is created as (ctx) => (...args) => result, so it only reads and writes the stores of its own instance.
  • Stores mirror the Core: the Core is the source of truth for documents and annotations. event-listeners/ copy Core events into the stores, and components render from the stores.
  • Modular UI: headers, grouped items, buttons, panels and flyouts are plain data in the viewer store. instance.UI.Components and the modular APIs read and write that data.

Where to go next ​