Add a Signature Request to an XPS Document

This topic describes how to add a signature request to an XPS document. A signature request prompts a user to sign a document if he or she agrees with the signature intent.

Before using the following code examples in your program, read the disclaimer in Common Digital Signature Programming Tasks.

To add a signature request to an XPS Document:

  1. Load the XPS document into a signature manager, as described in Initialize the Signature Manager.
  2. Add a signature block to the signature manager.
  3. Create a signature request in the new signature block.
  4. Set the properties of the signature request:
    1. Set the signature intent.
    2. Set the name of the person whose signature is requested (the requested signer).
    3. Set the date the signature is required.
    4. Set other signature properties as required.

The following code example illustrates how to add a signature request to an XPS document.

AddSignatureRequestToDocument (
    __in IXpsSignatureManager    *signatureManager,
    __in LPCWSTR                reasonForSignatureRequest,
    __in LPCWSTR                nameOfRequestedSigner,
    __in LPCWSTR                requestSignByDate
    HRESULT                  hr = S_OK;
    IXpsSignatureBlock       *signatureDefinition = NULL;
    IXpsSignatureRequest     *signatureRequest = NULL;
    // Create a new signature block and get a pointer to it
    hr = signatureManager->AddSignatureBlock (NULL, 0, &signatureDefinition);
    if (SUCCEEDED(hr)) {
        // Create a new signature request to use for this signature block
        hr = signatureDefinition->CreateRequest(NULL, &signatureRequest);

    if (SUCCEEDED(hr)) {
        // Initialize the properties of the signature request

        //  Set the string that describes the purpose of the signature
        //  to the person who will sign the document.
        hr = signatureRequest->SetIntent(reasonForSignatureRequest);

    if (SUCCEEDED(hr)) {
        //  Set the name of the person whose signature is requested.
        hr = signatureRequest->SetRequestedSigner(nameOfRequestedSigner);

    if (SUCCEEDED(hr)) {
        //  Set the date that the person should sign the document.
        //  The person is requested to sign the document on or before
        //   the date specified in this field. Refer to the help text
        //   for the correct format of this string.
        hr = signatureRequest->SetRequestSignByDate(requestSignByDate);

    if (NULL != signatureDefinition) signatureDefinition->Release();
    if (NULL != signatureRequest) signatureRequest->Release();

    return hr;

Related topics

Used in This Section
For More Information
XPS Digital Signature API Errors
XPS Document Errors
XML Paper Specification