Javascript 如何在Windows 8/Cordova应用程序中打开本地PDF?

Javascript 如何在Windows 8/Cordova应用程序中打开本地PDF?,javascript,cordova,pdf,windows-8,winjs,Javascript,Cordova,Pdf,Windows 8,Winjs,我有一个自己开发的IOS应用程序,现在我的任务是将其移植到Windows 8,以便在Windows平板电脑上使用。我的应用程序从Dropbox下载文件,Dropbox存储在本地文件夹中。我看所有这些都很好。我可以使用ms引用图像-appdata:///local/“+filename在我的img标签的src中,我甚至可以使用HTML5视频标签从同一文件夹播放MP4 我的问题是,对于我的IOS版本,我使用Cordova的iApp浏览器打开本地PDF,但在这个Windows8版本上,它不起作用 我正

我有一个自己开发的IOS应用程序,现在我的任务是将其移植到Windows 8,以便在Windows平板电脑上使用。我的应用程序从Dropbox下载文件,Dropbox存储在本地文件夹中。我看所有这些都很好。我可以使用
ms引用图像-appdata:///local/“+filename
在我的img标签的src中,我甚至可以使用HTML5视频标签从同一文件夹播放MP4

我的问题是,对于我的IOS版本,我使用Cordova的iApp浏览器打开本地PDF,但在这个Windows8版本上,它不起作用

我正在使用以下代码(
filename
equals
[1]casestury-AC_EN_04.pdf
,它确实存在于文件系统中):

当我运行模拟器时,在VisualStudio中出现以下错误

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框架文件)

就这样

@马修·科威工作得很好。 但是,当文件位于子文件夹中时,需要注意以下示例:


var fullPath=“\folderName\fileName.pdf”

此处可能的答案:[从WinJS应用程序中打开pdf文件][1][1]:您可以指定要包含哪个winjs文件吗?我不需要winjs中的任何内容,只需要此功能。-包含基本文件。即使您只需要一个功能,我相信您必须包含全部内容。我刚刚注意到windows构建默认包含winjs(请参阅),因此似乎没有必要明确添加它。是否可以从blob创建文件对象?我看到了
Windows.Storage.StorageFile.createStreamedFileAsync
,但没有示例。
APPHOST9607: The app can't launch the URI at ms-appdata:///local/[1]CaseStudy-AC_EN_04.pdf because of this error: -2147024846.
//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);
});