pdf - Download using jsPDF on a mobile devices -


i have page includes download button using jspdf. on desktop machines downloads page should. however, pdf.save() not work on tablet or phone.

i tried add special case mobile devices open pdf in new window, since mobile devices don't download things same desktops, idea being once pdf open in new window user can choose save manually.

var pdf = new jspdf('p', 'pt', 'letter'); var specialelementhandlers = {     '#editor': function (element, renderer) {         return true;     } };  html2canvas($("#pdf-area"), {     onrendered: function (canvas) {         $("#pdf-canvas").append(canvas);         $("#pdf-canvas canvas").css("padding", "20px");     } });  var options = {     pagesplit: true };  function download(doctitle) {     pdf.addhtml($("#pdf-area")[0], options, function () {         if (/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(navigator.useragent)) {             pdf.output('dataurlnewwindow');                    } else {             pdf.save(doctitle);         }             }); } 

but download function still nothing on tablet/phone. tested make sure pdf.output() function working:

    pdf.addhtml($("#pdf-area")[0], options, function () {         pdf.output('dataurlnewwindow');                     }); 

and still work on desktop, nothing on mobile.

here example if you're using cordova platform development:

https://github.com/saharcasm/cordova-jspdf-email

the workaround of pdf not being downloaded in devices use cordova-plugin-file.

use output method on doc give raw pdf needs written & saved in file.

for example,

var doc = new jspdf();  //... work object var pdfoutput = doc.output("blob"); //returns raw object of pdf file 

the pdfoutput written on actual file using file plugin.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -