【发布时间】:2016-07-30 05:45:59
【问题描述】:
我在 cordova android 设备上运行, 我可以到达'console.log ("write success");'行但我不认为该文件没有出现在它的保存位置。
我试过在 2 个不同的机器人上运行, 创建一个pdf文件并保存在任何地方的任何文件夹中
源代码 http://www.tricedesigns.com/2014/01/08/generating-pdf-inside-of-phonegap-apps/
//FIRST GENERATE THE PDF DOCUMENT
console.log("generating pdf...");
var doc = new jsPDF();
doc.text(20, 20, 'HELLO!');
doc.setFont("courier");
doc.setFontType("normal");
doc.text(20, 30, 'This is a PDF document generated using JSPDF.');
doc.text(20, 50, 'YES, Inside of PhoneGap!');
var pdfOutput = doc.output();
console.log( pdfOutput );
//NEXT SAVE IT TO THE DEVICE'S LOCAL FILE SYSTEM
console.log("file system...");
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
console.log(fileSystem.name);
console.log(fileSystem.root.name);
console.log(fileSystem.root.fullPath);
fileSystem.root.getFile("test.pdf", {create: true}, function(entry) {
var fileEntry = entry;
console.log(entry);
entry.createWriter(function(writer) {
writer.onwrite = function(evt) {
console.log("write success");
};
console.log("writing to file");
writer.write( pdfOutput );
}, function(error) {
console.log(error);
});
}, function(error){
console.log(error);
});
},
function(event){
console.log( evt.target.error.code );
谢谢!!
【问题讨论】:
-
您找到解决方案了吗?我也面临同样的问题!
-
不:{,我也需要帮助
标签: javascript android cordova cordova-plugins jspdf