Created
January 17, 2016 19:59
-
-
Save jdnichollsc/a5a5b7635ea9e7af515e to your computer and use it in GitHub Desktop.
Cordova - Send base64 file with jsPDF and Email Composer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var pdfString = doc.output('datauristring'); //base64 string from jsPDF | |
if (window.cordova && window.cordova.plugins.email) { | |
var email = { | |
//to: '[email protected]', | |
//cc: '[email protected]', | |
//bcc: ['[email protected]'], | |
attachments: [ | |
generateAttachment(pdfString, "myFileName.pdf") | |
], | |
subject: 'Mira un PDF!', | |
body: 'Abre el PDF creado con jsPDF :)', | |
isHtml: true | |
}; | |
cordova.plugins.email.open(email); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var generateAttachment = function(uriString, fileName){ | |
var uristringparts = uriString.split(','); | |
uristringparts[0] = "base64:" + fileName + "//"; | |
return uristringparts.join(""); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice, this method is one of the best ones i have come across, most use the file system and the cache.
nicely done.