DocuSign Java Rest Api - Combining Anchor Tagged Custom File and PDF Form Field Transformation (Composite Templates)

瘦欲@ 提交于 2019-12-02 04:03:18

When you specify a Composite Template in the Envelope definition, only the information specified in the CompositeTemplate will be used to create the envelope.

For your scenario you can use two CompositeTemplates and specify the same signer in both of them. For the PDF form fields to be recognized, you will have to set the "DefaultRecipient" property on the signer to true.

You can specify each of your document in its own CompositeTemplate. This will ensure both your documents are present in the envelope.

I have updated your code

// create a new envelope to manage the signature request
EnvelopeDefinition envDef = new EnvelopeDefinition();       
envDef.setEmailSubject(documentName);

// add a document to the envelope
Document doc = new Document();          
doc.setDocumentBase64(Base64.getEncoder().encodeToString(fileBytes)); //custom file
doc.setName(documentName); 

//this is the objectid of the ElectronicDocument
doc.setDocumentId(ElectronicDocumentId); 

Signer signer = new Signer(); 
signer.setEmail(primarySignerEmail);
signer.setName(primarySignerName);
signer.setRecipientId(primarySignerId); 
signer.setAccessCode(primaryAuthCode); 
signer.setDefaultRecipient("true");
signer.setRoleName("PrimaryTenant"); //so we attach them to w9template


////create tab code not included

//create the tabs and assign to signer
Tabs tabs = new Tabs();
tabs.setSignHereTabs(signHereTabs); 
tabs.setInitialHereTabs(initialHereTabs);
tabs.setDateSignedTabs(dateSignedTabs);
signer.setTabs(tabs);

CompositeTemplate compositeTemplate1 = new CompositeTemplate();
InlineTemplate inlineTemplate1 = new InlineTemplate();
inlineTemplate1.setSequence("1");

compositeTemplate1.document(doc);

inlineTemplate1.setRecipients(new Recipients());
inlineTemplate1.getRecipients().setSigners(new ArrayList<Signer>());
inlineTemplate1.getRecipients().getSigners().add(signer);

List<InlineTemplate> inlineTemplateList1 = new ArrayList<InlineTemplate>();
inlineTemplateList1.add(inlineTemplate1);
compositeTemplate.inlineTemplates(inlineTemplateList1);

 List<CompositeTemplate> compositeTemplateList = new ArrayList<CompositeTemplate>();
 compositeTemplateList.add(compositeTemplate1);


 Blob     blob = w9Template.getFileBlob();
 int blobLength;
 try 
 {
    blobLength = (int) blob.length();
    w9Bytes = blob.getBytes(1, blobLength);     
    blob.free();
 } catch (SQLException e) {
    logger.warn(e);
 }  

if (w9Bytes != null)
{
    //create compositTemplate for w-9
    CompositeTemplate compositeTemplate2 = new CompositeTemplate();
    InlineTemplate inlineTemplate2 = new InlineTemplate();
    inlineTemplate2.setSequence("2");


    //create w-9 document
    Document docw9 = new Document();    
    docw9.setDocumentBase64(Base64.getEncoder().encodeToString(w9Bytes));
    docw9.setName("W-9");               
    docw9.setDocumentId(ElectronicDocumentId); 
    docw9.transformPdfFields("true");

    compositeTemplate2.document(docw9);

    Signer signer2 = new Signer(); 
    signer2.setEmail(primarySignerEmail);
    signer2.setName(primarySignerName);
    signer2.setRecipientId(primarySignerId); 
    signer2.setAccessCode(primaryAuthCode);
    signer2.setDefaultRecipient("true");

    inlineTemplate2.setRecipients(new Recipients());
    inlineTemplate2.getRecipients().setSigners(new ArrayList<Signer>());
    inlineTemplate2.getRecipients().getSigners().add(signer2);

    List<InlineTemplate> inlineTemplateList2 = new ArrayList<InlineTemplate>();
    inlineTemplateList2.add(inlineTemplate);
    compositeTemplate2.inlineTemplates(inlineTemplateList2);

    compositeTemplateList.add(compositeTemplate2); 
}

envDef.setCompositeTemplates(compositeTemplateList); 



// send the envelope by setting |status| to "sent". To save as a draft set to "created"
envDef.setStatus("sent");

try
{               
    // instantiate a new EnvelopesApi object
    EnvelopesApi envelopesApi = new EnvelopesApi();

   // call the createEnvelope() API
   // use the |accountId| we retrieved through authenticate() function to      create the Envelope
    EnvelopeSummary envelopeSummary = envelopesApi.createEnvelope(accountId, envDef);
        logger.debug("EnvelopeSummary: " + envelopeSummary);
}
catch (com.docusign.esign.client.ApiException ex)
{

} 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!