在Xamarin Forms PCL项目中打开远程pdf的最佳方法 [英] best way to open a remote pdf in xamarin forms pcl project

查看:97
本文介绍了在Xamarin Forms PCL项目中打开远程pdf的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ia和Android的xamarin pcl应用程序中的服务器上加载pdf的最佳方法是什么.是否有一个很好的细节,还是我们必须编写自定义渲染器?

Whats is the best way to load a pdf on server in the xamarin pcl App for both Ios and Android. Is there a good nuget or we have to write the custom renderers?

推荐答案

在应用程序中打开PDF,您有几种选择.

Opening a PDF in the app, you have a few options.

iOS在其WebView中已经有PDF支持一段时间了. Android没有.如果要在WebView中执行此操作,则可以执行以下操作:

iOS has had PDF support in its WebView for a while. Android doesn't. If you want to do it in a WebView you can do this:

var webView = new WebView();
webView.Source = new UrlWebViewSource() { Url = "https://example.com/my.pdf" };

如果仅支持Android API 21+及更高版本,则可以使用

If you are only supporting Android API 21+ and higher, you can use the PdfRenderer for Android only.

如果您需要支持较旧的设备,或者希望使用跨平台方法,则有两种选择.如果它是公开的PDF文档,您可以采用一种简单的方法并使用Google的PDF Viewer

If you need to support older devices, or want a cross platform approach, you have 2 options. If its a public PDF document, you can take an easy approach and use Google's PDF Viewer

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 Viewer. Xamarin在这里有一个演练: https://developer. xamarin.com/recipes/cross-platform/xamarin-forms/controls/display-pdf/

If it's secure and you have to download it to your app first, use Mozilla's PDFJS Viewer. Xamarin have a walkthrough here: https://developer.xamarin.com/recipes/cross-platform/xamarin-forms/controls/display-pdf/

这篇关于在Xamarin Forms PCL项目中打开远程pdf的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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