docusign / docusign-esign-node-client

The Official DocuSign Node.js Client Library used to interact with the eSign REST API. Send, sign, and approve documents using this client.
http://docusign.github.io/docusign-esign-node-client
MIT License
145 stars 100 forks source link

How to generate document from PDFBytes received in call back? #255

Open krrajiv opened 3 years ago

krrajiv commented 3 years ago

We need to publish the completed to s3, in the callback response, I see the value of the document in req.body.envelopeDocuments[0].PDFBytes Can someone help me with how to convert this to file? Tried using fs.writeFileSync('random.pdf',req.body.envelopeDocuments[0].PDFBytes) and fs.writeFileSync('random.pdf',Buffer.from(req.body.envelopeDocuments[0].PDFBytes)) and fs.writeFileSync('random.pdf',Buffer.from(req.body.envelopeDocuments[0].PDFBytes, 'base64')) all of this seems to generate empty PDF only. how to get the actual completed document?

LarryKlugerDS commented 3 years ago

See https://github.com/docusign/code-examples-node/blob/master/lib/eSignature/eg007EnvelopeGetDoc.js#L108

That example shows you how to download the document. Remember that it is a binary file. If you have trouble uploading it to S3, I suggest asking on StackOverflow.

judemcenerny commented 5 months ago

Answer to original question is still needed. I do not need to implement downloading the file another way. I have the file contents, pushed via web hook. I tried decoding it as base64 and writing that as binary, but the file is not openable, says "damaged."

How does one take the string contents of the PDFBytes and convert and write to a file which can then be opened as PDF file?