UWP 发送文件数据到 WebView

UWP send file data to WebView

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

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?

简短的回答是肯定的,并且已经有这样的control,但它只适用于Xamarin.Forms。您可以轻松地将其移植到 UWP。

步骤 1

pdfjs JavaScript 包导入您的 UWP 项目。

步骤 2

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

<WebView Name="PDFViewer"/>

步骤 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"))));