Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Display Online PDF in Android Webview

$
0
0

Problem Statement:

I am trying to display a hosted PDF from a secure site using https in a WebView using Xamarin.Forms.

What I Have Tried:

I have a custom renderer for the Android WebView control.

If I try using the pdfjs library, I get the following output

enter image description here

Below is my custom renderer:

public class BindableWebviewRenderer : WebViewRenderer
{
    public BindableWebviewRenderer(Context context)
        :base (context)
    {

    }

    protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
    {
        base.OnElementChanged(e);

        if (e.NewElement != null)
        {
            var customWebView = Element as BindableWebView;
            Control.Settings.AllowUniversalAccessFromFileURLs = true;
            Control.LoadUrl(string.Format("file:///android_asset/pdfjs/web/viewer.html?file={0}", string.Format("file:///android_asset/Content/{0}", WebUtility.UrlEncode(customWebView.URL))));
        }
    }
}

I have also tried using

Control.LoadUrl("https://drive.google.com/viewerng/viewer?embedded=true&url=" + customWebView.URL);

But this just displays an empty page (it is also worth noting that the URL created from this also does not work in a browser).

Questions I Have Already Consulted:


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>