2017-06-30 98 views
0

我想从网络服务器下载pdf文件(并在每次启动时重新下载它),并在xamarin for android的webview中显示它。有没有办法?在Xamarin WebView中显示PDF

 WebView webview = FindViewById<WebView>(Resource.Id.webView1); 
     webview.Settings.JavaScriptEnabled = true; 
     webview.Settings.AllowFileAccess = true; 
     webview.LoadUrl("http://www.justadomain.com/document.pdf"); 

回答

0

试试这个:

webview.LoadUrl("https://docs.google.com/viewer?url="+"http://www.justadomain.com/document.pdf"); 
+0

是的,我知道这种方式,但我想显示一个普通的pdf没有任何渲染或JavaScript包装。 – Emil

0

也有提供PDF软件开发工具包,但不幸的是昂贵许多Xamarin组件。对于其他免费替代品,您可以随时查看此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; 

否则,你也可以尝试找到针对Android像this one一个PDF库,并通过Java绑定,将其导入到你的项目Xamarin。

希望这会有所帮助。