Skip to content

Instantly share code, notes, and snippets.

@jdnichollsc
Created January 17, 2016 19:59
Show Gist options
  • Save jdnichollsc/a5a5b7635ea9e7af515e to your computer and use it in GitHub Desktop.
Save jdnichollsc/a5a5b7635ea9e7af515e to your computer and use it in GitHub Desktop.
Cordova - Send base64 file with jsPDF and Email Composer
var pdfString = doc.output('datauristring'); //base64 string from jsPDF
if (window.cordova && window.cordova.plugins.email) {
var email = {
//to: 'jdnichollsc@hotmail.com',
//cc: 'jdnichollsc@hotmail.com',
//bcc: ['jdnichollsc@hotmail.com'],
attachments: [
generateAttachment(pdfString, "myFileName.pdf")
],
subject: 'Mira un PDF!',
body: 'Abre el PDF creado con jsPDF :)',
isHtml: true
};
cordova.plugins.email.open(email);
}
var generateAttachment = function(uriString, fileName){
var uristringparts = uriString.split(',');
uristringparts[0] = "base64:" + fileName + "//";
return uristringparts.join("");
};
@darkraisisi
Copy link

darkraisisi commented Nov 15, 2017

Nice, this method is one of the best ones i have come across, most use the file system and the cache.
nicely done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment