DocuSign API 返回文件字节字符串,尝试转换为 PDF 时获得空白或损坏的文件



我正在使用 docusign api 以便从信封中获取一些文档,我得到了所有信息,但对于 PDF 下载,我得到了一个"filebytes"字符串,当尝试处理它以下载它时,我只得到一个空白页(不确定这是否是预期的结果,因为我使用的是沙盒帐户(。我正在从客户那里做这一切。

这是我处理字符串的方法:

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);
}

});

有什么想法吗?

这是一篇关于这个主题的博客文章。 Node.js 代码是这样的(你必须从服务器执行此操作(:

// 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

如果您的代码或此代码返回一个空页面,请确认您没有收到它 如果您使用 DocuSign 网络应用程序,它可能是空的吗? 请记住编码,这是使用 64 位编码来获取 REST API 中的位。

最新更新