【问题标题】:Opening a pdf with pdf.js with Xamarin on windows phone在 Windows 手机上使用 Xamarin 使用 pdf.js 打开 pdf
【发布时间】:2016-01-08 18:53:20
【问题描述】:

我正在尝试在 Windows Phone 应用程序上使用 Xamarin 打开带有 pdf.js 的 pdf 文件,但无法正常工作。

它正确显示了 pdf.js viewer.html,但我无法打开 pdf 文件。我尝试了以下方法:

PdfWebViewer.Source = "Assets/pdf.js/web/viewer.html?
file=ms-appx:///Assets/Temp/test.pdf";

PdfWebViewer.Source = "Assets/pdf.js/web/viewer.html?
file=Assets/Temp/test.pdf";

PdfWebViewer.Source = "Assets/pdf.js/web/viewer.html?
file=File:///Assets/Temp/test.pdf";

PdfWebViewer.Source = "Assets/pdf.js/web/viewer.html?
file=File://Assets/Temp/test.pdf";

出于测试目的,我的 Assets/Temp 文件夹中有一个 test.pdf 文件,其 ContentType 设置为 Content。

但是上面提到的组合都不起作用。每当我指定文件时,我只会显示“找不到页面”而不是 viewer.html

我需要在 pdf 的底部显示按钮,所以我必须使用我的应用程序打开 pdf。不能使用其他应用打开 pdf。

有什么想法吗?

谢谢。

【问题讨论】:

  • 真的有必要使用pdf.js来打开你的PDF吗?我没有使用 pdf.js 在我的应用程序中打开 PDF,所以我无法帮助您。但是我通过启动用户安装的默认 PDF 阅读器应用程序(例如 Acrobat Reader 或 OneReader)从我的应用程序打开 PDF。如果这对您来说是一个可行的选择,请告诉我。
  • 我可能应该提到我们不能离开应用程序,因为我们需要在 pdf 的底部显示按钮,但 Xamarin 要求我尝试使用 webview 构建渲染器并调整大小以填充屏幕到我的工具栏。也许这会奏效。我会试一试,如果可行,我会更新这篇文章。

标签: c# windows-phone-8 xamarin windows-phone-8.1 pdf.js


【解决方案1】:

更改 URI 方案,如下所示:

protected override void OnNavigatedTo(NavigationEventArgs e)
        {

                MyView.Source = new Uri(String.Format("ms-appx-web:///Assets/pdfjs/web/viewer.html?file={0}", "ms-appx-web:///Files/a1.pdf"));

// ms-appx-web:///thefolder in which file is available/filename.pdf
        }

另请注意,在 Windows 中您可能无法访问 PDF 文件系统,而只能访问捆绑的 pdf 文件

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-02
    • 1970-01-01
    • 2019-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-22
    相关资源
    最近更新 更多