Skip to content

PDF Generation Template Editor

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

View on GitHub

Content Editor ​

The content editor lets users edit text and images directly on the PDF page — add text, add images, and modify existing content. The page editor lets users insert, delete, rotate, move and extract pages. This guide covers both.

Content editing belongs to the Core ContentEditManager (documentViewer.getContentEditManager()), with its own history manager. The UI drives it through tools and panels.

Content editing ​

Start content editing ​

Content editing is the toolbar group toolbarGroup-EditText. Switching to it activates the content editing tool ContentEditTool:

javascript
UI.setToolbarGroup('toolbarGroup-EditText');

The tools of the group are the grouped items editTextGroupedItems. Selecting a text block shows the content edit popup (UI.contentEditPopup) and the properties panel textEditingPanel.

Core APIs ​

APIPurpose
contentEditManager.startContentEditMode() / endContentEditMode()Enter / leave content editing.
contentEditManager.isInContentEditMode()Whether content editing is active.
contentEditManager.getContentBoxes(pageNumber)The text and image blocks of a page.
contentEditManager.getSelectedContentBox()The selected block.
contentEditManager.getContent(box) / setContent(box, content)Read / write the text of a block.
documentViewer.getContentEditHistoryManager()Undo / redo of content editing; fires undoRedoStatusChanged with { canUndo, canRedo }.
javascript
const contentEditManager = instance.Core.documentViewer.getContentEditManager();
console.log(contentEditManager.isInContentEditMode());

The page editor ​

UI APIs ​

javascript
await UI.enterPageEditorMode();   // open the page editor
UI.isInPageEditorMode();          // => true
await UI.savePageEditor();        // apply the changes to the document
await UI.exitPageEditorMode();    // leave without saving
APIPurpose
enterPageEditorMode()Open the page editor (toolbar group toolbarGroup-Document). Resolves when the editor is ready.
exitPageEditorMode()Discard the changes and return to the View group.
isInPageEditorMode()Whether the page editor is open.
savePageEditor()Apply the changes to the document shown in the viewer.
enablePageEditorSave() / disablePageEditorSave()Show / hide the Save button of the page editor.
enablePageEditorSaveAs() / disablePageEditorSaveAs()Show / hide the Save As button of the page editor.

While the page editor is open, the header page-editor-header replaces the top header.

Content editor state ​

StatePurpose
Content editingWhether content editing is active, the selected blocks, the text properties shown in textEditingPanel.
Page editorWhether the page editor is open, the pages and the selection in the editor.
Undo / redoMirrors the history managers of the Core.

Content editor components ​

  • Page editor — the page grid shown in the page editor, with the page editing modals (insertPageModal, mergePagesModal, deletePagesModal, extractPagesModal, movePagesModal).
  • textEditingPanel — the properties of the selected text block.
  • Content edit popup — copy, properties and delete (see Popups).

Examples ​

Hide Save As in the page editor ​

javascript
UI.disablePageEditorSaveAs();

Save the page editor changes ​

javascript
await UI.enterPageEditorMode();
// … the user edits the pages …
await UI.savePageEditor();

Listen for content editing undo/redo ​

javascript
const history = instance.Core.documentViewer.getContentEditHistoryManager();
history.addEventListener('undoRedoStatusChanged', ({ canUndo, canRedo }) => {
  console.log(canUndo, canRedo);
});