Docusign combined pdf - can we extract the individ

2019-08-03 02:23发布

问题:

We're looking at is downloading the combined pdf and then extracting the individual documents ( not my idea ). I tried using pdfsharp against my combined pdf, but I don't see any title information on the individual documents. I was just wondering if this is even possible. If I use pdfsharp, it can pull out all the pages, but I have no way of really knowing which pages belong with with document.

回答1:

After you create a DocuSign envelope you can read the document information from the envelope and remember the page counts for each document. This should also work if you are using Templates.

You can use the EnvelopeDocuments: list API to get the document information, which includes pages for each doc. Then when you need to extract the individual documents from the combined PDF you'll know where to separate the individual docs.

Here's a sample API response for the list documents call:

{
    "envelopeDocuments": [
        {
            "availableDocumentTypes": [
                {
                    "isDefault": "true",
                    "type": "electronic"
                }
            ],
            "display": "inline",
            "documentId": "1",
            "includeInDownload": "true",
            "name": "NDA.pdf",
            "order": "1",
            "pages": "3",
            "signerMustAcknowledge": "no_interaction",
            "type": "content",
            "uri": "/envelopes/44efc9e6-915e-4b1d-9b54-801410d6922d/documents/1"
        },
        {
            "availableDocumentTypes": [
                {
                    "isDefault": "true",
                    "type": "electronic"
                }
            ],
            "display": "inline",
            "documentId": "2",
            "includeInDownload": "true",
            "name": "House.pdf",
            "order": "2",
            "pages": "1",
            "signerMustAcknowledge": "no_interaction",
            "type": "content",
            "uri": "/envelopes/44efc9e6-915e-4b1d-9b54-801410d6922d/documents/2"
        },
        {
            "availableDocumentTypes": [
                {
                    "isDefault": "true",
                    "type": "electronic"
                }
            ],
            "display": "inline",
            "documentId": "3",
            "includeInDownload": "true",
            "name": "contractor_agreement.docx",
            "order": "3",
            "pages": "2",
            "signerMustAcknowledge": "no_interaction",
            "type": "content",
            "uri": "/envelopes/44efc9e6-915e-4b1d-9b54-801410d6922d/documents/3"
        },
        {
            "availableDocumentTypes": [
                {
                    "isDefault": "true",
                    "type": "electronic"
                }
            ],
            "display": "inline",
            "documentId": "certificate",
            "includeInDownload": "true",
            "name": "Summary",
            "order": "999",
            "pages": "4",
            "signerMustAcknowledge": "no_interaction",
            "type": "summary",
            "uri": "/envelopes/44efc9e6-915e-4b1d-9b54-801410d6922d/documents/certificate"
        }
    ],
    "envelopeId": "44efc9e6-915e-4b1d-9b54-801410d6922d"
}


回答2:

The getEnvelopeDocuments api has an option to download all the documents in an envelope as a zip file. You can just unzip the file and get individual documents.

GET /v2/accounts/{accountId}/envelopes/{envelopeId}/documents/archive

Retrieve a ZIP archive that contains all of the PDF documents, the certificate, and any .WAV files used for voice authentication.


Here is a sample code to download zip file and unzip it using the Docusign C# SDK.

Full Example here.

var envApi = new EnvelopesApi();

// GetDocument() API call returns a MemoryStream
var docStream = envApi.GetDocument(accountId, envelopeId, "archive");
// let's save the document to local file system
string zipName = Path.GetRandomFileName();
string zipfilePath = @"C:\temp\" + zipName + ".zip";
using (var fs = new FileStream(zipfilePath, FileMode.Create))
{
    docStream.Seek(0, SeekOrigin.Begin);
    docStream.CopyTo(fs);
}

string extractPath = @"c:\temp\" + zipName; 
System.IO.Compression.ZipFile.ExtractToDirectory(zipfilePath, extractPath);        

Edit(By Kathy-Lori)

For some reason, I had a problem casting the Stream to a FileStream object. What I did instead was the following:

Stream docStream = envApi.GetDocument(AccountId, envelopeId, "archive");
MemoryStream ret = new MemoryStream();

byte[] buffer = new byte[8192];
int bytesRead;
while ((bytesRead = docStream.Read(buffer, 0, buffer.Length)) > 0)
{
   ret.Write(buffer, 0, bytesRead);
}
ret.Position = 0;

using (var fs = new FileStream(@"C:\temp\envelopeDocuments.zip", FileMode.Create)) 
{
   ret.CopyTo(fs); 
} 


标签: docusignapi