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

Cordova. Email a pdf generated by 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 电子邮件编辑器插件完成的

我找到了答案。因此,您必须根据逗号拆分 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。我希望这对正在研究相同问题的任何人有所帮助。