我想从网络服务器下载一个pdf文件(并在每次启动时重新下载),然后在xamarin for web中的webview中显示它。有办法吗?
WebView webview = FindViewById<WebView>(Resource.Id.webView1);
webview.Settings.JavaScriptEnabled = true;
webview.Settings.AllowFileAccess = true;
webview.LoadUrl("http://www.justadomain.com/document.pdf");
答案 0 :(得分:0)
试试这个:
webview.LoadUrl("https://docs.google.com/viewer?url="+"http://www.justadomain.com/document.pdf");
答案 1 :(得分:0)
还有许多Xamarin组件提供PDF SDK,但不幸的是价格昂贵。对于其他免费替代方案,您可以随时查看blog post,其中说明了在应用程序中显示PDF文件时的选项。
最简单也许最干净的解决方案是让第三方应用程序显示您的PDF文件。以下是从上面的博客文章中获取的java代码:
using Uri = Android.Net.Uri;
Intent intent = new Intent(Intent.ActionView);
intent.SetDataAndType(Uri.Parse("file:///" + PathToFile(filename)), "application/pdf");
intent.SetFlags(ActivityFlags.ClearTop);
StartActivity(intent);
return null;
否则,您也可以尝试为this one找到适合Android的PDF库,并通过java绑定将其导入Xamarin项目。
希望这有帮助。
答案 2 :(得分:0)
网络引擎无法做到这一点!
如果您无论如何都想显示 PDF,则需要一种将其转换为某种 HTML 的方法。有很多关于此的工具,例如 Google Drive 或 Mozillas PDF.js