Print documents
Connect PDF conversion to the File menu for printing in React and Vue.
Printing converts the document with your PDF export handler and opens the browser print dialog. No separate print handler exists.
Enable printing
Configure menu.exporters.pdf. This example uses the exporters.ts module from Connect export handlers:
import { DocxEditor } from '@docx-editor.dev/react';
import { exporters } from './exporters';
import '@docx-editor.dev/core/styles/editor.css';
export function Editor({ source }: { source: Uint8Array }) {
return <DocxEditor document={source} menu={{ exporters }} />;
}<script setup lang="ts">
import { DocxEditor } from '@docx-editor.dev/vue';
import { exporters } from './exporters';
import '@docx-editor.dev/core/styles/editor.css';
defineProps<{ source: Uint8Array }>();
</script>
<template>
<DocxEditor :document="source" :menu="{ exporters }" />
</template>PDF conversion runs on Node.js and requires the EigenPal Pro License. For converter installation and the server endpoint, see Export Markdown and PDF.
File > Print, Ctrl+P, and Cmd+P on macOS then print. The shortcut works when focus is inside the editor.
The slot is file.print, exposed as DocxEditor.Menu.Print and DocxEditorMenu.Print. In a custom File menu:
- If you replace the menu with
preset={false}, include this part. - Pass
hiddento remove it. - A generic
Menu.Itemdoes not print.
Configure print settings
Before conversion, the packaged dialog asks for Markup and Print comments. These settings change the printed view only, not the editor's view. The handler receives them in its ChromeExportView argument:
| Field | Value |
|---|---|
displayMode | The chosen markup: All Markup, Simple Markup, No Markup, or Original. Starts at the current review view. |
comments | Whether comments print. Defaults to on. |
revisionMarkup, revisionAuthorSlots | The current markup preferences and author slots. |
Forward all four fields to exportPdf, as in Convert PDF on the server. A handler that ignores view ignores both settings. A handler that drops comments always prints comments.
| Menu option | Effect |
|---|---|
printSettings: false | Prints the current view without asking. |
printSettings: true | Required for a custom popups.print component to show the settings step. |
The packaged dialog shows settings by default. The step also does not show when popups.print is false or no PDF handler exists.
Build a custom print flow
Call runChromePrint(editor, exporters, container, settings) from @docx-editor.dev/core/editor to prepare a ChromePrintJob:
import {
ChromePrintError,
runChromePrint,
type ChromeExportHandlers,
type ChromePrintJob,
} from '@docx-editor.dev/core/editor';
import type { Editor } from '@docx-editor.dev/core';
export async function printDocument(
editor: Editor,
exporters: ChromeExportHandlers,
container: Element
): Promise<ChromePrintJob> {
const job = await runChromePrint(editor, exporters, container);
try {
await job.print();
} catch (error) {
if (!(error instanceof ChromePrintError)) {
job.dispose();
throw error;
}
// Show job.url as a link to the PDF viewer.
}
// Keep the job during printing. Dispose it before the next print or on unmount.
return job;
}| Member or argument | Behavior |
|---|---|
container | Optional Document or Element for the hidden print frame. Defaults to document. Inside a modal, pass an element in the modal. |
settings | Optional ChromePrintSettings with displayMode and comments. Omitted settings keep the current view. |
job.url | Object URL of the PDF. Valid until dispose(). |
job.print(options?) | Loads the PDF and opens the browser print dialog. |
job.dispose() | Removes the hidden frame and revokes url. |
For a settings form, initialChromePrintSettings(editor.snapshot()) returns starting values. CHROME_PRINT_DISPLAY_MODES lists the modes with label keys. isChromePrintShortcut(event) recognizes the print shortcut.
Keep the job alive while the user prints or opens its link. Removing the frame during printing can cancel the printout.
Handle failures
runChromePrint rejects with ChromeExportError when the PDF handler is missing. Conversion and PDF validation errors also reject it. Browser print failures throw ChromePrintError:
| Code | Meaning |
|---|---|
pdf-viewer-unavailable | The browser reports no built-in PDF viewer (navigator.pdfViewerEnabled is false). |
pdf-load-failed | The PDF frame failed to load. Call print() again to reload it. |
print-refused | The browser refused access to PDF printing. |
print-ended | The job was disposed. Create another job. |
The packaged dialog offers an Open PDF link for these failures and after a 15-second load timeout. If a browser prints blank pages from a frame, export the PDF and print it from a PDF viewer.
Customize feedback
Use popups.print to replace the settings, progress, and error feedback. See Customize print feedback.
For a modal progress dialog, pass job.print({ beforePrint: closeDialog }). The callback runs after the PDF loads and before printing. Wait for the dialog to unmount before it returns: use flushSync in React, or await nextTick() in Vue.
Limits
- Printing calls
save()first, which validates form input and can refresh fields with an undo step. See Save a document. - Cancel during preparation discards a conversion result that arrives later.
- The packaged print action stays unavailable during preparation and while its error dialog is open.
- Without
menu.exporters.pdf, the browser handles the shortcut, and File > Print opens a setup error. - macOS Ctrl+P stays available for moving to the previous line.
- The PDF converter determines the printed layout. If a background is missing, inspect the exported PDF.