2014-11-07 2 views
0

jsPDF로 생성 된 PDF를 Mandrill 이메일에 첨부하려고합니다. 코드는 다음과 같습니다.jsPDF로 PDF를 생성하고 Mandrill API로 첨부하십시오.

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': '[email protected]', 
     'to': [ 
      { 
      'email': '[email protected]', 
      '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 등으로 붙이려고했지만 아무 것도 작동하지 않습니다.

PDF를 blob로 첨부하려고했지만 파일이 손상 될뿐만 아니라 실패합니다.

아이디어가 있으십니까?

감사합니다.

답변

0
"attachments": [{ 
    "type": "application/pdf", 
     "name": "quote.pdf", 
     "content": btoa(pdfOutput) 
}] 

트릭을 할해야

관련 문제