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.
instance.Core gives integrators direct access to the Core object model. It is the @compdfkit/core namespace plus three members that belong to this viewer:
const {
documentViewer, // the main DocumentViewer
annotationManager, // documentViewer.getAnnotationManager()
getDocumentViewers, // () => all DocumentViewer objects of this WebViewer
Annotations, Tools, Actions, SaveOptions, PageRotation, createDocument,
} = instance.Core;instance.Core is a frozen object. The namespace members (Annotations, Tools, Document, …) are the same classes the UI uses.@compdfkit/core directly. They go through the thin wrappers in src/core/, which take the documentViewerKey as the last parameter and hold no business state.documentViewer, annotationManager and the document returned by documentViewer.getDocument().documentViewer is the main viewer (key 1). The document comparison feature creates more viewers; getDocumentViewers() returns them all, and instance.UI.getDocumentViewer(key) returns one by key.
const viewers = instance.Core.getDocumentViewers();
console.log(viewers.length, viewers[0] === instance.Core.documentViewer);instance.UI.loadDocument(src, options) loads a document into the viewer. documentViewer.getDocument() returns the Document; Document.getFileData({ flags }) returns the PDF data. instance.Core.createDocument(src, options) creates a Document without displaying it.
documentViewer.getPageCount(), getCurrentPage(), setCurrentPage(pageNumber), getZoomLevel(), zoomTo(zoom), getViewerElement(), getScrollViewElement(), and getDisplayModeManager().getDisplayMode() for coordinate conversion.
documentViewer.search(text, mode, options) and clearSearchResults(); getSelectedText() returns the selected text.
Document.insertBlankPages, insertPages, removePages, rotatePages, movePages, copyPages, extractPages, setPassword.
annotationManager.addAnnotation(s), deleteAnnotation(s), getAnnotationsList(), selectAnnotation, redrawAnnotation, exportAnnotations(), importAnnotations(xfdf), setCurrentUser(name), enableReadOnlyMode(), setPermissionCheckCallback(fn). Annotation classes are in instance.Core.Annotations.
documentViewer.getTool(toolName), setToolMode(tool), getToolMode(). Tool classes and ToolNames are in instance.Core.Tools.
annotationManager.getFieldManager() returns the FieldManager (fields, widget highlighting).
documentViewer.getContentEditManager() returns the ContentEditManager (startContentEditMode, endContentEditMode, getContentBoxes, …).
documentViewer.addEventListener(name, handler) and annotationManager.addEventListener(name, handler). See Events.
const { documentViewer } = instance.Core;
documentViewer.setCurrentPage(documentViewer.getPageCount());const xfdfString = await instance.Core.annotationManager.exportAnnotations();
console.log(xfdfString);const { documentViewer, SaveOptions } = instance.Core;
const data = await documentViewer.getDocument().getFileData({ flags: SaveOptions.INCREMENTAL });
console.log(data.byteLength);