英特尔XDK + jsPDF [英] Intel-XDK + jsPDF
本文介绍了英特尔XDK + jsPDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将应用程序中的表格导出为pdf文件!
I'm trying to export an table from my app to an pdf file!
在模拟器中可以正常工作,但是当应用安装在Moto G中时,我无法保存文件,我使用的是以下代码:
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...
我听说我需要使用cordova文件插件,但是如何使用它呢?
I heard that I need to use the cordova file plugin, but how to use this?
推荐答案
我找到了方法:
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 );
});
这篇关于英特尔XDK + jsPDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文