Skip to content

PDF Generation Template Editor

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

View on GitHub

API Reference ​

This page lists the public API of the WebViewer instance. After ComPDFKitViewer() resolves:

javascript
const { UI, Core } = instance;
  • instance.UI — the UI APIs, constants and component classes below. All methods act on this instance only.
  • instance.Core — the Core namespace plus this viewer's documentViewer and annotationManager (see the last section).

Arguments in [brackets] are optional.

Document ​

APIDescription
UI.loadDocument(src, [options])Load a document (URL, Blob, File, ArrayBuffer, data: URL or Document). Returns a Promise.
UI.closeDocument()Close the document.
UI.downloadPdf([options])Download the document; { flatten: true } downloads a flattened copy.
UI.print() / UI.printInBackground([options]) / UI.cancelPrint()Print.
UI.searchTextFull(text, [options]) / UI.searchText(text, [options])Search and show the results in the search panel.
UI.getPassword()The password entered when the document was opened.
UI.checkPermissionPassword(password)Verify the permission password. Returns Promise<boolean>.

Header & Toolbar ​

UI.getModularHeader(dataElement) → ModularHeader ​

Get a header. Methods: getItems(), setItems(items), getGroupedItems(), setGap(gap), setJustifyContent(value), setMaxWidth(width), setMaxHeight(height), setStyle(style).

UI.setToolbarGroup(group) ​

Switch the active toolbar group, such as 'toolbarGroup-Annotate'.

APIDescription
UI.getModularHeaderList()All headers.
UI.addModularHeaders(headers) / UI.setModularHeaders(headers)Add / replace headers.
UI.getGroupedItems(dataElement)A grouped items component (items, setItems, setGap, setGrow, setJustifyContent, setStyle).
UI.getRibbonGroup(dataElement)The ribbon group (items, setItems).
UI.getActiveRibbonItem() / UI.setActiveRibbonItem(dataElement)The active ribbon item.
UI.setActiveGroupedItems(dataElements)Show grouped items in tools-header.
UI.FlyoutsgetFlyout(dataElement), getAllFlyouts(), addFlyouts(flyouts), removeFlyout(dataElement), setActiveFlyout(dataElement), setFlyoutPosition({ x, y }).
UI.exportModularComponents() / UI.importModularComponents(data, [functionMap])Export / import the modular UI.
UI.ComponentsClasses: ModularHeader, TopHeader, BottomHeader, LeftHeader, RightHeader, GroupedItems, RibbonGroup, RibbonItem, CustomButton, ToolButton, ToolGroupToggleButton, ToggleElementButton, StatefulButton, PresetButton, Divider, CustomElement, Zoom, Label, PageControls, ViewControls, Flyout, MainMenu, TabPanel.

Elements (open / close / enable / disable) ​

APIDescription
UI.openElement(dataElement) / UI.openElements(dataElements)Open elements.
UI.closeElements(dataElements)Close elements.
UI.toggleElementVisibility(dataElement)Toggle an element.
UI.isElementOpen(dataElement)Whether an element is open.
UI.disableElements(dataElements) / UI.enableElements(dataElements)Remove / restore elements.
UI.isElementDisabled(dataElement)Whether an element is disabled.
UI.updateElement(dataElement, overrides)Override properties of a button.
UI.enableFeatures(features) / UI.disableFeatures(features)Turn features on / off (UI.Feature).

Panels ​

UI.addPanel(panel) ​

Add a panel { dataElement, location: 'left' | 'right', render }.

UI.setPanels(panelList) ​

Replace the panel list.

UI.getPanels() → Panel[] ​

The panels. Each panel has dataElement, location, render, setLocation(location), delete() and toObject(); the tab panel also has panelsList.

APIDescription
UI.setActiveTabInPanel({ tabPanel, tabName })Switch the tab of a tab panel.
UI.setActiveLeftPanel(panelName)Switch the tab of the left panel.
UI.setSideWindowVisibility(visible)Open / close the left panel.
UI.setPanelWidth(dataElement, width)Set the width of a panel.

View ​

APIDescription
UI.setZoomLevel(zoom) / UI.getZoomLevel()Zoom (1.5 or '150%').
UI.setMinZoomLevel(zoom) / UI.setMaxZoomLevel(zoom) / UI.setZoomList(list)Zoom range and presets.
UI.setFitMode(mode) / UI.getFitMode()Fit mode (UI.FitMode).
UI.setLayoutMode(mode) / UI.getLayoutMode()Layout mode (UI.LayoutMode).
UI.setScrollMode(mode) / UI.getScrollMode()Scroll direction: 'Vertical' or 'Horizontal' (all pages in one row).
UI.toggleFullScreen() / UI.isFullscreen()Full screen.
UI.getDocumentViewer([documentViewerKey])A document viewer.

Tools ​

APIDescription
UI.setToolMode(toolName, [options])Activate a tool.
UI.getToolMode()The active tool object.
UI.registerTool(tool)Register a tool { toolName, toolObject, buttonImage, buttonName, tooltip }.
UI.updateTool(toolName, properties) / UI.unregisterTool(toolName)Update / remove a registered tool.
UI.disableTools(toolNames) / UI.enableTools(toolNames) / UI.isToolDisabled(toolName)Disable / enable tools.

Themes & Styles ​

APIDescription
UI.setTheme(theme)'light' or 'dark'.
UI.setCustomStyle(cssText)Inject CSS into the UI.
UI.setCustomLoading({ element, styles })Replace the loading indicator.

Localization ​

APIDescription
UI.setLanguage(language)Switch the language. Returns a Promise.
UI.getCurrentLanguage() / UI.getAvailableLanguages()The current language / the available languages.
UI.setTranslations(language, translations)Add or override translations.
UI.getLocalizedText(key)The translation of a key.
UI.addLanguage({ code, name }) / UI.removeLanguage(language) / UI.setLanguages(languages)Edit the language list.

Signatures ​

APIDescription
UI.setSignatureDialogTabs(tabs)Tabs of the signature dialog: 'keyboard', 'trackpad', 'image'.
UI.setSignatureDialogProperties(type, properties, [replace])Colors, fonts and line width of a tab.
UI.setMaxSignaturesCount(count)Maximum saved signatures.
UI.setSignatureFonts(fonts)Fonts of typed signatures.
UI.signSignatureWidget(widget, [signature])Sign a signature field.
UI.VerificationOptions.addTrustedCertificates(certificates)Add trusted certificates for verification. URLs are downloaded again at every verification.

Stamps ​

APIDescription
UI.setStampPanelTabs(tabs)Tabs of the stamp panel.
UI.setImportStamps(images)Images of the import tab.
UI.addCustomStamps(images) / UI.setCustomStamps(images) / UI.getCustomStamps()Custom stamps.

Forms ​

APIDescription
UI.setFormFillNavigatorCollapsed(collapsed)Collapse the form fill navigator.
UI.setFormFillNavigatorPosition({ left, top })Move the form fill navigator.
UI.FormFillThe navigation state of the form fill navigator.

Page Editor ​

APIDescription
UI.enterPageEditorMode() / UI.exitPageEditorMode() / UI.isInPageEditorMode()Open / close the page editor.
UI.savePageEditor()Apply the page editor changes.
UI.enablePageEditorSave() / UI.disablePageEditorSave()Show / hide Save.
UI.enablePageEditorSaveAs() / UI.disablePageEditorSaveAs()Show / hide Save As.

Modals ​

UI.addCustomModal(options) ​

Register a custom modal { dataElement, header, body, footer, render, disableBackdropClick, disableEscapeKeyDown }. Open it with UI.openElement(dataElement).

APIDescription
UI.showWarningMessage({ title, message, confirmBtnText, onConfirm, onCancel })Show a warning dialog.
UI.displayErrorMessage(message)Show an error dialog.

Popups ​

UI.annotationPopup, UI.textPopup, UI.contentEditPopup, UI.snippingToolPopup, UI.contextMenuPopup — each has getItems(), add(items, [dataElement]) and update(items).

User / Author ​

APIDescription
UI.setAuthor(author)The author shown in the settings dialog.
Core.annotationManager.setCurrentUser(name) / getCurrentUser()The author of new annotations.

Fonts ​

UI.Fonts: getAnnotationFonts(), setAnnotationFonts(fonts), addAnnotationFont(font), removeAnnotationFont(font), getSignatureFonts(), setSignatureFonts(fonts), getFontSizes(), setFontSizes(sizes).

Settings ​

APIDescription
UI.exportUserSettings() / UI.importUserSettings(settings)Export / import user settings (language, theme, shortcuts, …).
UI.hotkeysKeyboard shortcuts: on(key, handler), off(key).

Events ​

APIDescription
UI.addEventListener(name, handler, [options]) / UI.removeEventListener(name, handler)UI events (UI.Events).

Lifecycle ​

APIDescription
UI.dispose()Destroy the instance. Returns a Promise.

Constants ​

UI.Events, UI.Feature, UI.ToolbarGroup, UI.Panels, UI.LayoutMode, UI.FitMode, UI.Theme, UI.Languages, UI.PRESET_BUTTON_TYPES, UI.JustifyContent, UI.FeatureFlags.

instance.Core ​

MemberDescription
documentViewerThe main DocumentViewer: pages, zoom, tools, search, events. getDocument() returns the Document.
annotationManagerThe AnnotationManager of documentViewer: annotations, selection, XFDF, permissions.
getDocumentViewers()All document viewers of this WebViewer.
AnnotationsAnnotation classes and Annotations.Color.
ToolsTool classes and Tools.ToolNames.
ActionsAction classes for links and form fields.
Document, createDocument(src, [options])Documents; create one without displaying it.
SaveOptions, PageRotationConstants for saving and rotating pages.
ContentEditContent editing types.
javascript
const { documentViewer, annotationManager, SaveOptions } = instance.Core;
console.log(documentViewer.getPageCount(), annotationManager.getAnnotationsList().length, SaveOptions.INCREMENTAL);