2017-07-25 54 views
0

我在我的应用程序中实现DocuSign功能来签署PDF。 我正在关注以下链接: https://www.docusign.com/developer-center/api-overview 我们能够在使用上述链接中提到的步骤的同时在PDF中添加签名,但在第二次调用相同方法签署新的PDF时,我们会收到错误消息CreateEnvelope()在DotNet应用程序中使用DocuSign时出现错误

错误响应的线:{ “的errorCode”: “UNSPECIFIED_ERROR”, “消息”: “输入字符串的不正确的格式。” }

它在创建信封时产生错误。在这一行

EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId,envDef);

下面是我使用

static string userName = Utility.GetConfigValue("docSignUserName"); 
     static string password = Utility.GetConfigValue("docSignPassword"); 
     static string integratorKey = Utility.GetConfigValue("docSignIntegratorKey"); 
     static string baseURL = ""; 

     public static SignedPDF SignDocument(UserViewModel user, StateViewModel state, string signFilePath, string newFilePath, string controlSign) 
     { 
      PdfReader pdfReader = new PdfReader(signFilePath); 
      PdfReader newpdfReader = new PdfReader(newFilePath); 
      PdfStamper pdfStamper = new PdfStamper(newpdfReader, new FileStream(HttpContext.Current.Server.MapPath(Utility.GetConfigValue("StateTaxForms")) + "Test.pdf", FileMode.Create)); 
      AcroFields pdfFormFields = pdfStamper.AcroFields; 
      IList<AcroFields.FieldPosition> fieldPositions = pdfFormFields.GetFieldPositions(controlSign); 

      try 
      { 
       AcroFields.FieldPosition fieldPosition = fieldPositions[0]; 

       // Enter recipient (signer) name and email address 
       string recipientName = user.FirstName + " " + user.LastName; 
       string recipientEmail = user.Email; 

       // instantiate api client with appropriate environment (for production change to www.docusign.net/restapi) 
       string basePath = Utility.GetConfigValue("docSignInstantiateClient"); 

       // instantiate a new api client 
       ApiClient apiClient = new ApiClient(basePath); 

       // set client in global config so we don't need to pass it to each API object 
       Configuration.Default.ApiClient = apiClient; 

       string authHeader = "{\"Username\":\"" + userName + "\", \"Password\":\"" + password + "\", \"IntegratorKey\":\"" + integratorKey + "\"}"; 
       Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader); 

       // we will retrieve this from the login() results 
       string accountId = null; 

       // the authentication api uses the apiClient (and X-DocuSign-Authentication header) that are set in Configuration object 
       AuthenticationApi authApi = new AuthenticationApi(); 
       LoginInformation loginInfo = authApi.Login(); 

       // user might be a member of multiple accounts 
       accountId = loginInfo.LoginAccounts[0].AccountId; 

       // Read a file from disk to use as a document 
       byte[] fileBytes = File.ReadAllBytes(signFilePath); 

       EnvelopeDefinition envDef = new EnvelopeDefinition(); 
       envDef.EmailSubject = "Please sign this document"; 

       // Add a document to the envelope 
       Document doc = new Document(); 
       doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes); 
       doc.Name = "SignedFile.pdf"; 
       doc.DocumentId = "1"; 

       envDef.Documents = new List<Document>(); 
       envDef.Documents.Add(doc); 

       // Add a recipient to sign the documeent 
       Signer signer = new Signer(); 
       signer.Name = recipientName; 
       signer.Email = recipientEmail; 
       signer.RecipientId = "1"; 

       // must set |clientUserId| to embed the recipient 
       signer.ClientUserId = "1234"; 

       // Create a |SignHere| tab somewhere on the document for the recipient to sign 
       signer.Tabs = new Tabs(); 
       signer.Tabs.SignHereTabs = new List<SignHere>(); 
       SignHere signHere = new SignHere(); 

       var height = pdfReader.GetPageSize(1).Height; 
       signHere.DocumentId = "1"; 
       signHere.RecipientId = "1"; 
       signHere.PageNumber = Convert.ToInt32(fieldPosition.page).ToString(); 
       signHere.XPosition = Convert.ToInt32(fieldPosition.position.Left).ToString(); 
       if (state.Abbreviation == "DC" && controlSign != "Signature of Employee") 
       { 
        signHere.YPosition = (height - Convert.ToInt32(fieldPosition.position.Top - 5)).ToString(); 
       } 
       else 
       { 
        signHere.YPosition = (height - Convert.ToInt32(fieldPosition.position.Top + 35)).ToString(); 
       } 
       if (state.Abbreviation == "NC" && controlSign != "Signature of Employee") 
       { 
        signHere.YPosition = (height - Convert.ToInt32(fieldPosition.position.Top + 25)).ToString(); 
       } 
       signer.Tabs.SignHereTabs.Add(signHere); 

       envDef.Recipients = new Recipients(); 
       envDef.Recipients.Signers = new List<Signer>(); 
       envDef.Recipients.Signers.Add(signer); 

       // set envelope status to "sent" to immediately send the signature request 
       envDef.Status = "sent"; 

       // Use the EnvelopesApi to create and send the signature request 
       EnvelopesApi envelopesApi = new EnvelopesApi(); 
       EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef); 

       RecipientViewRequest viewOptions = new RecipientViewRequest() 
       { 
        ReturnUrl = Utility.GetConfigValue("docSignReturnURL"), 
        ClientUserId = "1234", // must match clientUserId set in step #2! 
        AuthenticationMethod = "email", 
        UserName = recipientName, 
        Email = recipientEmail 
       }; 

       // create the recipient view (aka signing URL) 
       ViewUrl recipientView = envelopesApi.CreateRecipientView(accountId, envelopeSummary.EnvelopeId, viewOptions); 

       // Start the embedded signing session! 
       //var value = System.Diagnostics.Process.Start(recipientView.Url); 
       SignedPDF signedPDF = new SignedPDF(); 
       signedPDF.URL = recipientView.Url; 
       signedPDF.EnvelopeID = envelopeSummary.EnvelopeId; 
       return signedPDF; 
      } 
      catch (Exception ex) 
      { 
       throw new PDFSignException(ErrorConstants.THERE_WAS_AN_ERROR_WHILE_SIGNING_PDF); 
      } 
      finally 
      { 
       pdfStamper.Close(); 
       pdfReader.Close(); 
      } 
     } 

您好CodingDawg这是JSON

{ 
    "documents": [ 
    { 
     "documentBase64": "", 
     "documentId": "1", 
     "name": "SignedFile.pdf" 
    } 
    ], 
    "emailSubject": "Please sign this document", 
    "recipients": { 
    "signers": [ 
     { 
     "clientUserId": "1234", 
     "email": "[email protected]", 
     "name": "Sagar Mali", 
     "recipientId": "1", 
     "tabs": { 
      "signHereTabs": [ 
      { 
       "documentId": "1", 
       "pageNumber": "1", 
       "recipientId": "1", 
       "xPosition": "192", 
       "yPosition": "679.968" 
      } 
      ] 
     } 
     } 
    ] 
    }, 
    "status": "sent" 
} 

我们已经移除了基座64的字符串作为长度不支持的代码。

+0

请添加您的代码。 –

+0

请澄清您的具体问题或添加其他详细信息,以突出显示您的需要。正如目前所写,很难确切地说出你在问什么。请参阅[如何提问](https://stackoverflow.com/help/how-to-ask)页面以获得澄清此问题的帮助。 –

+0

“XPosition”和“YPosition”的最终价值是什么? –

回答

1

确保signHere.XPosition & signHere.YPosition值正确传递。

以下语句可以计算为十进制值。确保它是一个整数。

signHere.YPosition = (height - Convert.ToInt32(fieldPosition.position.Top + 25)).ToString(); 

故障排除步骤

请运行envelopeDefinition.ToJson()(SDK documentation),并确保最终的Json发布到的DocuSign API是正确的。

相关问题