【发布时间】:2018-09-06 11:08:05
【问题描述】:
您好,我尝试使用 cordova-plugin-file 在 Phonegap 中保存 PDF 数据字符串
示例:
%PDF-1.3
%ºß¬à
3 0 obj
<</Type /Page
/Parent 1 0 R
/Resources 2 0 R
/MediaBox [0 0 595.28 841.89]
/Contents 4 0 R
>>
endobj
4 0 obj
<</Length 8757>>
使用此功能转至 PDF 文件:
savePDF("Storecheck"+surveyID+".pdf", pdfOutput)
function savePDF(fileName, fileData) {
console.log(fileData);
//function writeToFile(fileName, data) {
window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(directoryEntry) {
directoryEntry.getFile(fileName, {
create: true
}, function(fileEntry) {
fileEntry.createWriter(function(fileWriter) {
fileWriter.onwriteend = function(e) {
// for real-world usage, you might consider passing a success callback
console.log('Speichern von "' + fileName + '"" abgeschlossen.');
};
fileWriter.onerror = function(e) {
// you could hook this up with our global error handler, or pass in an error callback
console.log('speichern fehlgeschlagen ' + e.toString());
};
var blob = new Blob([fileData], {
type: 'application/pdf'
});
fileWriter.write(blob);
}, );
}, );
}, );
}
我没有收到错误消息,但文件没有出现。 另外,我想将 PDF 保存在“文档”中,而不是“.file.dataDirectory”中
谁能告诉我我做错了什么?
【问题讨论】:
标签: javascript cordova pdf save