Cordova 科尔多瓦。通过电子邮件发送jsPDF生成的pdf
当我尝试通过电子邮件发送pdf生成的pdf时,格式如下:Cordova 科尔多瓦。通过电子邮件发送jsPDF生成的pdf,cordova,email,pdf,mobile,jspdf,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 wa
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 email composer插件完成的,我找到了答案。因此,在加入数组元素之前,必须基于逗号拆分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已成功附加。我希望这能帮助那些研究同样问题的人