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 ComPDFKit WebViewer UI is fully customizable. This page is the hub for the most common customization tasks. Each linked guide goes deeper with API signatures and examples.
The public customization surface lives on instance.UI after the viewer initializes:
const { UI } = instance;| Task | API | Guide |
|---|---|---|
| Add / remove / reorder toolbar buttons | UI.getModularHeader(id).setItems(items) | Header & Toolbar |
| Change the tools of a toolbar group | UI.getGroupedItems(id).setItems(items) | Header & Toolbar |
| Switch the active toolbar group | UI.setToolbarGroup(group) | Header & Toolbar |
| Add a custom left/right panel | UI.addPanel(panel) | Panels |
| Replace all panels | UI.setPanels(panels) | Panels |
| Open / close a panel or dialog | UI.openElement / UI.closeElements | Show / Hide Elements |
| Hide / show buttons | UI.disableElements / UI.enableElements | Show / Hide Elements |
| Switch theme | UI.setTheme('dark') | Themes & Styles |
| Inject custom CSS | UI.setCustomStyle(css) | Themes & Styles |
| Switch language | UI.setLanguage('zh-CN') | Localization |
| Add a language | UI.addLanguage({ code, name }) | Localization |
| Register a custom modal | UI.addCustomModal(options) | Custom Modals |
| Customize context menus | UI.annotationPopup, UI.textPopup, … | Popups |
| Activate a tool | UI.setToolMode(toolName) | Tools |
| Register a custom tool | UI.registerTool(tool) | Tools |
Almost every visible piece of the UI — panels, dialogs, toolbar buttons — is identified by a data-element string. The UI state keeps which elements are open and which are disabled.
Three families of APIs control visibility:
openElement, openElements, closeElements, toggleElementVisibility) — whether an element is currently shown (e.g. open the left panel).enableElements, disableElements) — whether the element is rendered at all. Disabling a toolbar button removes it; it does not disable the underlying feature. Use enableFeatures / disableFeatures for features.setActiveTabInPanel) — switches the active tab inside a tab panel (e.g. which left-panel tab is shown).See Show / Hide Elements for details.
The toolbar is built from modular components:
default-top-header (navigation tools and the ribbon) and tools-header (the tools of the active group).default-ribbon-group holds one ribbon item per toolbar group: toolbarGroup-View, toolbarGroup-Annotate, toolbarGroup-Forms, toolbarGroup-Measure, toolbarGroup-FillAndSign, toolbarGroup-Security, toolbarGroup-Redact, toolbarGroup-Compare, toolbarGroup-EditText, toolbarGroup-Document and toolbarGroup-Separation.annotateGroupedItems and formsGroupedItems.CustomButton, ToolButton, ToggleElementButton, StatefulButton, PresetButton, Divider, CustomElement and more, created with instance.UI.Components.See Header & Toolbar.
Panels are declared in a panel list. The default list contains the left tab panel tabPanel (thumbnails, outlines, notes, layers, signatures, search) and the right panels stylePanel, pageModePanel, formFieldPanel, rubberStampPanel, linkPanel, textEditingPanel, colorSeparationPanel and redactionStylePanel. Custom panels added with UI.addPanel use a render function that returns an HTMLElement.
See Panels.
UI.disableElements(['printButton', 'downloadButton']);UI.openElement('tabPanel');
UI.setActiveTabInPanel({ tabPanel: 'tabPanel', tabName: 'thumbnailsPanel' });const header = UI.getModularHeader('default-top-header');
header.setItems([
...header.getItems(),
new UI.Components.CustomButton({
dataElement: 'my-export-btn',
label: 'Export',
onClick: () => { /* … */ },
}),
]);UI.setTheme('dark');
UI.setLanguage('zh-CN');UI.addPanel({
dataElement: 'myPanel',
location: 'right',
render: () => {
const el = document.createElement('div');
el.textContent = 'Hello from my panel';
return el;
},
});
UI.openElement('myPanel');The whole modular UI can be exported and imported as data. UI.exportModularComponents() returns the headers, components, panels, flyouts and popups; edit the result and pass it to UI.importModularComponents(data, functionMap). Functions such as onClick are referenced by name and supplied in functionMap; when the exported UI contains a function that is not in a function map, exportModularComponents prints a warning that shows the entry to add.
const data = UI.exportModularComponents();
console.log(Object.keys(data.modularHeaders));