在适用于 Ios 和 Android 的 xamarin pcl 应用程序中,在服务器上加载 pdf 的最佳方式是什么。是否有一个好的 nuget 或者我们必须编写自定义渲染器?
在应用程序中打开 PDF,您有几个选项。
iOS 在其 WebView 中支持 PDF 一段时间了。安卓没有。如果你想在 WebView 中执行此操作,可以这样做:
var webView = new WebView();
webView.Source = new UrlWebViewSource() { Url = "https://example.com/my.pdf" };
如果您仅支持 Android API 21+ 及更高版本,则可以使用PDF渲染器 https://developer.xamarin.com/api/type/Android.Graphics.Pdf.PdfRenderer/仅适用于安卓。
如果您需要支持旧设备,或者想要跨平台方法,您有两个选择。如果它是公共 PDF 文档,您可以采取简单的方法并使用 Google 的 PDF 查看器
var webView = new WebView();
var pdfUrl = "https://example.com/my.pdf";
var googleUrl = "http://drive.google.com/viewerng/viewer?embedded=true&url=";
webView.Source = new UrlWebViewSource() { Url = googleUrl + pdfUrl };
如果它是安全的并且您必须先将其下载到您的应用程序中,请使用 Mozilla 的 PDFJS 查看器。 Xamarin 这里有一个演练:https://developer.xamarin.com/recipes/cross-platform/xamarin-forms/controls/display-pdf/ https://developer.xamarin.com/recipes/cross-platform/xamarin-forms/controls/display-pdf/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)