Show / Hide Table of Contents

Class PrintDocument

Provides printing capabilities for a Silverlight application.

Inheritance
System.Object
DependencyObject
PrintDocument
Inherited Members
DependencyObject.GetValue(DependencyProperty)
DependencyObject.SetCurrentValue(DependencyProperty, Object)
DependencyObject.ReadLocalValue(DependencyProperty)
DependencyObject.SetValue(DependencyProperty, Object)
DependencyObject.SetValue(DependencyPropertyKey, Object)
DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs)
DependencyObject.CoerceValue(DependencyProperty)
DependencyObject.Dispatcher
DependencyObject.INTERNAL_OnAttachedToVisualTree()
DependencyObject.INTERNAL_OnDetachedFromVisualTree()
DependencyObject.ClearValue(DependencyProperty)
DependencyObject.ClearValue(DependencyPropertyKey)
DependencyObject.CheckAccess()
DependencyObject.GetAnimationBaseValue(DependencyProperty)
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: System.Windows.Printing
Assembly: OpenSilver.dll
Syntax
public class PrintDocument : DependencyObject, IDependencyObject
Remarks
  1. All elements are collected using the PrintPage event and then 'print-section' class is added to all of them.
  2. 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'
  3. 'print-section' is added as the first child of the body element.
  4. @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 Source

PrintDocument()

Initializes a new instance of the PrintDocument class.

Declaration
public PrintDocument()

Fields

| Improve this Doc View Source

PrintedPageCountProperty

Gets the identifier for the PrintedPageCount dependency property.

Declaration
public static readonly DependencyProperty PrintedPageCountProperty
Field Value
Type Description
DependencyProperty

Properties

| Improve this Doc View Source

PrintedPageCount

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 Source

Print(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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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 Source

BeginPrint

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>
| Improve this Doc View Source

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>
| Improve this Doc View Source

PrintPage

Occurs when each page is printing.

Declaration
public event EventHandler<PrintPageEventArgs> PrintPage
Event Type
Type Description
System.EventHandler<PrintPageEventArgs>

Extension Methods

DependencyObjectHelper.GetSelfAndAncestors(DependencyObject)
VisualTreeExtensions.GetVisualAncestors(DependencyObject)
VisualTreeExtensions.GetVisualAncestorsAndSelf(DependencyObject)
VisualTreeExtensions.GetVisualChildren(DependencyObject)
VisualTreeExtensions.GetVisualChildrenAndSelf(DependencyObject)
VisualTreeExtensions.GetVisualDescendants(DependencyObject)
VisualTreeExtensions.GetVisualDescendantsAndSelf(DependencyObject)
VisualTreeExtensions.GetVisualSiblings(DependencyObject)
VisualTreeExtensions.GetVisualSiblingsAndSelf(DependencyObject)
  • Improve this Doc
  • View Source