The PrintDocument method displays the print dialog for the
currently loaded document. The dialog is shown asynchronously and the
method will return once the print user interface has been invoked. This
method does not perform the printing operation itself; it only initiates
the print workflow and allows the user to select a printer, adjust
preferences, and confirm printing.
This method can only be called after navigation has completed and the
current document is fully loaded. If navigation is still in progress when
the method is called, it will fail with an error indicating that the
operation is in progress. This method only supports interactive printing
through a user interface. If you need to programmatically export the document
without user interaction, use the SaveDocument method instead.
It is recommended that most applications use the default dialog. The
WEBVIEW_PRINT_DIALOG_SYSTEM option shows a simplified print
dialog provided by browser. This is not the same dialog exposed by the Windows
Common Controls API through the PrintDlg or PrintDlgEx functions,
and it may differ in appearance and available options depending on the platform
and version of the WebView2 runtime.
To provide more control over how the document is printed, initialize
the entire WEBVIEW_PRINT_SETTINGS structure to zero, then
initialize its dwSize member to the size of the structure. Set the
remaining members to the options required for the print operation. If
the lpszPrinter member is NULL or empty, the operating system's
default printer is used.
The dwFlags structure member controls whether custom page
dimensions, margins, and scaling are applied, and whether
backgrounds and headers and footers are included. For example,
setting margin values has no effect unless
WEBVIEW_PRINT_FLAG_MARGINS is also specified. When
this flag is specified, all four margin members are used,
including any members set to zero.
Page dimensions and margins are specified in inches. Scaling
is specified as a factor, where 1.0 represents 100 percent.
Printer settings such as color mode, duplex printing, and custom
media sizes are subject to the capabilities of the selected
printer.
To save the document directly to a PDF file, use SaveDocument
method.