This documentation is archived and is not being maintained.

XpsDocumentWriter.WritingPrintTicketRequired Event

Occurs just before a Write or WriteAsync method adds a PrintTicket to a document or print queue.

Namespace: System.Windows.Xps
Assembly: System.Printing (in system.printing.dll)

Public Event WritingPrintTicketRequired As WritingPrintTicketRequiredEventHandler
Dim instance As XpsDocumentWriter
Dim handler As WritingPrintTicketRequiredEventHandler

AddHandler instance.WritingPrintTicketRequired, handler

/** @event */
public void add_WritingPrintTicketRequired (WritingPrintTicketRequiredEventHandler handler)

/** @event */
public void remove_WritingPrintTicketRequired (WritingPrintTicketRequiredEventHandler handler)

In JScript, you can handle the events defined by a class, but you cannot define your own.
Not applicable.

WritingPrintTicketRequired enables an event handler to substitute a new PrintTicket for the one that is passed to the write operation.

The following four Write and WriteAsync methods do not call the WritingPrintTicketRequired event:

The following example shows how to use the WritingPrintTicketRequired event.

// ---------------- PrintMultipleFixedContentDocuments ----------------
/// <summary>
///   Prints the content of a multiple fixed document sequence.</summary>
/// <param name="pq">
///   The print queue to print to.</param>
/// <param name="async">
///   true to print asynchronously; false to print synchronously.</param>
public void PrintMultipleFixedContentDocuments(PrintQueue pq, bool async)
    // Create a multiple document FixedDocumentSequence.
    FixedDocumentSequence fds =

    // Create a document writer to print to.
    XpsDocumentWriter xdwPrint = GetPrintXpsDocumentWriter(pq);

    // Set the event handler for creating print tickets for
    // each document within the fixed document sequence.
    xdwPrint.WritingPrintTicketRequired +=
        new WritingPrintTicketRequiredEventHandler(
    _firstDocumentPrintTicket = 0;

    // Print either asynchronously or synchronously.
    if (async)
        PrintMultipleFixedContentDocumentsAsync(xdwPrint, fds);
        PrintMultipleFixedContentDocuments(xdwPrint, fds);
}// end:PrintMultipleFixedContentDocuments()

For the complete sample, see Printing an XPS Document.

The event handler is created in the following example.

// ----- MultipleFixedContentDocuments_WritingPrintTicketRequired -----
/// <summary>
///   Creates a PrintTicket event handler for
///   printing a FixedDocumentSequence.</summary>
private void MultipleFixedContentDocuments_WritingPrintTicketRequired(
                Object sender, WritingPrintTicketRequiredEventArgs e)
    if (e.CurrentPrintTicketLevel ==
        // Create a PrintTicket for the FixedDocumentSequence. Any
        // PrintTicket setting specified at the FixedDocumentSequence
        // level will be inherited by lower level (i.e. FixedDocument or
        // FixedPage) unless there exists lower level PrintTicket that
        // sets the setting differently, in which case the lower level
        // PrintTicket setting will override the higher level setting.
        PrintTicket ptFDS = new PrintTicket();
        ptFDS.PageOrientation = PageOrientation.Portrait;
        ptFDS.Duplexing = Duplexing.TwoSidedLongEdge;
        e.CurrentPrintTicket = ptFDS;

    else if (e.CurrentPrintTicketLevel ==
        // Use different PrintTickets for different FixedDocuments.
        PrintTicket ptFD = new PrintTicket();

        if (_firstDocumentPrintTicket <= 1)
        {   // Print the first document in black/white and in portrait
            // orientation.  Since the PrintTicket at the
            // FixedDocumentSequence level already specifies portrait
            // orientation, this FixedDocument can just inherit that
            // setting without having to set it again.
            ptFD.PageOrientation = PageOrientation.Portrait;
            ptFD.OutputColor = OutputColor.Monochrome;

        else // if (_firstDocumentPrintTicket > 1)
        {   // Print the second document in color and in landscape
            // orientation.  Since the PrintTicket at the
            // FixedDocumentSequence level already specifies portrait
            // orientation, this FixedDocument needs to set its
            // PrintTicket with landscape orientation in order to
            // override the higher level setting.
            ptFD.PageOrientation = PageOrientation.Landscape;
            ptFD.OutputColor = OutputColor.Color;

        e.CurrentPrintTicket = ptFD;
    }// end:else if (CurrentPrintTicketLevel==FixedDocumentPrintTicket)

    // Even though we don't show code for specifying PrintTicket for
    // the FixedPage level, the same inheritance-override logic applies
    // to FixedPage as well.

}// end:MultipleFixedContentDocuments_WritingPrintTicketRequired()

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0