2014-12-03 168 views
0

我試圖從我的應用程序中導出表格到PDF文件!Intel-XDK + jsPDF

該工作在模擬器正常,但我無法保存,當應用程序被安裝在我的Moto G的文件,我用波紋管代碼:

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'); 
        }); 

也許我需要做某種配置啓用此功能...

我聽說我需要使用cordova文件插件,但如何使用它?

回答

0

我已經找到了辦法:

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); 
    });