PrintTaskRequest PrintTaskRequest PrintTaskRequest PrintTaskRequest PrintTaskRequest Class

Definition

Contains the request from the system to create a print task. This object is available from the PrintTaskRequestedEventArgs object passed to the PrintTaskRequested event.

public : sealed class PrintTaskRequest : IPrintTaskRequest
struct winrt::Windows::Graphics::Printing::PrintTaskRequest : IPrintTaskRequest
public sealed class PrintTaskRequest : IPrintTaskRequest
Public NotInheritable Class PrintTaskRequest Implements IPrintTaskRequest
// This class does not provide a public constructor.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

The PrintTaskRequest class is used by an app to create a new PrintTask object. A PrintTask object is created in response to the PrintTaskRequested event and it indicates to the system that the app has content to be printed. When creating a PrintTask object using the CreatePrintTask method, the app must provide a name for the PrintTask and a PrintTaskSourceRequestedHandler event handler which is called when the content to be printed is required.

An app should do the minimum amount of work possible in the PrintTaskRequested event handler since only a short amount of time is provided for a response. Wherever possible, the app should simply create a PrintTask and delay any content initialization until the PrintTaskSourceRequestedHandler event handler is called.

If an app needs to perform an asynchronous operation during the PrintTaskRequested handler it must retrieve and use a PrintTaskRequestedDeferral object. Prior to the exit of the event handler, and typically before the asynchronous operation is started, the app must retrieve the PrintTaskRequestedDeferral object by calling the GetDeferral method of the PrintTaskRequest object. When the asynchronous operation completes, the app must call the Complete method of the PrintTaskRequestedDeferral object to signal that the print task request is complete. The call to the Complete method must occur before the Deadline is reached in order for the request to be accepted.

The CreatePrintTask method in PrintTaskRequest can be used to create the print task. Here is a JavaScript code snippet showing the creation of a print task:

    // Print event handler for printing via the PrintManager API.
    // printEvent contains the print task request object
    function onPrintTaskRequested(printEvent) {
        printEvent.request.createPrintTask("Print Sample", function (args) {
            args.setSource(MSApp.getHtmlPrintDocumentSource(document));
        }); 
    }

For more information on this and other printing scenarios, see Printing on the Windows Dev Center.

Properties

Deadline Deadline Deadline Deadline Deadline

Gets a DateTime value that indicates how long an app has to respond to the PrintTaskRequested event. If the system has not received a response from the PrintTaskRequested event handler by the time the deadline is reached, then the print task is ignored.

Methods

CreatePrintTask(String, PrintTaskSourceRequestedHandler) CreatePrintTask(String, PrintTaskSourceRequestedHandler) CreatePrintTask(String, PrintTaskSourceRequestedHandler) CreatePrintTask(String, PrintTaskSourceRequestedHandler) CreatePrintTask(String, PrintTaskSourceRequestedHandler)

Creates a new PrintTask which indicates that the app has content to be printed.

GetDeferral() GetDeferral() GetDeferral() GetDeferral() GetDeferral()

Retrieves the deferral object associated with the PrintTaskRequest. The deferral object is used to handle asynchronous calls in the PrintTaskRequested event handler.

See Also