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.
This page lists the public API of the WebViewer instance. After ComPDFKitViewer() resolves:
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.
| API | Description |
|---|---|
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>. |
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'.
| API | Description |
|---|---|
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.Flyouts | getFlyout(dataElement), getAllFlyouts(), addFlyouts(flyouts), removeFlyout(dataElement), setActiveFlyout(dataElement), setFlyoutPosition({ x, y }). |
UI.exportModularComponents() / UI.importModularComponents(data, [functionMap]) | Export / import the modular UI. |
UI.Components | Classes: ModularHeader, TopHeader, BottomHeader, LeftHeader, RightHeader, GroupedItems, RibbonGroup, RibbonItem, CustomButton, ToolButton, ToolGroupToggleButton, ToggleElementButton, StatefulButton, PresetButton, Divider, CustomElement, Zoom, Label, PageControls, ViewControls, Flyout, MainMenu, TabPanel. |
| API | Description |
|---|---|
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). |
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.
| API | Description |
|---|---|
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. |
| API | Description |
|---|---|
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. |
| API | Description |
|---|---|
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. |
| API | Description |
|---|---|
UI.setTheme(theme) | 'light' or 'dark'. |
UI.setCustomStyle(cssText) | Inject CSS into the UI. |
UI.setCustomLoading({ element, styles }) | Replace the loading indicator. |
| API | Description |
|---|---|
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. |
| API | Description |
|---|---|
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. |
| API | Description |
|---|---|
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. |
| API | Description |
|---|---|
UI.setFormFillNavigatorCollapsed(collapsed) | Collapse the form fill navigator. |
UI.setFormFillNavigatorPosition({ left, top }) | Move the form fill navigator. |
UI.FormFill | The navigation state of the form fill navigator. |
| API | Description |
|---|---|
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. |
UI.addCustomModal(options) Register a custom modal { dataElement, header, body, footer, render, disableBackdropClick, disableEscapeKeyDown }. Open it with UI.openElement(dataElement).
| API | Description |
|---|---|
UI.showWarningMessage({ title, message, confirmBtnText, onConfirm, onCancel }) | Show a warning dialog. |
UI.displayErrorMessage(message) | Show an error dialog. |
UI.annotationPopup, UI.textPopup, UI.contentEditPopup, UI.snippingToolPopup, UI.contextMenuPopup — each has getItems(), add(items, [dataElement]) and update(items).
| API | Description |
|---|---|
UI.setAuthor(author) | The author shown in the settings dialog. |
Core.annotationManager.setCurrentUser(name) / getCurrentUser() | The author of new annotations. |
UI.Fonts: getAnnotationFonts(), setAnnotationFonts(fonts), addAnnotationFont(font), removeAnnotationFont(font), getSignatureFonts(), setSignatureFonts(fonts), getFontSizes(), setFontSizes(sizes).
| API | Description |
|---|---|
UI.exportUserSettings() / UI.importUserSettings(settings) | Export / import user settings (language, theme, shortcuts, …). |
UI.hotkeys | Keyboard shortcuts: on(key, handler), off(key). |
| API | Description |
|---|---|
UI.addEventListener(name, handler, [options]) / UI.removeEventListener(name, handler) | UI events (UI.Events). |
| API | Description |
|---|---|
UI.dispose() | Destroy the instance. Returns a Promise. |
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 | Member | Description |
|---|---|
documentViewer | The main DocumentViewer: pages, zoom, tools, search, events. getDocument() returns the Document. |
annotationManager | The AnnotationManager of documentViewer: annotations, selection, XFDF, permissions. |
getDocumentViewers() | All document viewers of this WebViewer. |
Annotations | Annotation classes and Annotations.Color. |
Tools | Tool classes and Tools.ToolNames. |
Actions | Action classes for links and form fields. |
Document, createDocument(src, [options]) | Documents; create one without displaying it. |
SaveOptions, PageRotation | Constants for saving and rotating pages. |
ContentEdit | Content editing types. |
const { documentViewer, annotationManager, SaveOptions } = instance.Core;
console.log(documentViewer.getPageCount(), annotationManager.getAnnotationsList().length, SaveOptions.INCREMENTAL);