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.
The UI state lives in Pinia stores. Each WebViewer instance creates its own Pinia and its own set of stores, so two viewers on one page never share state.
When an instance is created, three stores are defined on the instance's Pinia, and a few store plugins are installed:
| Store | Holds |
|---|---|
| viewer | UI state: open / disabled elements, the modular components (headers, grouped items, flyouts, panels, popups), the active toolbar group, theme, language, custom modals, stamps, saved signatures, zoom list, and more. |
| document | Mirrors of Core state: loaded documents, page counts, permissions, the current user, search query, outlines, bookmarks, layers, signature verification results. |
| settings | The normalized options passed to ComPDFKitViewer() (without the license key) and feature flags. |
Plugins:
viewer keys to localStorage (or keeps them in memory when storage is not available).instance.UI.Events such as THEME_CHANGED, LANGUAGE_CHANGED, VISIBILITY_CHANGED and TOOLBAR_GROUP_CHANGED when the related state changes.instance.UI interacts with the stores The stores are internal. Integrators read and change UI state through instance.UI:
const { UI } = instance;
UI.openElement('tabPanel'); // viewer store: open elements
console.log(UI.isElementOpen('tabPanel')); // true
UI.setToolbarGroup('toolbarGroup-Annotate'); // viewer store: active toolbar group
UI.setTheme('dark'); // viewer store: theme
UI.addEventListener(UI.Events.VISIBILITY_CHANGED, (element, isVisible) => {
console.log(element, isVisible);
});The document store only mirrors the Core. To change documents or annotations, call the Core (instance.Core.documentViewer, annotationManager); the event listeners update the store.
The viewer store saves these keys: the current language, custom stamps, and saved signatures / initials / digital signatures. They are stored under the key prefix cpdf:<instanceId>:, where instanceId is the instanceId option, or the id of the container element, or default.
User settings such as language, theme and keyboard shortcuts can also be exported and imported:
const settings = instance.UI.exportUserSettings();
console.log(settings.language, settings.theme);
instance.UI.importUserSettings({ theme: 'light' });