Class PrintDocument
Provides printing capabilities for a Silverlight application.
Inherited Members
Namespace: System.Windows.Printing
Assembly: OpenSilver.dll
Syntax
public class PrintDocument : DependencyObject
Remarks
- All elements are collected using the PrintPage event and then 'print-section' class is added to all of them.
- A separate 'print-section' div is created inside 'beforeprint' event and all 'print-section' elements added to it with different class name to be printed later - 'print-document-section-to-print'
- 'print-section' is added as the first child of the body element.
- @media print is used to show 'print-document-section-to-print' elements and hide the rest.
The reason it recreates and adds the elements to 'body' is to avoid wrong positioning depending on other relative elements. One other solution would be to use 'fixed' position however it breaks paging (break-after). 'beforeprint' event prepares everything needed for printing and 'afterprint' cleans up things.
'beforeprint' and 'afterprint' events registered only once and @media print rule is added/removed by JavaScript which guarantees no side effects after print.
Constructors
| Improve this Doc View SourcePrintDocument()
Initializes a new instance of the PrintDocument class.
Declaration
public PrintDocument()
Fields
| Improve this Doc View SourcePrintedPageCountProperty
Gets the identifier for the PrintedPageCount dependency property.
Declaration
public static readonly DependencyProperty PrintedPageCountProperty
Field Value
Type | Description |
---|---|
DependencyProperty |
Properties
| Improve this Doc View SourcePrintedPageCount
Gets the number of pages that have printed.
Declaration
public int PrintedPageCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 | The number of pages that have printed. |
Methods
| Improve this Doc View SourcePrint(String)
Starts the printing process for the specified document by opening the print dialog box.
Declaration
public void Print(string documentName)
Parameters
Type | Name | Description |
---|---|---|
System.String | documentName | The name of the document to print. |
Exceptions
Type | Condition |
---|---|
System.Security.SecurityException | The print operation is not user-initiated. |
Print(String, PrinterFallbackSettings, Boolean)
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.
Declaration
[NotImplemented]
public void Print(string documentName, PrinterFallbackSettings printerFallbackSettings, bool useDefaultPrinter = false)
Parameters
Type | Name | Description |
---|---|---|
System.String | documentName | The name of the document to print. |
PrinterFallbackSettings | printerFallbackSettings | The settings to use to enable vector printing for printers with limited support. |
System.Boolean | useDefaultPrinter | 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
Type | Condition |
---|---|
System.Security.SecurityException | The print operation is not user-initiated.-or-useDefaultPrinter is set to true and the application is not a trusted application. |
PrintBitmap(String)
Starts the bitmap printing process for the specified document by opening the print dialog box.
Declaration
[NotImplemented]
public void PrintBitmap(string documentName)
Parameters
Type | Name | Description |
---|---|---|
System.String | documentName | The name of the document to print. |
Events
| Improve this Doc View SourceBeginPrint
Occurs after the Print(String) method is called and the print dialog box successfully returns, but before the PrintPage event is raised.
Declaration
public event EventHandler<BeginPrintEventArgs> BeginPrint
Event Type
Type | Description |
---|---|
System.EventHandler<BeginPrintEventArgs> |
EndPrint
Occurs when the printing operation is passed to the print spooler or when the print operation is cancelled by the application author.
Declaration
public event EventHandler<EndPrintEventArgs> EndPrint
Event Type
Type | Description |
---|---|
System.EventHandler<EndPrintEventArgs> |
PrintPage
Occurs when each page is printing.
Declaration
public event EventHandler<PrintPageEventArgs> PrintPage
Event Type
Type | Description |
---|---|
System.EventHandler<PrintPageEventArgs> |