我正在尝试将生成的 PDF 与 jsPDF 附加到 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 编码来回修改,在实际的 e-mail HTML 中附加等等 - 但没有任何作用。
我也尝试将 PDF 附加为 blob,但是失败了,文件也会被破坏。
有任何想法吗?
谢谢!
1 回答
应该做的伎俩