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 header and the toolbar are built from modular components. This guide explains their structure and the APIs that change them.
UI.getModularHeader(dataElement) Returns the header object. Its items can be read with getItems() and replaced with setItems(items).
/**
* @method UI.getModularHeader
* @param {string} dataElement The header, such as 'default-top-header' or 'tools-header'.
* @returns {UI.Components.ModularHeader}
*/
const header = UI.getModularHeader('default-top-header');
console.log(header.getItems().map(item => item.dataElement));The header object also provides getGroupedItems(), setGap(gap), setJustifyContent(value), setMaxWidth(width), setMaxHeight(height) and setStyle(style). UI.getModularHeaderList() returns all headers.
| API | Purpose |
|---|---|
UI.getModularHeader(id) / UI.getModularHeaderList() | Get one / all headers. |
UI.addModularHeaders(headers) | Add headers created with UI.Components.ModularHeader (or TopHeader, BottomHeader, LeftHeader, RightHeader). |
UI.setModularHeaders(headers) | Replace all headers. |
UI.getGroupedItems(id) | Get a grouped items component; change it with setItems(items). |
UI.getRibbonGroup(id) | Get the ribbon group; change it with setItems(items). |
UI.exportModularComponents() / UI.importModularComponents(data, functionMap) | Export / import the whole modular UI as data. |
UI.setToolbarGroup(group) Switch the active toolbar group (the ribbon item that is selected, and the tools shown in tools-header).
/**
* @method UI.setToolbarGroup
* @param {string} group A value of UI.ToolbarGroup, such as 'toolbarGroup-Annotate'.
*/
UI.setToolbarGroup('toolbarGroup-Annotate');Valid groups: toolbarGroup-View, toolbarGroup-Annotate, toolbarGroup-Forms, toolbarGroup-Measure, toolbarGroup-FillAndSign, toolbarGroup-Security, toolbarGroup-Redact, toolbarGroup-Compare, toolbarGroup-EditText, toolbarGroup-Document, toolbarGroup-Separation, plus the custom groups toolbarGroup-Shapes, toolbarGroup-Insert and toolbarGroup-Edit. UI.Events.TOOLBAR_GROUP_CHANGED fires when the group changes.
| Header | Contents |
|---|---|
default-top-header | leftPanelButton, fullscreenButton, selectToolsButton, panToolButton, zoom-container, snippingToolButton, textSelectToolButton, the ribbon group default-ribbon-group, searchPanelToggle, and menuButton (opens the MainMenuFlyout). |
tools-header | The grouped items of the active toolbar group. |
page-editor-header | The header shown in the page editor (cancel, save, save as). |
compare-header | The header shown in document comparison. |
Each ribbon item in default-ribbon-group names a toolbar group and the grouped items it shows:
| Ribbon item | Grouped items |
|---|---|
toolbarGroup-View | — |
toolbarGroup-Annotate | annotateGroupedItems |
toolbarGroup-Forms | formsGroupedItems |
toolbarGroup-Measure | measureGroupedItems |
toolbarGroup-FillAndSign | fillAndSignGroupedItems |
toolbarGroup-Security | securityGroupedItems |
toolbarGroup-Redact | redactionGroupedItems |
toolbarGroup-Compare | — |
toolbarGroup-EditText | editTextGroupedItems |
toolbarGroup-Document | — |
toolbarGroup-Separation | — |
When the ribbon does not fit, the items that do not fit are collected into a "···" menu.
Items are created with the classes in instance.UI.Components:
| Class | type | Renders as |
|---|---|---|
CustomButton | customButton | A button that runs onClick. |
ToolButton | toolButton | A button that activates the tool toolName. |
ToggleElementButton | toggleButton | A button that opens/closes toggleElement. |
StatefulButton | statefulButton | A button with several states. |
PresetButton | presetButton | A built-in button (UI.PRESET_BUTTON_TYPES), such as downloadButton or printButton. |
GroupedItems | groupedItems | A group of items. |
RibbonGroup / RibbonItem | ribbonGroup / ribbonItem | The toolbar group switcher and its items. |
Flyout / MainMenu | flyout | A drop-down menu. |
Zoom, PageControls, ViewControls, Label | zoom, pageControls, viewControls, label | Built-in widgets and a text label. |
CustomElement | customElement | Any element returned by render(). |
Divider | divider | A vertical separator. |
Every item accepts hidden: true hides it, and an array of screen sizes (desktop, tablet, mobile, small-mobile) hides it only on those sizes. An empty GroupedItems with grow: 1 works as a spacer that pushes the following items to the other side.
See Customize the Navigation Bar for the properties of each item.
setItems works internally Headers, grouped items, ribbon groups and their items are stored as plain data in the viewer store, keyed by dataElement. setItems(items) stores each item under its dataElement (replacing an item with the same dataElement) and writes the list of dataElement values back to the header or group. The header components re-render from the store. Grouped items are rendered only when they are active, or when alwaysVisible is true.
const header = UI.getModularHeader('default-top-header');
header.setItems(header.getItems().filter(item => item.dataElement !== 'snippingToolButton'));const header = UI.getModularHeader('default-top-header');
const items = header.getItems();
const index = items.findIndex(item => item.dataElement === 'searchPanelToggle');
items.splice(index, 0, new UI.Components.CustomButton({
dataElement: 'myAction',
label: 'My Action',
onClick: () => console.log('clicked'),
}));
header.setItems(items);const { Components } = UI;
UI.getGroupedItems('annotateGroupedItems').setItems([
new Components.ToolButton({ dataElement: 'highlightToolButton', toolName: 'AnnotationCreateTextHighlight' }),
new Components.ToolButton({ dataElement: 'rectangleToolButton', toolName: 'AnnotationCreateRectangle' }),
]);const { Components } = UI;
const myTools = new Components.GroupedItems({
dataElement: 'myGroupedItems',
items: [
new Components.ToolButton({ dataElement: 'myRectangleButton', toolName: 'AnnotationCreateRectangle', img: 'RectangleTool' }),
],
});
const toolsHeader = UI.getModularHeader('tools-header');
toolsHeader.setItems([...toolsHeader.getItems(), myTools]);
const ribbonGroup = UI.getRibbonGroup('default-ribbon-group');
ribbonGroup.setItems([
...ribbonGroup.items,
new Components.RibbonItem({
dataElement: 'toolbarGroup-Shapes',
label: 'Shapes',
toolbarGroup: 'toolbarGroup-Shapes',
groupedItems: ['myGroupedItems'],
}),
]);
UI.setToolbarGroup('toolbarGroup-Shapes');const mainMenu = UI.Flyouts.getFlyout('MainMenuFlyout');
mainMenu.setItems([
...mainMenu.items,
{ dataElement: 'aboutButton', label: 'About', onClick: () => alert('ComPDFKit WebViewer') },
]);disableElements to hide buttons without restructuring the toolbar.