Trilium Electron API
    Preparing search index...

    Interface ElectronPrintingApi

    Printing and PDF export flow. Trilium drives Electron's printing pipeline through a small state machine that the main process owns, with progress and results pushed back to the renderer via IPC events.

    interface ElectronPrintingApi {
        exportAsPdfPreview(opts: Record<string, unknown>): void;
        getPrinters(): Promise<unknown[]>;
        onExportAsPdfPreviewResult(
            callback: (result: { buffer?: Uint8Array; error?: string }) => void,
        ): void;
        onPrintDone(callback: (printReport: unknown) => void): void;
        onPrintProgress(
            callback: (data: { action: string; progress: number }) => void,
        ): void;
        printFromPreview(opts: Record<string, unknown>): void;
        removeExportAsPdfPreviewResultListener(): void;
        removePrintListeners(): void;
        savePdf(data: { buffer: Uint8Array; title: string }): void;
        sendPrintProgress(progress: number): void;
    }
    Index

    Methods

    • Asks the main process to render the current note as a PDF and return the resulting bytes for the in-app preview. Result is delivered via onExportAsPdfPreviewResult.

      Parameters

      Returns void

    • Returns the list of printers known to the OS.

      Returns Promise<unknown[]>

    • Subscribes to the result of an exportAsPdfPreview call.

      Parameters

      • callback: (result: { buffer?: Uint8Array; error?: string }) => void

      Returns void

    • Subscribes to the "print finished" event, fired once the OS print job is dispatched.

      Parameters

      • callback: (printReport: unknown) => void

      Returns void

    • Subscribes to progress updates emitted by the main process during a print or PDF export run. action describes the current stage (e.g. "rendering").

      Parameters

      • callback: (data: { action: string; progress: number }) => void

      Returns void

    • Sends the previewed PDF to the OS print dialog with the given options.

      Parameters

      Returns void

    • Removes the listener registered via onExportAsPdfPreviewResult.

      Returns void

    • Removes all listeners registered via onPrintProgress and onPrintDone.

      Returns void

    • Persists a previously generated PDF buffer to disk via the native save dialog. title is used as the suggested filename.

      Parameters

      • data: { buffer: Uint8Array; title: string }

      Returns void

    • Reports rendering progress (0..100) from the renderer to the main process.

      Parameters

      • progress: number

      Returns void