plus.io.requestFileSystem(plus.io.PUBLIC_DOWNLOADS, function(fs) {
fs.root.getFile('test.pdf', {
create: true
}, function(fileEntry) {
console.log(fileEntry.fullPath)
fileEntry.createWriter(function(writer) {
writer.onwrite = function(e) {
plus.console.log("Write data success!");
};
var doc = new jsPDF();
doc.text(20, 20, '你好 Hello world!');
doc.text(50, 20, '你好 Hello world!');
doc.text(20, 30, 'This is client-side Javascript, pumping out a PDF.');
doc.addPage(); //生成下一页
doc.text(20, 20, 'Do you like that?');
//doc.save('Test.pdf');//如果用这行,下面的可以都注释起来,效果就是当前面页变为打开的PDF
var abf = doc.output('dataurlstring'); //dataurlstring
console.log(JSON.stringify(abf));
console.log(abf.length);
abf = abf.replace(/^data:application\/(pdf|PDF);base64,/,"");//这里试过注释起来
console.log(abf);
//writer.seek(writer.length - 1); //这里试过不-1 也试过注释起来
writer.write(abf);
//writer.abort(); //这里试过注释起来
})
}, function(e) {
alert("getFile failed: " + e.message);
});
}, function(e) {
alert("Request file system failed: " + e.message);
})
用jspdf生成的base64格式的字符串保存为文件后打开生成的文件后提示不是正确的PDF文件
下面的是得到jspdf生成的base64格式的字符串
"data:application/pdf;base64,JVBERi0xLjMKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL1Jlc291cmNlcyAyIDAgUgovTWVkaWFCb3ggWzAgMCA1OTUuMjggODQxLjg5XQovQ29udGVudHMgNCAwIFI+PgplbmRvYmoKNCAwIG9iago8PC9MZW5ndGggMjcxPj4Kc3RyZWFtCjAuNTcgdwowIEcKQlQKL0YxIDE2IFRmCjE4LjQgVEwKMCBnCjU2LjY5IDc4NS4yMCBUZAooT2BZfQAgAEgAZQBsAGwAbwAgAHcAbwByAGwAZAAhKSBUagpFVApCVAovRjEgMTYgVGYKMTguNCBUTAowIGcKMTQxLjczIDc4NS4yMCBUZAooT2BZfQAgAEgAZQBsAGwAbwAgAHcAbwByAGwAZAAhKSBUagpFVApCVAovRjEgMTYgVGYKMTguNCBU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