PrintTicket.PageMediaSize Property

Definition

Gets or sets the page size for the paper (or other media) that a printer uses for a print job.

public System.Printing.PageMediaSize PageMediaSize { get; set; }

Property Value

A PageMediaSize object that represents the page size by using a name, dimensions, or both.

Exceptions

Calling code has attempted to set the property with a PageMediaSize object that has at least one null property.

-or-

Calling code has attempted to set the property with a PageMediaSize object whose PageMediaSizeName property is set to a value that is not in the PageMediaSizeName enumeration.

-or-

Calling code has attempted to set the property with a PageMediaSize object whose Width or Height property is set to a value less than 1.

Examples

The following example shows how to use this property to scale a visual element to fit within the margins of the paper on which it is to print.

/// <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()

Remarks

This property corresponds to the Print Schema's PageMediaSize keyword.

You can test for the options that the printer supports by using the PageMediaSizeCapability property.

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9