Jquery 无法使用PhoneGap查看pdf文件
我试图查看已下载的pdf,但没有显示它的运气 这是我下载和显示文件的代码。当我试图打开文件时,我只会收到一个警报,说无法查看文件 jQueryJquery 无法使用PhoneGap查看pdf文件,jquery,cordova,pdf,Jquery,Cordova,Pdf,我试图查看已下载的pdf,但没有显示它的运气 这是我下载和显示文件的代码。当我试图打开文件时,我只会收到一个警报,说无法查看文件 jQuery // Download edition's pdf file function downloadFile(filename){ var localDir = cordova.file.dataDirectory; // Validate if file exist before download window.resolveLoc
// Download edition's pdf file
function downloadFile(filename){
var localDir = cordova.file.dataDirectory;
// Validate if file exist before download
window.resolveLocalFileSystemURL(localDir + filename, function(){
ShowPDF(localDir + filename);
}, function(){
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function onFileSystemSuccess(fileSystem) {
fileSystem.root.getFile(
"index.html", {create: true, exclusive: false},
function gotFileEntry(fileEntry) {
//var sPath = fileEntry.fullPath.replace("index.html","");
var localDir = cordova.file.dataDirectory;
var fileTransfer = new FileTransfer();
fileEntry.remove();
fileTransfer.download(
path + filename,
localDir + filename,
function(theFile) {
ShowPDF(theFile.toURI());
console.log("download complete: " + theFile.toURI());
},
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code: " + error.code);
console.log(error);
}
);
}, fail);
}, fail);
});
};
// Show downloaded pdf
function ShowPDF(filePath){
window.open(filePath, '_system', 'location=yes')
};
编辑:
我刚刚意识到,这部分还将使用浏览器下载文件,然后您可以查看下载的文件
window.open(path + filename, '_system', 'location=yes');
在显示本地文件之前,我需要验证文件是否已下载
更新
我照此操作,但仍然无法查看本地文件您无法在cordova webview中打开PDF。
试试Phonegap插件 我目前正在使用fileOpener插件,但仍然没有成功。请确保您的设备中至少有一个pdf阅读器。是的,我的手机上有阅读器。我认为可能的问题是,存储文件的位置可能没有读取文件的权限。我正在调查这个问题