Download using jsPDF on a mobile devices

后端 未结 3 1418
青春惊慌失措
青春惊慌失措 2020-12-20 04:50

I have a page that includes a download button using jsPDF. On desktop machines it downloads the page as it should. However, pdf.save() does not work on my table

相关标签:
3条回答
  • 2020-12-20 05:34

    Here is the solution of download on mobile with jspdf

    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))
    {
         var blob = pdf.output();
         window.open(URL.createObjectURL(blob));
    }
    else
    {
         pdf.save('filename.pdf');
    }
    
    0 讨论(0)
  • 2020-12-20 05:43

    Here is the example if you're using the Cordova platform for your development:

    https://github.com/saharcasm/Cordova-jsPDF-Email

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

    Use the output method on the doc that will give you the raw pdf which needs to be written & saved in a file.

    For example,

    var doc = new JsPDF(); 
    //... some work with the object
    var pdfOutput = doc.output("blob"); //returns the raw object of the pdf file
    

    The pdfOutput is then written on an actual file by using the file plugin.

    0 讨论(0)
  • 2020-12-20 05:45

    I had similar issue.

    jsPDF won't download file on phones/ tablets / ipads using "pdf.save()".

    Do it through File plugin if you are using cordova/phonegap, this will save pdf file in downloads folder (Android) - for the ios you can access pdf file through a path (which is saved somewhere in temp directory) and can send or share.

    Hope this helps you.

    0 讨论(0)
提交回复
热议问题