This documentation is archived and is not being maintained.

PageMediaSize.Width Property

Gets the page width.

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

public Nullable<double> Width { get; }
You cannot set this property in XAML.

Property Value

Type: System.Nullable<Double>
A Double that represents the page width, in pixels, which are 1/96 inch units.

The following example shows how to use this class to scale a visual element to fit within the margins of the paper on which it is to print. For the full sample, see Printing an XPS Document.

/// <summary> 
///   Returns a scaled copy of a given visual transformed to 
///   fit for printing to a specified print queue.</summary> 
/// <param name="v">
///   The visual to be printed.</param> 
/// <param name="pq">
///   The print queue to be output to.</param> 
/// <returns> 
///   The root element of the transformed visual.</returns> 
private Visual PerformTransform(Visual v, PrintQueue pq)
{
    ContainerVisual root = new ContainerVisual();
    const double inch = 96;

    // Set the margins. 
    double xMargin = 1.25 * inch;
    double yMargin = 1 * inch;

    PrintTicket pt = pq.UserPrintTicket;
    Double printableWidth = pt.PageMediaSize.Width.Value;
    Double printableHeight = pt.PageMediaSize.Height.Value;

    Double xScale = (printableWidth - xMargin * 2) / printableWidth;
    Double yScale = (printableHeight - yMargin * 2) / printableHeight;

    root.Children.Add(v);
    root.Transform = new MatrixTransform(xScale, 0, 0, yScale, xMargin, yMargin);

    return root;
}// end:PerformTransform()

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Show: