1
votes

I am loading an html page from a web server into a Xamarin Forms WebView. This html page contains links to a PDF file.

In iOS, when the user clicks the link, the PDF file is downloaded and opened. In Android, when the user clicks the link, nothing happens. Note that several PDF-Viewers are installed on the Android device.

Is there any configuration necessary for make this work in Android:

Here is the code:

if (dict.ContainsKey("url")){
    string url = dict["url"]; 
    if (Uri.IsWellFormedUriString(url, UriKind.Absolute)){
        NotifWebView.Source = url;
    } else {
        var htmlSource = new HtmlWebViewSource();
        htmlSource.Html = @"<html><body><h1>Fehler!</h1><p>Ungültige oder keine URL oder ungültiges HTML.</p></body></html>";
        NotifWebView.Source = htmlSource;
    }
}

Thanks for your help!

1

1 Answers

0
votes

You can use https://github.com/xamarin/recipes/tree/master/Recipes/xamarin-forms/Controls/display-pdf

The WebView control can display PDF files on the iOS platform, but not on the Android and Windows Phone platforms due to lack of platform support.You need to create a custom renderer to acheve it in android platform.The process for doing this is as follows:

  1. Create a Xamarin.Forms custom control
  2. Consume the custom control from Xamarin.Forms.
  3. Create the custom renderer for the control on each platform.

If you're willing to spend some money, it looks like Syncfusion has a solution for viewing and editing PDF files. http://www.syncfusion.com/products/xamarin