2

The specific scenario that we are attempting to solve for our API solution is to create an envelope using a template and to replace the template document with a user specified document. DocuSign's documentation on creating a composite template show the steps for the serverside template and inline templates clearly, and this functionality is working correctly for us. However, the portion of the XML string containing the alternate document does not affect the template. Here is the link to DocuSign's example followed by the code snippet regarding document portion of the composite template.

https://www.docusign.com/p/APIGuide/Content/Sending%20Group/Rules%20for%20CompositeTemplate%20Usage.htm

<Document>
    <ID>1</ID>
    <Name>Form Document</Name>
    <PDFBytes>PDF_BYTES_GO_HERE</PDFBytes>
    <TransformPdfFields>true</TransformPdfFields>
    <FileExtension>pdf</FileExtension>
</Document>

We have tried multiple variations of breaking down the pdf into bytes to insert into the "PDF_BYTES_GO_HERE" portion.

Here is the code we used to get the pdf bytes, convert them to a string and insert into the tag.

Dim fs As FileStream
    fs = File.Open(filePath, FileMode.Open)
    Dim bytes As Byte() = New Byte(fs.Length - 1) {}
    fs.Read(bytes, 0, System.Convert.ToInt32(fs.Length))
    fs.Close()
    Dim byteString As String = System.Convert.ToBase64String(bytes, 0, bytes.Length)

byteString is the string that we then use in the XML string.

"<Document>" & _
    "<documentId>1</documentId>" & _
    "<name>DOCUSIGN API TEST</name>" & _
    "<PDFBytes>" & byteString & "</PDFBytes>" & _
    "<TransformPdfFields>false</TransformPdfFields>" & _
    "<FileExtension>pdf</FileExtension>" & _
"</Document>" & _

What type of data is expected within the tag and what is the best way to convert a pdf into that data?

Larry K
  • 42,977
  • 12
  • 82
  • 121
Litmas
  • 76
  • 1
  • 8

1 Answers1

3

Based on the documentation you've linked to, and the code sample you included, it seems as though you're using the DocuSign SOAP API. If that's the case, then the DocuSign SOAP API guide will be a useful reference for you. As the guide specifies, the PDFBytes property expects a base64-encoded byte stream that represents the document contents:

Document properties

Are you manually constructing the XML payload? If so, you might instead want to consider adding a Service Reference to your project for the DocuSign WSDL, and then using the proxy classes (i.e., DocuSign object model) that come from that to construct the payload and subsequently send the envelope. If you go this route, the API guide contains code examples in a couple different languages that illustrate the setting of the PDFBytes property during Envelope creation -- starting on page 62. For example:

C#

// Attach the document(s)
envelope.Documents = new DocuSignWeb.Document[1];
DocuSignWeb.Document doc = new DocuSignWeb.Document();
doc.ID = "1";
doc.Name = "Document Name";
doc.PDFBytes = [Location of Document];
envelope.Documents[0] = doc;

PHP

// Attach the document
$doc = new Document();
$doc->ID = "1";
$doc->Name = "Picture PDF";
$doc->PDFBytes = file_get_contents("docs/picturePdf.pdf");
$env->Documents = array($doc);

Perhaps try modeling your approach after one of these examples (in VB, rather than C# or PHP)?

Kim Brandl
  • 11,964
  • 2
  • 14
  • 19
  • Thank you for your answer @Kim Brandl. I have now converted the pdf bytes into the correct format. We are actually using the REST API and have run into a slightly different problem which I have now posted as a different question. – Litmas Sep 09 '14 at 21:39