【发布时间】:2015-01-04 02:16:03
【问题描述】:
我正在尝试将生成的带有 jsPDF 的 PDF 附加到 Mandrill 电子邮件。代码如下:
doc.addHTML($('#pdfTarget').get(0), function() {
var pdfOutput = doc.output();
$.ajax({
type: 'POST',
url: 'https://mandrillapp.com/api/1.0/messages/send.json',
data: {
'key': 'my_key',
'message': {
'from_email': 'recipient@gmail.com',
'to': [
{
'email': 'email@gmail.com',
'name': 'Test',
'type': 'to'
}
],
'autotext': 'true',
'subject': 'Here is your PDF',
'html': 'This is your PDF!',
"attachments": [
{
"type": "application/pdf;base64",
"name": "your_pdf.pdf",
"content": Base64.encode(pdfOutput)
}
]
}
}
}).done(function(response) {
console.log(response); // if you're into that sorta thing
});
});
如果我运行 doc.save() 生成的 PDF 将被下载并正确保存。但是,如果我使用 doc.output() 并将结果用作电子邮件附件,则文件将被损坏。如果我像示例中那样对输出进行 Base64 编码,则附加的 PDF 不会损坏,但会显示为空白。我已经通过 Base64 编码来回修改,在实际的电子邮件 HTML 中附加为 an 等等 - 但没有任何效果。
我也尝试将 PDF 作为 blob 附加,但失败了,文件也会损坏。
有什么想法吗?
谢谢!
【问题讨论】: