简体   繁体   中英

DocuSign Api returning filebytes string, getting blank or corrupted file when try to convert to PDF

I'm working with the docusign api in order to get some documents from envelopes, I get all the info, but for the PDF download I get a "filebytes" string, and when trying to process it to download it, I get just a blank page (not sure if that's the expecting result since I'm using sandbox account). I'm doing all this from the client.

here's what I'm doing to process the string:

      const pdfBlob = new Blob([Buffer.from(content)], {
    type: 'application/pdf'
  });

  if (window.navigator && window.navigator.msSaveOrOpenBlob) {
    window.navigator.msSaveOrOpenBlob(pdfBlob, filename);
    resolve();
  } else {
    const tempLink = document.createElement('a');
    const url = window.URL.createObjectURL(pdfBlob);

    const clickEvent = new MouseEvent('click', {
      'view': window,
      'bubbles': true,
      'cancelable': false
    });
    tempLink.href = url;
    tempLink.target = '_blank';
    tempLink.download = filename;
    document.body.appendChild(tempLink);
    tempLink.dispatchEvent(clickEvent);
    setTimeout(() => {
      document.body.removeChild(tempLink);
      window.URL.revokeObjectURL(url);
      resolve();
    }, 100);
  }


});

Any ideas?

Here is a blog post on this topic. The Node.js code is this (you have to do this from server):

// You would need to obtain an accessToken using your chosen auth flow 
let apiClient = new ApiClient(basePath);
let config = new docusign.Configuration(apiClient);
config.addDefaultHeader('Authorization', 'Bearer ' + accessToken);
let envelopesApi = new docusign.EnvelopesApi(config); 
var accountId; // accountId for your DocuSign account
var envelopeId; // envelopeId that you are working on
// produce a ZIP file with all documents including the CoC
let results1 = await envelopesApi.GetDocument(accountId, envelopeId, 'archive', null);
// produce a PDF combining all signed documents as well as the CoC
let results2 = await envelopesApi.GetDocument(accountId, envelopeId, 'combined', null);
// produce a particular document with documentId '1'
let results3 = await envelopesApi.GetDocument(accountId, envelopeId, '1', null);
//TODO - use byte array to write or send the file for your use

If your code or this code returns an empty page, please confirm that you don't get it if you use the DocuSign web app, it's possible it is empty? Please remember encoding, this is using 64 bit encoding to get bits in the REST API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM