PrintDocument.Print Method (String, PrinterFallbackSettings, Boolean)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Starts the vector printing process for the specified document by optionally opening the print dialog box or printing directly to the default printer for trusted applications.

Namespace:  System.Windows.Printing
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Sub Print ( _
    documentName As String, _
    printerFallbackSettings As PrinterFallbackSettings, _
    useDefaultPrinter As Boolean _
)
public void Print(
    string documentName,
    PrinterFallbackSettings printerFallbackSettings,
    bool useDefaultPrinter
)

Parameters

  • documentName
    Type: System.String
    The name of the document to print.
  • useDefaultPrinter
    Type: System.Boolean
    Whether or not to automatically print to the default printer for the computer without showing a print dialog. This parameter can only be true in trusted applications, otherwise an exception will occur.

Exceptions

Exception Condition
SecurityException

The print operation is not user-initiated.

-or-

useDefaultPrinter is set to true and the application is not a trusted application.

Remarks

In Silverlight 5 the printing defaults to vector printing. In Silverlight 4, the printing defaults to bitmap printing. You can specify bitmap printing in Silverlight 5 by using the PrintBitmap method.

Specify the output to print by handling the PrintPage event and by setting the PrintPageEventArgs.PageVisual property to the UIElement you wish to print. If you are printing items that are not in the visual tree, you should populate the UIElement with all its content before setting it to the PrintPageEventArgs.PageVisual.

If the user cancels the print operation, the BeginPrint and EndPrint events will not occur.

Version Information

Silverlight

Supported in: 5

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.