科尔多瓦。通过电子邮件发送jsPDF生成的pdf

时间:2015-07-01 15:31:51

标签: cordova email pdf mobile jspdf

当我尝试以与此格式相同的格式通过电子邮件发送pdf生成的pdf时:

var pdf = new jsPDF();
pdf.text(0, 0, 'Hello World!');
var pdfBase64 = pdf.output('datauristring');

window.plugin.email.open({
  to: ['to@email.com'],
  subject: 'New PDF!',
  body: 'Hi there, here is that new PDF you wanted!',
  isHTML: false,
  attachments: [pdfBase64]
});`

它正确地打开了电子邮件应用程序,但随后给出了一个错误,即无法附加pdf。有谁知道这背后的原因?这是使用jsPDF和cordova电子邮件编辑器插件

完成的

1 个答案:

答案 0 :(得分:1)

我找到了答案。因此,您必须基于逗号分割datauri,然后在连接数组元素之前将字符串base64附加到它前面。我做了类似的事。

var doc = new jsPDF();
doc.text(20, 20, 'Hello world!');
doc.text(20, 30, 'This is client-side Javascript, pumping out a PDF.');
doc.addPage();
doc.text(20, 20, 'From within Cordova.');
var uristring = doc.output('datauristring');
var uristringparts = uristring.split(',');
uristringparts[0] = "base64:" + escape('sample.pdf') + "//";

var moddeduristring =  uristringparts.join("");
return moddeduristring;

以这种方式成功附加电子邮件pdf。我希望这可以帮助那些正在研究同样问题的人。