Skip to content

PDF Generation Template Editor

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

View on GitHub

UI Customization ​

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:

javascript
const { UI } = instance;

Customization at a glance ​

TaskAPIGuide
Add / remove / reorder toolbar buttonsUI.getModularHeader(id).setItems(items)Header & Toolbar
Change the tools of a toolbar groupUI.getGroupedItems(id).setItems(items)Header & Toolbar
Switch the active toolbar groupUI.setToolbarGroup(group)Header & Toolbar
Add a custom left/right panelUI.addPanel(panel)Panels
Replace all panelsUI.setPanels(panels)Panels
Open / close a panel or dialogUI.openElement / UI.closeElementsShow / Hide Elements
Hide / show buttonsUI.disableElements / UI.enableElementsShow / Hide Elements
Switch themeUI.setTheme('dark')Themes & Styles
Inject custom CSSUI.setCustomStyle(css)Themes & Styles
Switch languageUI.setLanguage('zh-CN')Localization
Add a languageUI.addLanguage({ code, name })Localization
Register a custom modalUI.addCustomModal(options)Custom Modals
Customize context menusUI.annotationPopup, UI.textPopup, …Popups
Activate a toolUI.setToolMode(toolName)Tools
Register a custom toolUI.registerTool(tool)Tools

The element model ​

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:

  • Open / close (openElement, openElements, closeElements, toggleElementVisibility) — whether an element is currently shown (e.g. open the left panel).
  • Enable / disable (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.
  • Active tab (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 model ​

The toolbar is built from modular components:

  • Headers — default-top-header (navigation tools and the ribbon) and tools-header (the tools of the active group).
  • Ribbon group and ribbon items — 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.
  • Grouped items — the tools of each group, such as annotateGroupedItems and formsGroupedItems.
  • Items — CustomButton, ToolButton, ToggleElementButton, StatefulButton, PresetButton, Divider, CustomElement and more, created with instance.UI.Components.

See Header & Toolbar.

The panel model ​

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.

Common recipes ​

Hide the print and download buttons ​

javascript
UI.disableElements(['printButton', 'downloadButton']);

Open the left panel on the thumbnails tab ​

javascript
UI.openElement('tabPanel');
UI.setActiveTabInPanel({ tabPanel: 'tabPanel', tabName: 'thumbnailsPanel' });

Add a custom toolbar button ​

javascript
const header = UI.getModularHeader('default-top-header');
header.setItems([
  ...header.getItems(),
  new UI.Components.CustomButton({
    dataElement: 'my-export-btn',
    label: 'Export',
    onClick: () => { /* … */ },
  }),
]);

Switch to dark theme and Chinese ​

javascript
UI.setTheme('dark');
UI.setLanguage('zh-CN');

Add a custom right-side panel ​

javascript
UI.addPanel({
  dataElement: 'myPanel',
  location: 'right',
  render: () => {
    const el = document.createElement('div');
    el.textContent = 'Hello from my panel';
    return el;
  },
});
UI.openElement('myPanel');

Advanced customization ​

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.

javascript
const data = UI.exportModularComponents();
console.log(Object.keys(data.modularHeaders));

Next steps ​