在Windows Phone中打开PDF文件 [英] Opening a PDF file in Windows Phone

查看:137
本文介绍了在Windows Phone中打开PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Windows Phone 7开发一个应用程序,我正在使用Phonegap模板。
一切看起来很完美,但现在我被困在浏览器中打开一个PDF文件。
我尝试以下,但是不工作,因为PDF的URL超过了2048字符限制(它是一个数据url)。此代码在deviceReady事件触发后运行。

I'm developing an app for Windows Phone 7 and I'm using a Phonegap template for it. Everything looks perfect, but now I’m stuck trying to open a PDF file in the browser. I tried the following but that doesn’t work because the url of the PDF exceeds the 2048 character limit (it’s a data url). This code runs after the deviceReady event was fired.

var ref = window.open('http://www.google.com', '_blank', 'location=no');
ref.addEventListener('loadstart', function () { alert(event.url); });

现在,我试图将PDF文件保存到存储,然后我试图它由浏览器打开,但浏览器不显示任何内容。我编辑来自cordovalib的InAppBrowser.cs代码,并且在调用browser.Navigate(loc)之前添加了以下行:

Now, I'm trying to save the PDF file to storage and then I'm trying to have it opened by the browser, but the browser doesn't show anything. I'm editing the InAppBrowser.cs code from cordovalib and I added the following lines before calling browser.Navigate(loc);

private void ShowInAppBrowser(string url)
{
    IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
    FileStream stream = store.OpenFile("test.pdf", FileMode.Create);
    BinaryWriter writer = new BinaryWriter(stream);
    var myvar = Base64Decode("the big data url");
    writer.Write(myvar);
    writer.Close();

    if (store.FileExists("test.pdf")) // Check if file exists
    {
        Uri loc = new Uri("test.pdf", UriKind.Relative);
        ...
    }
}

以下错误:
日志:错误回调中出错:InAppBrowser1921408518 = TypeError:无法获取属性url的值:object为null或未定义

This code is returning the following error: Log:"Error in error callback: InAppBrowser1921408518 = TypeError: Unable to get value of the property 'url': object is null or undefined"

我不想使用ComponentOne。

I don’t wanna use ComponentOne.

任何帮助将非常感激。

推荐答案

您无法在PDF文件的默认读取器中从隔离存储打开pdf文件。如果文件在线,例如它有一个URI,你可以使用WebBrowserTask打开它,因为它将下载并在Adobe Reader中打开文件。

You cannot open pdf files from the isolated storage in the default reader for PDF files. If the file is online e.g. it has a URI for it, you can use WebBrowserTask to open it since that will download and open the file in Adobe Reader.

在Windows Phone 8上,你可以打开你的自己的文件在该扩展的默认文件阅读器,但我不知道如何将帮助你,因为你的目标PhoneGap和Windows Phone 7。

On Windows Phone 8 you actually can open your own file in default file reader for that extension, but I am not sure how that will help you since you target PhoneGap and Windows Phone 7.

这篇关于在Windows Phone中打开PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆