UWP 向 WebView 发送文件数据 [英] UWP send file data to WebView

查看:29
本文介绍了UWP 向 WebView 发送文件数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 C# 编码的应用程序,但我想在带有 pdf.js 的 WebView 中显示一个 PDF 文件.UWP 提供的用于查看 PDF 的 API 对我来说太有限了,它们不支持诸如文本选择之类的东西,而且对于大文件来说可能会很慢.是否有可能(如果是这样,最好的方法是)在 C# UWP 应用程序内的 WebView 中使用 pdf.js 打开文件 (StorageFile)?

解决方案

是否可以(如果可以,最好的方法是)在 C# UWP 应用程序内的 WebView 中使用 pdf.js 打开文件 (StorageFile)?

简短的回答是肯定的,而且已经有这样的

第 2 步

实例化一个用于显示 pdfjs 索引页的 WebView 控件.

步骤 3

创建包含pdf文件绝对路径的PDFViewer源.

PDFViewer.Source = new Uri(string.Format("ms-appx-web:///pdfjs/web/viewer.html?file={0}", string.Format("ms-appx-web:///Assets/{0}", WebUtility.UrlEncode("hello.pdf"))));

I have an app coded in C#, but I would like to show a PDF file in a WebView with pdf.js. The APIs that the UWP provides for viewing PDFs are too limited for me, they do not support things like text selection and it can be very slow with large files. Is it possible (if so, what would be the best way to) open a file (StorageFile) using pdf.js inside a WebView inside a C# UWP app?

解决方案

Is it possible (if so, what would be the best way to) open a file (StorageFile) using pdf.js inside a WebView inside a C# UWP app?

The short answer is yes, and there is already such control, but it only works in Xamarin.Forms. You can port it to UWP easily.

Step 1

Import pdfjs JavaScript package to your UWP project.

Step 2

Instantiate a WebView control that used to display pdfjs index page.

<WebView Name="PDFViewer"/>

Step 3

Create PDFViewer source that contain pdf file absolute path.

PDFViewer.Source = new Uri(string.Format("ms-appx-web:///pdfjs/web/viewer.html?file={0}", string.Format("ms-appx-web:///Assets/{0}", WebUtility.UrlEncode("hello.pdf"))));

这篇关于UWP 向 WebView 发送文件数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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