如何在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文件,而不是一个应用程序清单文件,所以也许我错过了一个设置?

有没有人有这方面的经验?

+1

潜在的答案在这里:打开从WinJS应用PDF文件] [ 1] [1]:http://*.com/questions/12171444/open-a-pdf-file-from-a-winjs-application – markp3rry

万一有其他人有这个问题。我能够用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”

+0

你可以指定哪些winjs文件包括哪些内容?我不需要WinJS的任何东西,但是这个功能。 – dcp3450

+0

http://try.buildwinjs.com/#get - 包含基本文件。即使你只想要一个功能,我相信你必须包括整个事情。 –

+0

我刚刚注意到windows的构建默认包含了WinJS(见http://*.com/questions/28233531/why-is-winjs-included-automatically-when-targeting-windows-8-in-cordova),所以似乎没有必要明确地添加它 – Hobo