如何在Windows 8/Cordova应用程序中打开本地PDF?
问题描述:
我有一个IOS应用程序,我现在已经被分派到Windows 8平台上使用。我的应用程序从Dropbox下载文件,该文件存储在本地文件夹中。我可以看到所有这些工作正常。我能够通过在我的img标签的src中使用ms-appdata:///local/" + filename
来引用图像,我甚至可以使用HTML5视频标签从同一文件夹播放mp4。如何在Windows 8/Cordova应用程序中打开本地PDF?
我的问题是,对于我的IOS版本,我使用Cordova的InAppBrowser打开本地PDF,但在此Windows 8版本中,它不起作用。
我使用下面的代码(filename
等于[1]CaseStudy-AC_EN_04.pdf
,它并在文件系统上存在):
var ref = window.open("ms-appdata:///local/" + filename, '_blank', 'location=no');
我也得到Visual Studio中的以下错误,当我运行模拟器
APPHOST9607: The app can't launch the URI at ms-appdata:///local/[1]CaseStudy-AC_EN_04.pdf because of this error: -2147024846.
我试过切换到WinJS编码方法,甚至尝试在iFrame中加载PDF,但没有任何工作。如果必须的话,我不介意将用户踢到Internet Explorer ......我只需要一些方法让用户查看这些本地PDF。这是一个权限问题?我只有一个config.xml文件,而不是一个应用程序清单文件,所以也许我错过了一个设置?
有没有人有这方面的经验?
答
万一有其他人有这个问题。我能够用WinJS代码做我想做的事(确保你包含WinJS框架文件)
//this is just the filename, you can probably skip this step but my filenames are from downloaded files so they could be encoded.
fileName = decodeURIComponent(fileName);
//get the local folder that contains the downloaded files
var applicationData = Windows.Storage.ApplicationData.current;
var localFolder = applicationData.localFolder;
//grab the file and return a promise
localFolder.getFileAsync(fileName)
.then(function(file) {
//launch the file - this command will let the OS use it's default PDF reader - win 8 app 'reader' works great.
Windows.System.Launcher.launchFileAsync(file);
});
就是这样。
@Matthew科威正常工作。 但是,需要注意aditional的文件时是一个子文件夹如下为例内:
VAR FULLPATH =“\文件夹\ fileName.pdf”
潜在的答案在这里:打开从WinJS应用PDF文件] [ 1] [1]:http://*.com/questions/12171444/open-a-pdf-file-from-a-winjs-application – markp3rry