Intel-XDK + jsPDF

一笑奈何 提交于 2020-01-07 05:06:08

问题


I'm trying to export an table from my app to an pdf file!

This working normal in emulator, but I can't save the file when the app is installed in my Moto G, I'm using the code bellow:

 var pdf = new jsPDF('p', 'pt', 'a4');
        var source = $('#tabelagastos')[0];

        pdf.fromHTML(source, 15, 15, {'width': 170},
                     function (dispose) {
                        var arquivo = prompt("File name");
                        pdf.save(arquivo +'.pdf');
                     });

Maybe I need to do some kind of configuration to enable this function...

I heard that I need to use the cordova file plugin, but how to use this?


回答1:


I have found the way:

var pdf = new jsPDF('p', 'pt', 'a4');
    var source = $('#tabelagastos')[0];
    var PDFFILE ='';
    var arquivo = prompt("Qual o nome do arquivo?");

    pdf.specialElementHandlers = {
        '#bypassme': function (element, renderer) {
         return true;
     }
    };


    pdf.fromHTML(source, 15, 15, {'width': 170},
                 function (dispose) {
                    PDFFILE = pdf.output();
                 });

    //NEXT SAVE IT TO THE DEVICE

    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
        fileSystem.root.getFile(arquivo +".pdf", {create: true}, function(entry) {
            var fileEntry = entry;
            entry.createWriter(function(writer) {
            writer.onwrite = function(evt) {
                alert("Save (root folder)!");
            };

            writer.write( PDFFILE );
                }, function(error) {
            alert(error);
            });

        }, function(error){
            alert(error);
            });
    },
    function(event){
        alert( evt.target.error.code );
    });


来源:https://stackoverflow.com/questions/27271220/intel-xdk-jspdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!