DocuSign Java Rest Api - 结合锚标记自定义文件和 PDF 表单字段转换(复合模板)
DocuSign Java Rest Api - Combining Anchor Tagged Custom File and PDF Form Field Transformation (Composite Templates)
在我的应用程序中,我有一个 PDF 包,我将它们合并并发送到 DocuSign。这可以完美地使用 SignHere 和 Initial here AnchorTags;但是,我现在需要包含某些需要用户输入字段的 PDF(例如 W-9 表格)。我尝试了多种创建模板的方法,但都没有成功。我已经能够让 DocuSign 识别所有 PDF 表单字段(在模板 UI 中),但我无法将这些字段提供给用户。
我有两个重要问题:
首先,我无法让 DocuSign 在收件人的文档中包含我的自定义文件和我使用输入字段创建的模板。
我能够将 W-9 模板发送给收件人(但不是自定义文件),但没有任何输入字段或标签。
我已经在下面粘贴了我的代码
// 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);
List<Document> docs = new ArrayList<Document>();
docs.add(doc);
envDef.setDocuments(docs);
Signer signer = new Signer();
signer.setEmail(primarySignerEmail);
signer.setName(primarySignerName);
signer.setRecipientId(primarySignerId);
signer.setAccessCode(primaryAuthCode);
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);
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 compositeTemplate = new CompositeTemplate();
InlineTemplate inlineTemplate = new InlineTemplate();
inlineTemplate.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");
compositeTemplate.document(docw9);
inlineTemplate.setRecipients(new Recipients());
inlineTemplate.getRecipients().setSigners(new ArrayList<Signer>());
inlineTemplate.getRecipients().getSigners().add(signer);
List<InlineTemplate> inlineTemplateList = new ArrayList<InlineTemplate>();
inlineTemplateList.add(inlineTemplate);
compositeTemplate.inlineTemplates(inlineTemplateList);
List<CompositeTemplate> compositeTemplateList = new ArrayList<CompositeTemplate>();
compositeTemplateList.add(compositeTemplate);
envDef.setCompositeTemplates(compositeTemplateList);
}
// add recipient(s) to the envelope
envDef.setRecipients(new Recipients());
envDef.getRecipients().setSigners(new ArrayList<Signer>());
envDef.getRecipients().getSigners().add(signer);
// 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)
{
}
提前感谢您的努力。我整天都在想办法解决这个问题。
当您在信封定义中指定复合模板时,只有在复合模板中指定的信息才会用于创建信封。
对于您的方案,您可以使用两个 CompositeTemplates 并在其中指定相同的签名者。要识别 PDF 表单字段,您必须将签名者上的 "DefaultRecipient" 属性 设置为 true。
您可以在自己的 CompositeTemplate 中指定每个文档。这将确保您的两份文件都在信封中。
我已经更新了你的代码
// 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)
{
}
在我的应用程序中,我有一个 PDF 包,我将它们合并并发送到 DocuSign。这可以完美地使用 SignHere 和 Initial here AnchorTags;但是,我现在需要包含某些需要用户输入字段的 PDF(例如 W-9 表格)。我尝试了多种创建模板的方法,但都没有成功。我已经能够让 DocuSign 识别所有 PDF 表单字段(在模板 UI 中),但我无法将这些字段提供给用户。
我有两个重要问题:
首先,我无法让 DocuSign 在收件人的文档中包含我的自定义文件和我使用输入字段创建的模板。
我能够将 W-9 模板发送给收件人(但不是自定义文件),但没有任何输入字段或标签。
我已经在下面粘贴了我的代码
// 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);
List<Document> docs = new ArrayList<Document>();
docs.add(doc);
envDef.setDocuments(docs);
Signer signer = new Signer();
signer.setEmail(primarySignerEmail);
signer.setName(primarySignerName);
signer.setRecipientId(primarySignerId);
signer.setAccessCode(primaryAuthCode);
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);
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 compositeTemplate = new CompositeTemplate();
InlineTemplate inlineTemplate = new InlineTemplate();
inlineTemplate.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");
compositeTemplate.document(docw9);
inlineTemplate.setRecipients(new Recipients());
inlineTemplate.getRecipients().setSigners(new ArrayList<Signer>());
inlineTemplate.getRecipients().getSigners().add(signer);
List<InlineTemplate> inlineTemplateList = new ArrayList<InlineTemplate>();
inlineTemplateList.add(inlineTemplate);
compositeTemplate.inlineTemplates(inlineTemplateList);
List<CompositeTemplate> compositeTemplateList = new ArrayList<CompositeTemplate>();
compositeTemplateList.add(compositeTemplate);
envDef.setCompositeTemplates(compositeTemplateList);
}
// add recipient(s) to the envelope
envDef.setRecipients(new Recipients());
envDef.getRecipients().setSigners(new ArrayList<Signer>());
envDef.getRecipients().getSigners().add(signer);
// 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)
{
}
提前感谢您的努力。我整天都在想办法解决这个问题。
当您在信封定义中指定复合模板时,只有在复合模板中指定的信息才会用于创建信封。
对于您的方案,您可以使用两个 CompositeTemplates 并在其中指定相同的签名者。要识别 PDF 表单字段,您必须将签名者上的 "DefaultRecipient" 属性 设置为 true。
您可以在自己的 CompositeTemplate 中指定每个文档。这将确保您的两份文件都在信封中。
我已经更新了你的代码
// 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)
{
}