Skip to content
ComPDF
New Release

Open-Source PDF SDK & AI Document Processing

Get the full self-hosted SDK and AI document processing on GitHub. One-click deploy to quickly build your document workflows.

Getting Started

This guide covers installing dependencies, running the dev server, building for production, and embedding the WebViewer into your own page.

Prerequisites

  • Node.js 18+
  • pnpm (recommended) or npm
  • A ComPDFKit license key (contact ComPDF for an evaluation license)

Installation

bash
git clone <repository-url>
cd compdfkit-web-sdk
pnpm install

The workspace contains two packages:

PackagePathDescription
@compdfkit/corepackages/coreClosed-source PDF engine; builds into packages/webview/lib/.
@compdfkit/webviewpackages/webviewOpen-source Vue 3 UI layer (the focus of this documentation).

Development

bash
# Dev server on http://localhost:3032 (proxies the core build)
pnpm dev

# Dev with core watch mode (rebuilds the engine on core changes)
pnpm dev:core

The dev server runs at http://localhost:3032. In standalone mode (running the webview app directly, not embedded), loadConfig applies development defaults including a license and renderLayerPermission: true.

Production builds

bash
pnpm build          # Build the webview only (Vite → packages/webview/dist/)
pnpm build:core     # Build the core engine (Rollup → packages/webview/lib/)
pnpm build:webviewer # Build webviewer.js (the iframe embed entry)
pnpm build:release  # Full release: core → webviewer → webview → release/

See Deployment for the full release layout.

Tests & lint

bash
# Unit tests (webview only, Vitest + happy-dom)
pnpm --filter @compdfkit/webview test:unit

# Lint (webview only)
pnpm --filter @compdfkit/webview lint

There is no monorepo-wide test runner. The core package has no test infrastructure beyond individual .test.js files run manually.

Embedding the WebViewer

The integrator-facing entry is webviewer.js (packages/core/webviewer.js), bundled into packages/webview/lib/webviewer.js (ES) and webviewer.global.js (UMD, global name ComPDFKitViewer).

As an ES module

javascript
import ComPDFKitViewer from '@compdfkit/core/webviewer';

ComPDFKitViewer.init(
  {
    path: '/lib',                              // where the webviewer/ folder is served
    pdfUrl: '/files/sample.pdf',               // initial document
    license: 'YOUR_LICENSE_KEY',
    theme: 'light',                            // 'light' | 'dark'
    showToolbarControl: true,
  },
  document.getElementById('viewer')            // host element
).then(instance => {
  const { UI, Core, docViewer } = instance;
  // Ready to use — see the guides.
});

Via a <script> tag (UMD)

html
<div id="viewer"></div>
<script src="/lib/webviewer.global.js"></script>
<script>
  ComPDFKitViewer.init({ path: '/lib', pdfUrl: '/files/sample.pdf' }, document.getElementById('viewer'))
    .then(instance => { /* instance.UI, instance.Core */ });
</script>

How embedding works

  1. ComPDFKitViewer.init(options, element) creates an <iframe> pointing at webviewer/index.html?version=...#d=<initialDoc>&docId=<docId>, optionally appending &css=, &header=, &theme= hash params.
  2. Inside the iframe, the Vite-built webview app boots: main.jsSuspenser.vueApp/index.vue.
  3. App/index.vue awaits i18next, then performs a config handshake with the parent (loadConfig): the iframe posts requestConfig, the parent replies with the integrator's options (and optional config script URL).
  4. The core ComPDFKitViewer is constructed from the bundled lib/webview.min.js and registered as instance 1.
  5. window.instance = { docViewer, Core, UI } is defined inside the iframe.
  6. The iframe posts viewerLoaded to the parent; webviewer.js captures iframe.contentWindow.instance and resolves its init promise with it.

Options reference

OptionPurpose
pathBase URL where the webviewer/ folder is served (trailing / is added).
pdfUrlInitial document URL.
configURL of an optional integrator config script, loaded inside the iframe.
cssURL of a custom stylesheet injected into the iframe.
showToolbarControlboolean → toggles the toolbar via the &header= hash param.
theme'dark' / 'light'.
backgroundColorSets the iframe background color.
assetPathSets the iframe data-assetpath (URI-encoded).
licenseLicense key forwarded to the engine.
Feature flagsisAnnotationPopup, renderLayerPermission, webviewerServer, autoJumpNextSign, disableDigitalSignature, disableElectronicSignature, enableReply, enableDefaultFont, webFontURL, isRenderAnnotations.

The instance object

After initialization, instance exposes three surfaces:

javascript
instance.UI      // UI-layer APIs (setLanguage, setTheme, disableElements, setHeaderItems, …)
instance.Core    // Engine APIs forwarded through the core bridge
instance.docViewer // The underlying ComPDFKitViewer document viewer (instance 1)

instance.UI is the public surface documented across these guides. Head to the UI Customization overview or the API reference to continue.

Next steps