下载,保存(本地)和显示PDF从一个链接 [英] Download, save( locally ) and display PDF from a link

查看:364
本文介绍了下载,保存(本地)和显示PDF从一个链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发的Windows phone 8的应用程序。在我的应用程序,我要显示在离线PDF文件(没有的网络连接)模式下,应用程序内。对于我必须做到以下几点,

I am developing Windows phone 8 application. In my application, i have to display PDF file in offline( without net connection ) mode, within application. For that i have to do the following,


  1. 从由服务器端提供了一个链接(URL)下载PDF文件。

  2. 保存在本地存储下载的PDF文件。

  3. 开启和显示PDF从本地存储的文件。

在搜索,我发现建议使用的ComponentOne Studio的工具被称为工作室为Windows Phone的。不幸的是它不是免费的。有什么办法在免费的成本来实现?

On searching, i found suggestions to use ComponentOne Studio's toolset called 'Studio for Windows Phone'. Unfortunately it is not free. Is there any way to implement in free of cost?

任何引用,样品或想法,将不胜感激。

Any reference, samples or ideas will be greatly appreciated.

推荐答案

您可以下载PDF文件并将其保存在独立存储,能够为以后离线查看使用PDF查看器应用程序,例如Adobe Reader或PDF阅读器。

You can download the PDF file and save it in Isolated Storage, to be able to view later offline using a PDF viewer app such Adobe Reader or PDF Reader.

那么让我们看看如何做它一步一步的。

So lets see how to do it step-by-step.

1下载PDF从一个链接文件(URL )由服务器端提供的:

WebClient client = new WebClient();
client.OpenReadCompleted += client_OpenReadCompleted;
client.OpenReadAsync(new Uri("http://url-to-your-pdf-file.pdf"));



2 - 保存本地存储下载的PDF文件:

async void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
    byte[] buffer = new byte[e.Result.Length];
    await e.Result.ReadAsync(buffer, 0, buffer.Length);

    using (IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForApplication())
    {
        using (IsolatedStorageFileStream stream = storageFile.OpenFile("your-file.pdf", FileMode.Create))
        {
            await stream.WriteAsync(buffer, 0, buffer.Length);
        }
    }
}



3公开赛并从本地存储显示PDF文件:

// Access the file.
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFile pdffile = await local.GetFileAsync("your-file.pdf");

// Launch the pdf file.
Windows.System.Launcher.LaunchFileAsync(pdffile);

这篇关于下载,保存(本地)和显示PDF从一个链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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