將簽章要求新增至 XPS 檔

本主題描述如何將簽章要求新增至 XPS 檔。 如果使用者同意簽章意圖,簽章要求會提示使用者簽署檔。

在程式中使用下列程式碼範例之前,請先閱讀一般數位簽章程式設計 工作中的 免責聲明。

若要將簽章要求新增至 XPS 檔:

  1. 將 XPS 檔載入簽章管理員,如初始化簽章管理員 中所述
  2. 將簽章區塊新增至簽章管理員。
  3. 在新的簽章區塊中建立簽章要求。
  4. 設定簽章要求的屬性:
    1. 設定簽章意圖。
    2. 設定要求籤章的人員名稱(要求的簽署者)。
    3. 設定需要簽章的日期。
    4. 視需要設定其他簽章屬性。

下列程式碼範例說明如何將簽章要求新增至 XPS 檔。

HRESULT 
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;
}

用於本節

IXpsSignatureBlock

IXpsSignatureBlock::CreateRequest

IXpsSignatureManager

IXpsSignatureManager::AddSignatureBlock

IXpsSignatureRequest

IXpsSignatureRequest::SetIntent

IXpsSignatureRequest::SetRequestedSigner

IXpsSignatureRequest::SetRequestSignByDate

詳細資訊

XPS 數位簽章 API 錯誤

XPS 檔錯誤

XML 紙張規格