首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何在C#中使用DocuSign应用程序接口签名PDF?

在C#中使用DocuSign应用程序接口(API)签名PDF可以通过以下步骤实现:

  1. 首先,你需要注册一个DocuSign开发者账号,并创建一个应用程序。在创建应用程序时,你将获得一个集成密钥和其他必要的凭证,这些凭证将用于在代码中进行身份验证和授权。
  2. 接下来,你需要安装DocuSign API的C# SDK(软件开发工具包)。你可以在GitHub上找到DocuSign的C# SDK,并将其添加到你的项目中。该SDK提供了与DocuSign API进行通信所需的类和方法。
  3. 在你的C#代码中,你需要使用SDK提供的类和方法来实现签名PDF的功能。具体而言,你需要使用SDK提供的类来创建一个签名请求,并设置签名所需的参数,如签名位置、签名者信息等。然后,你可以使用SDK提供的方法将签名请求发送给DocuSign API,并获得一个签署URL。
  4. 在收到签署URL后,你可以将其嵌入到你的应用程序中的页面中,或将其发送给需要签署PDF的用户。用户点击该URL后,将跳转到DocuSign的签署页面,并可以在页面上进行签署操作。
  5. 一旦用户完成签署,你可以使用SDK提供的方法来验证签名状态和获取签署后的PDF文件。你可以选择将签署后的PDF保存到本地、发送给其他人,或根据需要进行其他后续操作。

请注意,DocuSign提供了丰富的文档和示例代码,详细介绍了如何使用其API进行PDF签名。以下是一些相关的资源:

  • DocuSign开发者中心:https://developers.docusign.com/
  • DocuSign API C# SDK GitHub页面:https://github.com/docusign/docusign-csharp-client
  • C# SDK文档和示例:在GitHub页面中,你可以找到详细的文档和示例代码,帮助你更好地理解和使用C# SDK。
  • C#中使用DocuSign API的签名PDF的示例代码:
代码语言:txt
复制
// 引入必要的命名空间
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。你需要将示例代码中的凭证信息替换为你自己的凭证,并根据需要调整签名请求的参数。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

领券