PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
ComPDFKit Web SDK is organized in clear layers. Understanding the boundaries between these layers is essential for customizing the UI and extending the SDK.
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)| Layer | Location | Role | Open source? |
|---|---|---|---|
| Bootstrap | webviewer.js (ES module) / webviewer.global.js (UMD) | Creates the iframe, passes the options, resolves with instance. | Yes |
| UI | webviewer/ | Vue 3 + Pinia application; owns all UI state. | Yes |
| Core | @compdfkit/core, bundled in the UI | Document rendering, annotations, forms, content editing, measurement. | No |
| Engine | webviewer/lib/ | Web Worker and WASM. | No |
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.
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/.@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.
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/).
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'instance object 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.
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.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.apis/ → core/ → @compdfkit/core. Components and APIs reach the Core only through src/core/.(ctx) => (...args) => result, so it only reads and writes the stores of its own instance.event-listeners/ copy Core events into the stores, and components render from the stores.viewer store. instance.UI.Components and the modular APIs read and write that data.instance.Core in depth.