向 XPS 文档添加签名请求
本主题介绍如何向 XPS 文档添加签名请求。 如果用户同意签名意向,签名请求会提示用户对文档进行签名。
在程序中使用以下代码示例之前,请阅读常见数字签名编程任务中的免责声明。
若要向 XPS 文档添加签名请求,请执行以下操作:
- 如初始化签名管理器中所述,将 XPS 文档加载到签名管理器中。
- 将签名块添加到签名管理器。
- 在新的签名块中创建签名请求。
- 设置签名请求的属性:
- 设置签名意向。
- 设置请求签名的人员的姓名(请求的签名者)。
- 设置需要签名的日期。
- 根据需要设置其他签名属性。
下面的代码示例演示如何向 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;
}
相关主题
-
本部分使用的内容
-
详细信息