在C#中使用DocuSign应用程序接口(API)签名PDF可以通过以下步骤实现:
请注意,DocuSign提供了丰富的文档和示例代码,详细介绍了如何使用其API进行PDF签名。以下是一些相关的资源:
// 引入必要的命名空间
using DocuSign.eSign.Api;
using DocuSign.eSign.Model;
using DocuSign.eSign.Client;
public class DocuSignService
{
private readonly string integratorKey = "YourIntegratorKey";
private readonly string userId = "YourUserId";
private readonly string accountId = "YourAccountId";
private readonly string privateKey = "YourPrivateKey";
public string SignPdf(string pdfPath, string recipientEmail, string recipientName)
{
// 配置身份验证信息
ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi");
apiClient.Configuration.DefaultHeader.Add("Authorization", GetJwtToken());
// 创建签名请求
EnvelopeDefinition envelope = new EnvelopeDefinition();
envelope.EmailSubject = "Please sign this PDF";
envelope.Recipients = new Recipients();
Signer signer = new Signer();
signer.Email = recipientEmail;
signer.Name = recipientName;
signer.RecipientId = "1";
signer.Tabs = new Tabs();
signer.Tabs.SignHereTabs = new List<SignHere>();
signer.Tabs.SignHereTabs.Add(new SignHere()
{
DocumentId = "1",
PageNumber = "1",
RecipientId = "1",
TabLabel = "SignHereTab",
XPosition = "100",
YPosition = "100"
});
envelope.Recipients.Signers = new List<Signer>();
envelope.Recipients.Signers.Add(signer);
Document document = new Document();
document.DocumentBase64 = Convert.ToBase64String(File.ReadAllBytes(pdfPath));
document.DocumentId = "1";
document.Name = "PDF Document";
envelope.Documents = new List<Document>();
envelope.Documents.Add(document);
envelope.Status = "sent";
// 发送签名请求
EnvelopesApi envelopesApi = new EnvelopesApi(apiClient);
EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envelope);
// 获取签署URL
RecipientViewRequest viewRequest = new RecipientViewRequest()
{
ReturnUrl = "https://www.example.com/signingCompleted",
ClientUserId = "1",
AuthenticationMethod = "email",
UserName = recipientName,
Email = recipientEmail
};
ViewUrl viewUrl = envelopesApi.CreateRecipientView(accountId, envelopeSummary.EnvelopeId, viewRequest);
return viewUrl.Url;
}
private string GetJwtToken()
{
// 根据文档中的说明,使用私钥生成JWT令牌
// 你需要在这里实现JWT令牌生成的代码
// 返回生成的JWT令牌
return "YourJwtToken";
}
}
以上示例代码演示了如何使用DocuSign的C# SDK在C#应用程序中签署PDF。你需要将示例代码中的凭证信息替换为你自己的凭证,并根据需要调整签名请求的参数。
领取专属 10元无门槛券
手把手带您无忧上云