Printing

This guide shows how to work with the Printing API.

Overview

The web page can be printed using the following ways:

  1. The window.print() JavaScript function. It can be invoked from the JavaScript code on a web page.
  2. The IFrame.Print() method of the DotNetBrowser API. It requests printing of the frame. If you need to print the whole page, call the Print() method in the main frame. See the code sample below:
browser.MainFrame?.Print();

The web page is not printed immediately. The PrintHandler will be invoked to tell the engine how to handle the print request. By default, all print requests are canceled.

To allow the print request and display the Print Preview dialog, use the code sample below:

browser.PrintHandler =
    new Handler<PrintParameters, PrintResponse>(p =>
    {
        return PrintResponse.ShowPrintPreview();
    });

In the Print Preview dialog, you can select the preferred printing options:

Print Preview

Canceling printing

If you need to cancel or disable printing at all, use the code sample below:

browser.PrintHandler =
    new Handler<PrintParameters, PrintResponse>(p =>
    {
        return PrintResponse.Cancel();
    });
Go Top