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 core bridge (packages/webview/src/core/) is the stateless facade between the Vue webview UI and the ComPDFKit Core engine. It hides the monolithic ComPDFKitViewer class behind ~120 thin functions and is the only layer permitted to call the engine.
documentViewers Map (the multi-instance registry).docNum is always the last parameter when present, forwarded to getDocumentViewer(docNum).getDocumentViewer(docNum).<engineMethod>(args...). Light argument destructuring is the only transformation.apis/ → core/ → engine. The bridge never touches Pinia stores or the DOM.documentViewers.js The only stateful file (24 lines):
import ComPDFKitViewer from '../../lib/webview.min.js'
const documentViewerMap = new Map();
export const setDocumentViewer = (number, documentViewer, options) => {
if (documentViewer) {
documentViewerMap.set(number, documentViewer); // pre-built viewer
} else {
const viewer = new ComPDFKitViewer(options); // or construct here
documentViewerMap.set(number, viewer);
}
};
export const deleteDocumentViewer = (number) => { documentViewerMap.delete(number); };
export const getDocumentViewer = (number = 1) => documentViewerMap.get(number);
export const getDocumentViewers = () => Array.from(documentViewerMap.values());getDocumentViewer() resolves to instance 1 (the primary document).options.helpers/initDocument.js registers instance 1; CompareDocumentContainer.vue registers instances 2 and 3 (the compare old/new file viewers).docNum through; the rest are hardwired to instance 1.core/index.js re-exports ~120 bridge functions. By domain:
getDocumentViewer, setDocumentViewer, getDocumentViewers, deleteDocumentViewer, init, initConfig, initializeViewer.
loadDocument, getPagesCount, getCurrentPage, getDocumentName, setDocumentName, getOutlines, getOptionUrl, download, getDocEditorPages, saveDocumentEdit, compare.
nextPage, previousPage, pageNumberChanged, rotateClockwise, rotateCounterclockwise, zoomIn, zoomOut, scaleChanged, getScale, getScrollViewElement, getSelectedPage, pageToWindow, windowToPage, requestFullScreenMode, toggleSidebar, switchScrollMode, switchSpreadMode, webViewerNamedAction, webViewerPageMode.
search, setActiveSearchResult, clearSearchResults, getSelectedText.
getAnnotationsList, getAnnotationManager, getAnnotationHistoryManager, importAnnotations, exportAnnotations, exportXfdf, saveAnnotations, removeAllAnnotations, selectAnnotation, jumpToAnnotation, setAnnotationStyles, addAnnotationImage, handleReplyAnnotation, setUnselectableAnnotationTypes, getUnselectableAnnotationTypes, enableAutoSelectOnCreate, disableAutoSelectOnCreate, updateViewWithColorIndex, showPopup, handlePopup, setAnnotator.
getDynamicStampPreview, getStampRect, handleStamp, setHighlightLink, setHighlightForm.
setTool, switchTool, setToolMode, getToolMode, getToolStyles, setToolStyles, registerTool, setDefaultSelect, setEraseMode, getEraseMode.
switchAnnotationEditorMode, setContentEditorProperty, getContentEditManager, getContentEditHistoryManager, addEditorImage, getCropedPageImage.
handleField, enableSkipNoRequired, disableSkipNoRequired, isSkipNoRequired, setConsecutiveType, getConsecutiveType, disableFillConsecutively, isFillConsecutively, getFormSignFilledAndUnfilled, getRequiredFormSign, setAutoJumpNextSign.
handleSign, getSignature, deleteSignature, verifySignature, getVerificationResult.
loadCertificates, addToTrustedCertificateLists, checkCertificateIsTrusted, checkPermissionPassword, getPermission, setPassword, removePassword, checkPassword.
applyRedactions, flattenPdf, flattenPdfDownload.
setLayers, exportLayers, setMeasurementDefaults.
setCurrentUser, getCurrentUser, isUserAdmin, isReadOnlyModeEnabled.
setPropertyPanel, setInitProperty, eventBus, addEvent, removeEvent, triggerPrinting, getViewerElement, handleCreateStatus.
apis/ consumes the bridge apis/index.js does import core from '@/core' and spreads the entire bridge into objForWebViewerCore, published as window.instance.Core. It also exposes the default instance directly: window.instance.docViewer = core.getDocumentViewer().
Only 2 of ~67 apis/ files import core directly (index.js, registerTool.js); all others receive it via injection. The apis/ layer is the join point that composes bridge calls with store mutations (e.g. saveDocumentEditor.js calls core.saveDocumentEdit(), then orchestrates store actions and more bridge calls).
A few bridge files deviate from the clean one-liner pattern (useful to know when debugging):
registerTool.js (26 lines) — probes documentViewer.toolRegistry.register, falls back to documentViewer.registerTool, returns false if neither exists.initializeViewer.js (15 lines) — destructures { container, viewer, thumbnailView, outlineView, toggleButton } before forwarding.eventBus.js — returns getDocumentViewer().eventBus (not stateful, despite the name).setDocumentName.js / getDocumentName.js — direct property access (getDocumentViewer().docName).Previously-fixed issues:
checkCertificateIsTrusted.jsused to reference an undefineddata(it now forwards itsdataargument, matching its sibling certificate functions);setActiveSearchResult.jshad areseultparameter typo (nowresult); and thesearch,setActiveSearchResult,clearSearchResults, andsetAnnotationStylesbridge files used an inlinegetDocumentViewer(docNum = 1)reassignment idiom (nowgetDocumentViewer(docNum), relying on thegetDocumentViewer(number = 1)default).
documentViewers.js is the file to inspect when debugging "which viewer am I talking to".apis/ is the join point.