Search code examples
c#asp.netasp.net-coredocusignapidocusign-sdk

Set signature placeholder in existing pdf file


enter image description here

I have pdf file. Is there any way to set signature placeholder using docusign in that pdf file?

I am not sure what's wrong here. so I am adding fully code here. It is not allowing me to save so adding some more text.

public static EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, string signerClientId, string docPdf)
{
    byte[] buffer = System.IO.File.ReadAllBytes(docPdf);

    EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition();
    envelopeDefinition.EmailSubject = "Please sign this document";
    Document doc1 = new Document();

    string doc1b64 = Convert.ToBase64String(buffer);

    doc1.DocumentBase64 = doc1b64;
    doc1.Name = "Lorem Ipsum"; // can be different from actual file name
    doc1.FileExtension = "pdf";
    doc1.DocumentId = "3";

    envelopeDefinition.Documents = new List<Document> { doc1 };

    Signer signer1 = new Signer
    {
        Email = signerEmail,
        Name = signerName,
        ClientUserId = signerClientId,
        RecipientId = "1",
    };

    SignHere signHere1 = new SignHere
    {
        AnchorString = "/sn1/",
        AnchorUnits = "pixels",
        AnchorXOffset = "10",
        AnchorYOffset = "20",
    };

    Tabs signer1Tabs = new Tabs
    {
        SignHereTabs = new List<SignHere> { signHere1 },
    };
    signer1.Tabs = signer1Tabs;

    Recipients recipients = new Recipients
    {
        Signers = new List<Signer> { signer1 },
    };
    envelopeDefinition.Recipients = recipients;

    envelopeDefinition.Status = "sent";

    return envelopeDefinition;
}

Solution

  • Yes, sure, of course. Here is an article showing how to do that and here is the relevant C# code:

    https://developers.docusign.com/docs/esign-rest-api/how-to/request-signature-email-remote/

    EnvelopeDefinition env = new EnvelopeDefinition();
    env.EmailSubject = "Please sign this document set";
    
    // Create document objects, one per document
    Document doc1 = new Document();
    string b64 = Convert.ToBase64String(Document1(signerEmail, signerName, ccEmail, ccName));
    doc1.DocumentBase64 = b64;
    doc1.Name = "Order acknowledgement"; // can be different from actual file name
    doc1.FileExtension = "html"; // Source data format. Signed docs are always pdf.
    doc1.DocumentId = "1"; // a label used to reference the doc
    Document doc2 = new Document
    {
        DocumentBase64 = doc2DocxBytes,
        Name = "Battle Plan", // can be different from actual file name
        FileExtension = "docx",
        DocumentId = "2",
    };
    Document doc3 = new Document
    {
        DocumentBase64 = doc3PdfBytes,
        Name = "Lorem Ipsum", // can be different from actual file name
        FileExtension = "pdf",
        DocumentId = "3",
    };
    
    // The order in the docs array determines the order in the envelope
    env.Documents = new List<Document> { doc1, doc2, doc3 };
    
    // create a signer recipient to sign the document, identified by name and email
    // We're setting the parameters via the object creation
    Signer signer1 = new Signer
    {
        Email = signerEmail,
        Name = signerName,
        RecipientId = "1",
        RoutingOrder = "1",
    };
    
    // routingOrder (lower means earlier) determines the order of deliveries
    // to the recipients. Parallel routing order is supported by using the
    // same integer as the order for two or more recipients.
    
    // create a cc recipient to receive a copy of the documents, identified by name and email
    // We're setting the parameters via setters
    CarbonCopy cc1 = new CarbonCopy
    {
        Email = ccEmail,
        Name = ccName,
        RecipientId = "2",
        RoutingOrder = "2",
    };
    
    // Create signHere fields (also known as tabs) on the documents,
    // We're using anchor (autoPlace) positioning
    //
    // The DocuSign platform searches throughout your envelope's
    // documents for matching anchor strings. So the
    // signHere2 tab will be used in both document 2 and 3 since they
    // use the same anchor string for their "signer 1" tabs.
    SignHere signHere1 = new SignHere
    {
        AnchorString = "**signature_1**",
        AnchorUnits = "pixels",
        AnchorYOffset = "10",
        AnchorXOffset = "20",
    };
    
    SignHere signHere2 = new SignHere
    {
        AnchorString = "/sn1/",
        AnchorUnits = "pixels",
        AnchorYOffset = "10",
        AnchorXOffset = "20",
    };
    
    // Tabs are set per recipient / signer
    Tabs signer1Tabs = new Tabs
    {
        SignHereTabs = new List<SignHere> { signHere1, signHere2 },
    };
    signer1.Tabs = signer1Tabs;
    
    // Add the recipients to the envelope object
    Recipients recipients = new Recipients
    {
        Signers = new List<Signer> { signer1 },
        CarbonCopies = new List<CarbonCopy> { cc1 },
    };
    env.Recipients = recipients;
    
    // Request that the envelope be sent by setting |status| to "sent".
    // To request that the envelope be created as a draft, set to "created"
    env.Status = envStatus;
    
    return env;