Skip to content

PDF Generation Template Editor

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

View on GitHub

Popups ​

Popups are small floating menus. Each popup is an object on instance.UI with the same interface.

The popup interface ​

MethodDescription
getItems()Returns a copy of the items. Each item has a dataElement.
add(items, dataElement?)Insert one item or an array of items after the item dataElement; without it (or when it is not found) the items are inserted at the beginning. Returns the popup.
update(items)Replace all items. Returns the popup.

Built-in items only need their dataElement. Custom items need a type and a dataElement:

typeItem
customButtonA button with img, label, title and onClick.
statefulButtonA button with several states (see Header & Toolbar).
toggleButtonA button that opens/closes toggleElement.
toolButtonA button that activates toolName.
dividerA separator.

The popups ​

UI.textPopup ​

Appears after text is selected.

Default items: copyTextButton, textHighlightToolButton, textUnderlineToolButton, textStrikeoutToolButton, textSquigglyToolButton.

UI.annotationPopup ​

Appears after an annotation is selected.

Default items: annotationReplyButton, annotationCopyButton, measureSettingsButton, annotationStyleEditButton, annotationDeleteButton. Items that do not apply to the selected annotation are not shown.

UI.contentEditPopup ​

Appears after a content block is selected in content editing.

Default items: contentEditCopyButton, contentEditPropertyButton, contentEditDeleteButton.

UI.snippingToolPopup ​

Appears after an area is selected with the snipping tool.

Default items: snippingDownloadButton, snippingExitButton.

UI.contextMenuPopup ​

The right-click menu. It has no default items and is not shown by the default UI; its items can still be read and written.

Positioning ​

A popup is placed next to its target (the selected text, annotation, content block or area) and is moved inside the visible area of the document. It closes when the selection is cleared.

Examples ​

Add a custom action to the annotation popup ​

javascript
UI.annotationPopup.add({
  type: 'customButton',
  dataElement: 'logAnnotationButton',
  label: 'Log',
  onClick: () => {
    const [annotation] = instance.Core.annotationManager.getSelectedAnnotations();
    console.log(annotation);
  },
}, 'annotationCopyButton');

Replace the text-popup actions ​

javascript
UI.textPopup.update([
  { dataElement: 'copyTextButton' },
  { type: 'divider', dataElement: 'textPopupDivider' },
  {
    type: 'customButton',
    dataElement: 'logTextButton',
    label: 'Log',
    onClick: () => console.log(instance.Core.documentViewer.getSelectedText()),
  },
]);

Remove an item ​

javascript
UI.annotationPopup.update(
  UI.annotationPopup.getItems().filter(item => item.dataElement !== 'annotationCopyButton'),
);
// or hide it
UI.disableElements(['annotationCopyButton']);