Printing

EO.WebBrowser provides several functions and one event for you to print the current page with or without user intervention.

Start Printing

Printing can be started either calling one of the WebView's Print methods, or by calling window.print() in JavaScript code. In both cases, the BeforePrint event will be raised and you will have the opportunity to cancel or continue the printing.

Through one of the Print method, you can:

  • Whether to print the whole page or only print the current selected frame;
  • Provide a PrinterSettings object so that the print dialog will be skipped;

For example, the following code prints the current page without displaying the print dialog:

//Get the default print settings
PrintSettings settings = WebView.GetDefaultPrintSettings();

//Start printing with the above settings
webView1.Print(settings);

Handle BeforePrint Event

In all cases, BeforePrint event will be raised before a printing job actually starts. Inside this event handler you can:

  • Modify the event argument's PrinterSettings or PageSettings to change the printer or page settings;
  • Calling the event argument's Cancel method to cancel the printing job;
  • Calling the event argument's Continue method to continue the print job with or without displaying the printing dialog;

The following code demonstrates how to cancel all printing jobs initiated by JavaScript:

//Hook up the event handler
webView.BeforePrint += new BeforePrintEventHandler(webView_BeforePrint);

void webView_BeforePrint(object sender, BeforePrintEventArgs e)
{
    //Cancel all printing from JavaScript 
    if (e.IsFromScript)
        e.Cancel();
}