Search code examples
pdfdocusignapi

Docusign duplicated Signature tags on all pages


I am using Docusign to add a signature my PDF documents in c#.

I have some html file, I add to end of html div with text "SignHere" that Docusign will recognize the zone for signature, but the problem that after converting html to pdf and send Docusign, I see that "SignHere" option in all pages, not the last one.

What I am wrong wrong here?

My code, after converting html to pdf file:

     if (System.IO.File.Exists(PdfPath))
                            {
      byte[] fileBytes = System.IO.File.ReadAllBytes(PdfPath);
      EnvelopeDefinition envDef = new EnvelopeDefinition();
      envDef.EmailSubject = envDefEmailSubject;
      envDef.EventNotification = new EventNotification();
      envDef.EventNotification.Url = envDefEventNotificationUrl; 
      envDef.EventNotification.LoggingEnabled = "true";
      envDef.EventNotification.IncludeDocuments = "true";
      envDef.EventNotification.RequireAcknowledgment = "true";
      envDef.EventNotification.IncludeCertificateWithSoap = "false";
      envDef.EventNotification.RequireAcknowledgment = "true";
      envDef.EventNotification.UseSoapInterface = "false";
      envDef.EventNotification.EnvelopeEvents = new List<EnvelopeEvent>();
      EnvelopeEvent envelopeEventSent = new EnvelopeEvent();
      envelopeEventSent.EnvelopeEventStatusCode = "sent";
                                       envDef.EventNotification.EnvelopeEvents.Add(envelopeEventSent);
     EnvelopeEvent envelopeEventDelivered = new EnvelopeEvent();
     envelopeEventDelivered.EnvelopeEventStatusCode = "delivered";
                                envDef.EventNotification.EnvelopeEvents.Add(envelopeEventDelivered);
     EnvelopeEvent envelopeEventSentCompleted = new EnvelopeEvent();
     envelopeEventSentCompleted.EnvelopeEventStatusCode = "completed";
     envDef.EventNotification.EnvelopeEvents.Add(envelopeEventSentCompleted);

     Document doc = new Document();
     doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes);
     doc.Name = docName;
     doc.DocumentId = docDocumentId;
     envDef.Documents = new List<Document>();
     envDef.Documents.Add(doc);

     Signer signer = new Signer();
     signer.Email = Email;
     signer.Name = signerName + LeadName;
     signer.RecipientId = signerRecipientId;
     signer.Tabs = new Tabs();

      //Custom Field For LeadId and PdfName
     envDef.CustomFields = new CustomFields();
     envDef.CustomFields.TextCustomFields = new List<TextCustomField>();
     TextCustomField textCustomFieldLeadId = new TextCustomField();
                                textCustomFieldLeadId.Name = "LeadId";
                                textCustomFieldLeadId.Value = LeadId;
                                textCustomFieldLeadId.Required = "false";
                                textCustomFieldLeadId.Name = "false";
                                envDef.CustomFields.TextCustomFields.Add(textCustomFieldLeadId);

                                TextCustomField textCustomFieldSignedPdfName = new TextCustomField();
                                textCustomFieldSignedPdfName.Name = "SignedPdfName";
                                textCustomFieldSignedPdfName.Value = SignedPdfName;
                                textCustomFieldSignedPdfName.Required = "false";
                                textCustomFieldSignedPdfName.Name = "false";
                                envDef.CustomFields.TextCustomFields.Add(textCustomFieldSignedPdfName);

                                if (SignHereExist)
                                {
        signer.Tabs.SignHereTabs = new List<SignHere>();
        SignHere signHere = new SignHere();
        signHere.RecipientId = signHereRecipientId;
        signHere.AnchorXOffset = signHereAnchorXOffset;       
        signHere.AnchorYOffset = signHereAnchorYOffset;
        signHere.AnchorIgnoreIfNotPresent = signHereAnchorIgnoreIfNotPresent;
        signHere.AnchorUnits = "inches";
        signHere.AnchorString = signHereAnchorString;
        signer.Tabs.SignHereTabs.Add(signHere);



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

        ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi");
        DocuSign.eSign.Client.Configuration cfi = new  DocuSign.eSign.Client.Configuration(apiClient);
        string authHeader = "{\"Username\":\"" + x+ "\", \"Password\":\"" + x+ "\", \"IntegratorKey\":\"" + x+ "\"}";
          cfi.AddDefaultHeader("X-DocuSign-Authentication", authHeader);

          EnvelopesApi envelopesApi = new EnvelopesApi(cfi);
          EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountID, envDef);
}

Solution

  • You are using Docusign Auto-Place (Anchor Tagging) in your request.

    signHere.AnchorString = signHereAnchorString;
    

    This will trigger a scan on the text in the document. If the scan finds the text specified in the variable signHereAnchorString anywhere in the document, it automatically places the "SignHere" option next to the text. That is the reason you are seeing "SignHere" option on all pages


    You have couple of options if you want to place the Tag only on the last page

    Option 1 - Using Anchor Tags: (See documentation here)

    • Modify your document to contain a unique string where you want to place the Signature tag. In this case, you could add the text "SignHereLastPage" in white font color (so that it isn't visible in the document) to where you want to place the Signature tag on the Document. Use "SignHereLastPage" as the anchor string.
    • You will just need to change one line in your code

      signHere.AnchorString = "SignHereLastPage";
      

    Option 2 - Fixed (or Absolute) Positioning (See documentation here)

    • You can use Absolute position of Tags and specify where you want to place the signature Tag. See Api recipe here

          signer.Tabs.SignHereTabs = new List<SignHere>();
          SignHere signHere = new SignHere();
          signHere.DocumentId =docDocumentId; 
          signHere.PageNumber = "1"; // Specify the last Page number here.
          signHere.RecipientId = signHereRecipientId;
          signHere.XPosition = "100"; //You can adjust this based on your document
          signHere.YPosition = "100"; //You can adjust this based on your document
          signer.Tabs.SignHereTabs.Add(signHere);