Skip to content
ComPDF
New Release

Open-Source PDF SDK & AI Document Processing

Get the full self-hosted SDK and AI document processing on GitHub. One-click deploy to quickly build your document workflows.

Popups

Popups are the floating context menus that appear over annotations, text selections, the content editor, and the crop-page tool. The WebViewer exposes four popup properties, each implementing the UI.Popup interface so you can read, add, and replace their action items.

The UI.Popup interface

All four popup properties are built by api_helpers/createPopupAPI.js. Each implements:

MethodSignaturePurpose
add(items, dataElement?)(items: Array|object, dataElement?: string) => thisInsert items after the item with the given dataElement (or at the beginning if omitted). Non-arrays are wrapped.
update(items?)(items?: Array|object) => thisReplace all popup items (clears if undefined).
getItems()() => Array<object>Return the current popup items.

To remove items, use UI.disableElements with the item's dataElement.

The four popups

UI.textPopup

Popup for the text-selection context menu.

javascript
/**
 * @name UI.textPopup
 * @implements {UI.Popup}
 * @type {UI.Popup}
 */
UI.textPopup.getItems();        // => [{ type, dataElement, ... }, ...]

Default actions: copy, highlight, underline, strikeout, squiggly.

UI.annotationPopup

Popup for selected annotations.

javascript
/**
 * @name UI.annotationPopup
 * @implements {UI.Popup}
 * @type {UI.Popup}
 */

Default actions vary by annotation type: reply, copy, property, settings, delete. Link and erasure-redaction annotations show delete only; redaction shows property + delete; form fields show property/copy/delete.

UI.contentEditorPopup

Popup for the content editor.

javascript
/**
 * @name UI.contentEditorPopup
 * @implements {UI.Popup}
 * @type {UI.Popup}
 */

Default actions: copy, delete, property.

UI.cropPagePopup

Popup for the crop-page component.

javascript
/**
 * @name UI.cropPagePopup
 * @implements {UI.Popup}
 * @type {UI.Popup}
 */

Default actions: crop, close/exit.

Item structure

Popup items share the same descriptor shape as toolbar items — type (actionButton, statefulButton, toggleElementButton, toolButton), dataElement, icon, label, and onClick. The popup components (components/Popups/) render items via CustomButton and typed Button branches, filtering out items whose dataElement is disabled.

Positioning

Popup position is computed by helpers/getPopupPosition.jsgetAnnotationPopupPositionBasedOn(rect, pageNumber, popup, documentViewerKey=1, position='right') returns { left, top }. It converts page-space annotation corners to window coordinates via core.pageToWindow, then clamps the popup within the scroll container's viewport (preferring below the annotation, falling back to above or to the side with more space).

Examples

Add a custom action to the annotation popup

javascript
UI.annotationPopup.add({
  type: 'actionButton',
  dataElement: 'myAnnotAction',
  label: 'Send to backend',
  onClick: () => { /* … */ },
});

Replace the text-popup actions

javascript
UI.textPopup.update([
  { type: 'actionButton', dataElement: 'copyTextButton',  label: 'Copy' },
  { type: 'toolButton',   dataElement: 'highlightToolButton', label: 'Highlight' },
]);

Remove an item

javascript
UI.disableElements(['replyButton']);   // removes the reply action from the annotation popup

Internal notes

  • Popup item arrays live in the viewer store (textPopup[], annotationPopup[], contentEditorPopup[], cropPagePopup[]) and are accessed through the encapsulated viewerStore.dispatch('getPopupItems')(popupDataElement).
  • The popup components read items via useViewer.getPopupItems(<key>) and filter by isElementDisabled.
  • showAnnotationPopup / popoverChanged flags in the store control popup visibility timing.