我无法在Apple手机中查看pdf文档的完美解决方案。我正在使用cordova / jquerymobile,能够使用cordova插件文件和文件传输下载文档。我尝试过fileOpener插件,但它无法正常工作,使用object和iframe标签在滚动和适合时出现问题。
==我在这里看看如何从远程或本地下载来删除pdf文档,这里我的pdf下载代码为ref ==
function DownloadFile(docid_page) {
var myFile = decodeURIComponent(docid_page.replace(/\+/g, " ")); //str.replace(/%20/g, " ");
var remoteFile = myFile.replace(/\s/g, "%20");
var localFileName ="Portico/" + remoteFile.substring(remoteFile.lastIndexOf('/') + 1);
//alert(localFileName);
var statusDom;
statusDom = document.querySelector('#status');
//----creating directory for documents--------
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, onFileSystemFail);
function onFileSystemSuccess(fileSystem) {
console.log(fileSystem.name);
var directoryEntry = fileSystem.root;
directoryEntry.getDirectory("Portico", {create: true, exclusive: false}, onDirectorySuccess, onDirectoryFail)
}
function onDirectorySuccess(parent) {
console.log(parent);
}
function onDirectoryFail(error) {
console.log("Unable to create new directory: " + error.code);
}
function onFileSystemFail(evt) {
console.log(evt.target.error.code);
}
//------end here----------------
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getFile(localFileName, {
create: true,
exclusive: false
}, function(fileEntry) {
var localPath = fileEntry.toURL();
var ft = new FileTransfer();
ft.onprogress = function(progressEvent) {
if (progressEvent.lengthComputable) {
$('#status').show();
var perc = Math.floor(progressEvent.loaded /
progressEvent.total * 100);
statusDom.innerHTML = "Downloading : " + perc + "%";
} else {
if (statusDom.innerHTML == "") {
statusDom.innerHTML = "Loading";
} else {
statusDom.innerHTML += ".";
}
}
};
ft.download(remoteFile, localPath, function(entry) {
// var dwnldImg = document.getElementById("dwnldImg");
$.mobile.loading('hide');
var disPath=decodeURIComponent(entry.fullPath);
navigator.notification.alert('Successfully downloaded in \n' +disPath, null,'Portico', 'OK');
//alert('Download successful! ' + entry.fullPath);
$('#status').hide();
}, fail);
}, fail);
}, fail);
}
function fail(error) {
navigator.notification.alert('Could not download. Try again later', null,'Portico', 'OK');
$.mobile.loading('hide');
}
答案 0 :(得分:0)
答案 1 :(得分:0)
喔!经过长时间的搜索,我找到了ios中查看pdf的完美解决方案..“ExternalFileUtil”我使用了插件 $ cordova插件添加https://github.com/critical/cordova-external-file-open.git