问题
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