Best way to send docusign replaceable contracts - node.js

What is the best way to send docusign contracts in a way that allows them to be editable during the envelope creation process?
See in DocuSign Documentation, we can see how to create documents and then attach them to the envelope:
docPdfBytes = fs.readFileSync(path.resolve('demoDocsPath', 'pdf1File.pdf'));
// add the documents
let doc1 = new docusign.Document()
, doc1b64 = Buffer.from(docPdfBytes).toString('base64')
;
doc1.documentBase64 = doc1b64;
doc1.name = 'Lorem Ipsum'; // can be different from actual file name
doc1.fileExtension = 'pdf';
doc1.documentId = '3';
An alternative that I found and that allows you to send a document where it is possible to make 'replaces' to fill in things like "name, address" is to save HTML in a string, instead of a pure PDF.
Docusign requires you to convert my file to base64, which will be transformed at the end of the request into a final PDF with the docusign configuration. The problem is when there are images in the HTML file, during HTML conversion -> 64 -> PDF, the images are not treated in a faithful way, for example, when there is a watermark, the PDF returns a page with the watermark and the misaligned body, see the example: expected and what i have.
Is there a better way to send replaceable documents? If not, how can you force the final PDF to respect CSS properties?

There are several techniques for creating custom documents. See my SO Answer
With regards to your question:
Base64 is an encoding technique. It has zero impact on the document.
The real issue you're facing is that the DocuSign conversion from HTML to PDF is not as sophisticated as your use case needs. For these types of use cases, I recommend that you create the PDF yourself.
There are many PDF creation libraries that enable your software to create exactly the PDF that you want.
If you only need to customize a form, you can use DocuSign tags (fields) to hold the dynamic data. Your application can set tags to have values from your data and either allow or not allow the document recipients to change the data as part of the signing process.
You can use an HTML original to specify the tags (see my other answer), or you can add the tags to your PDF document. Best is to use anchor text for that.

Related

DocuSign what are the special fields I can add to Word documents to use via the API

I am testing the Docusign API and I can send a document to sign and get it signed in the position I want using the SignHere data structure and setting the AnchorString.
I want to add a field for the signed date but what is the format and field name required. I can't see anywhere that tells me how to type these into a Word document.
I see you can create templates online using Docusign and put in these fields but I don't see how that will work for us. The document will be dynamically created by our document assembly system and then sent via the Docusign API so I need to build in the fields at that point when I add the signature anchor string.
So what is the Word document special field format and list of Docusign available fields please?
Also it would be good to know how to insert a field to ask the signer to enter some text. Any entry box.
Thanks for any help.
If you're using Salesforce to send out these documents, the DocuSign CLM product supports template codes in Word. See docs.
Otherwise, you can only specify locations of fields (tabs) in the Word doc. This is done via anchor strings also known as auto-place fields. Docs.
Placing the anchor strings in your Word doc is the first step. For the second step, I recommend that you create a DocuSign template by using the DocuSign web tool. Then, when you send the document via the API, you combine it with the template. Or better, you can insert the Word document into the template itself.
The advantage of this technique is that your business users, with the right instructions, can update the template by themselves.
An alternative is for the DocuSign API request to specify the document and the various fields (tabs) that should be included in the document for the signers.
Added
Two other options:
Create your source documents as HTML documents. You can include special tags to indicate different types of DocuSign fields. You can also indicate sections of documents that can be expanded/closed by the signer. HTML field documentation.
This is the best approach, IMHO.
Create your source documents as PDF Forms with form fields. DocuSign can then transform the PDF form fields into DocuSign form fields. There are limitations. Docs.

DocuSign: How do I dynamically replace placeholders in our source document?

We are attempting to use the DocuSign API for eSignatures on items such as leases & automatic billing authorizations. What I have are a set of .rtf documents provided to me by our legal team, and there are certain sections that need to be replaced dynamically. I have looked through the DocuSign REST API docs, and I think what we are supposed to be using are text tags. Ware using the PHP SDK. I have not set this document up as a template, as it would be great if we could just use a local file on the filesystem and then have placeholders automatically replaced by values specified in our payload.
What we would like to do is have fields in our documents (such as TenantName and TenantAddress) that we can assign values to, and have DocuSign dynamically replace these placeholders with the values we specify. I have tried doing this using Text Tabs, but the values are not being replaced. Here is a code sample:
$document = new Document([
'document_base64' => $b64fc, // base64_encoded value of file_get_contents('path/to/document.pdf')
'name' => 'Autobill Form',
'file_extension' => 'pdf',
'document_id' => '1',
]);
$tag1 = new Text();
$tag1->setTabLabel('TenantName');
$tag1->setValue('Joe Signer');
$tag1->setLocked(true);
$tag1->setDocumentId('1');
$tag1->setPageNumber('1');
$tag2 = new Text();
$tag2->setTabLabel('TenantAddress');
$tag2->setValue('123 Main St.');
$tag2->setLocked(true);
$tag2->setDocumentId('1');
$tag2->setPageNumber('1');
$tabs = new Tabs();
$tabs->setTextTabs([$tag1, $tag2]);
$document->setTabs($tabs);
// other code to set up recipients, envelopes, and get an embedded signing url
When I view the document, these fields are not replaced, and still have their placeholder values. I don't want to use anchors as I need the placeholder to be removed and replaced by DocuSign. I have also tried setting the text tabs on the Signer object, but that did not work either.
What am I doing wrong? This seems like it would be a fairly common use case for the DocuSign API, but I haven't been able to figure this out.
As Inbar states, the DocuSign eSignature API doesn't allow you to modify the underlying document. You'd need to external tooling to prepare the document prior to passing it into the API Call.
That said, one possible option would be to have blank spaces in your document that align with Text tabs. If you pre-populate those tags and set them to be read-only, the placeholders tags will burn-in during the signing session. Spacing, alignment, and font likely won't be perfect, but with some adjustment you can do okay.

Is it possible to conditionally display DocuSign template parts/sections?

I would like to know if it is possible to show/hide parts of DocuSign document template depending on the data which is passed in as a request.
I already have document template created and uploaded to DocuSign. I then use templateId to create envelope for that document and I also send some data (as json) to prepopulate certain fields inside the envelope.
The thing I am asking now is:
If the template has, let's say, 3 paragraphs, is it possible to hide one of them completely, based on the passed in json data?
Creating and uploading multiple templates is not an option due to large number of conditionally displayed sections.
I have been reading DocuSign API documentation, but couldn't find an answer to this.
To do that you will have to use Responsive Signing.
This feature change the format of the document you sign from PDF to HTML.
With HTML being the format, there are a lot more things you can do.
For example, you can use what we call "Smart Sections" which is exactly what you want. Sections that can be shown off/on based on logic you set.
Find out more about the responsive signing API here - https://developers.docusign.com/esign-rest-api/guides/responsive-signing/api-overview

Set recipient in Composite Template

I use Foxit Phantom for pre-fill tabs to documents. I use PDF form with label DocuSignSignHere. But, How to set recipient using this technique?
https://www.docusign.com/p/APIGuide/Content/Sending%20Group/Rules%20for%20CompositeTemplate%20Usage.htm
I tried to set number after label: DocuSignSignHere 1, DocuSignSignHere 2. It does not work. Is it possible? How to set recipientID with PDF Form?
You can not set DocuSign recipient information through the PDF fields of the document you want to get signed. Instead you need to set that information in the API call you make to DocuSign, inside the JSON properties of your request body.
Here is a full code sample (in 6 languages) of how to request a signature on a local document:
http://iodocs.docusign.com/APIWalkthrough/requestSignatureFromDocument
And make sure you check out the other 8 API Walkthroughs here.
In our way solution was in using Automatic Anchor Text with Custom Tags

Can't migrate RichText to RichText in XPages

I have an old Notes Client application. On the form are two RichText fields that hold attachments. JPG's, PDF's, whatever. The document also contains a unique key and other meta-data.
What I want to do is migrate from having multiple attachments on a document to a new document for each attachment. I've never done much with embedded objects and even less with MIME.
I'm currently working in XPages Java but could go to LotusScript if need be.
I was working with this snippet:
List<EmbeddedObject> docPicture = this.getFileAttachments(doc, "picture");
List<EmbeddedObject> docPDF = this.getFileAttachments(doc, "pdf");
for (EmbeddedObject eoPic : docPicture) {
picCount++;
Document newDoc = currentDatabase.createDocument();
newDoc.replaceItemValue("form", "fm_file");
newDoc.replaceItemValue("uploadToken", doc.getItemValueString("barCodeHuman"));
newDoc.replaceItemValue("fileName", eoPic.getName());
newDoc.replaceItemValue("size", eoPic.getFileSize());
fileName = eoPic.getName();
fileType = fileName.substring(fileName.length() - 3);
newDoc.replaceItemValue("type", this.getMIMEType(fileType));
// Extract Attachment and Add To Attachment Document
InputStream attachInputStream = eoPic.getInputStream();
Stream attachStream = session.createStream();
attachStream.setContents(attachInputStream);
MIMEEntity attachField = newDoc.createMIMEEntity("attachment");
MIMEHeader attachHeader = attachField.createHeader("content-disposition");
attachHeader.setHeaderVal("attachment;filename=\"" + eoPic.getName() + "\"");
attachField.setContentFromBytes(attachStream, this.getMIMEType(fileType), MIMEEntity.ENC_IDENTITY_BINARY);
Note I'm using the OpenNTF API but could go back to the lotus objects if need be.
Anyway - this almost worked. I got my documents - 1 per attachment. But when going into the field "attachment" in the document propertied it's not a RichTextField it's a MIME something. that's causing me probably with the next phase of my project. The RichTextDocuments work fine but not the MIME ones.
this is a 1 time migration need so any thoughts on how I can end up with RichTextFields would be appreciated. Thanks!!
try to not involve mime entities at all.
as Oliver said, check your target richText field on the form does not have the 'store contents as mime' checked.
you could even use a richText lite field and restrict it to attachments.
I think you might be using the MIMEEntity method setContentsFromStream because you want to directly move the attachment from doc to doc?
if you want to move using just RichText embedded objects (no mime entity involvement) you need to extract the embeddedObject using .extractFile to the file system first.
Then using the RichTextItem that you create on the new doc (instead of create mime entity) you can use rti.embedObject to attach the file you extracted. (probably best to delete the temporary extract file after successful migration), see the designer help for an example of the parameters required for embedding attachments.
when extracting the file to file system you could extract it to the JVM's temporary directory, the file on the file system needs to have the same file name that you want it to have when attached to the new document.
for this reason you can't really use File.createTemporaryFile() because your temp file name will have random characters in it. instead you
you can get the temp directory with
System.getProperty("java.io.tmpdir")`
and the use that in your extract filepath.
another thing to check before starting processing, is the current notesSession's isConvertMIME setting, if to source field is mime, session.isConvertMIME == true will convert the field to richText when loading the doc. I think in xpages it is false by default, though I don't think it will affect you because I think your source attachments are already richText but for someone reading this and using mime source field it would be important to note. also if you change this using setConvertMIME, be sure to change it back to what it was when you finish your processing.

Resources