WebExeBuilder Documentation

print

Category: Browser Control

Namespace: web.browser.print

Description

Opens the system print dialog for the current page, allowing the user to print the page content, save to PDF, or send to any installed printer. Uses the same native print mechanism as the built-in Print menu item.

Syntax

const success = await web.browser.print();

Parameters

None.

Returns

Promise<boolean>true when the print dialog is opened. Returns false if an error occurs.

Note: The promise resolves immediately when the print dialog opens — it does not wait for the user to finish printing or cancel.

Examples

Simple print button

document.getElementById('print-btn').addEventListener('click', async () => {
    await web.browser.print();
});

Print with confirmation

async function printReport() {
    const result = await web.dialogs.message({
        heading: 'Print Report',
        content: 'Ready to print the current report?',
        icon: 'info',
        buttons: 'okcancel'
    });

    if (result.button === 'ok') {
        await web.browser.print();
    }
}

Print-friendly styling

<style>
    /* Hide toolbar and navigation when printing */
    @media print {
        .toolbar, .sidebar, .no-print { display: none !important; }
        .content { margin: 0; padding: 0; }
    }
</style>

<button class="no-print" onclick="web.browser.print()">Print</button>

Use Cases

  • Print reports, invoices, or receipts
  • Save the current page as a PDF (via the system "Save as PDF" printer)
  • Print data tables, forms, or checklists
  • Add a print button to any app that displays formatted content

Notes

  • The system print dialog appears immediately — the user can choose a printer, set page range, orientation, etc.
  • Use CSS @media print rules to control what appears on the printed page (hide toolbars, navigation, buttons)
  • The print dialog includes "Save as PDF" as a printer option on Windows 10/11
  • The promise resolves when the dialog opens, not when printing completes
  • This calls the same WebView2 SimulateEditingCommand(ecPrint) as the built-in Print menu item
  • web.browser.getPageTitle() — get the page title (often used as the print document name)
  • web.browser.setZoom() — adjust zoom before printing if needed