It is fairly easy to display a PDF file that is local to your phone. For example, see this article from Xamarin.com.
A bit trickier is to get a PDF from a server and then to display it.
Here’s how I did it (note, this blog post offers snippets of code, rather than a complete solution… I will reduce my larger program to something manageable asap)
The first thing I did was create a model object named ReportItem. Its primary goal is to help group all the items in my list of pdf’s, but it contains the all-important URL to the pdf itself.
Next, I created a page named ShowPDFPage. In the XAML part of this page I just have a CustomWebView:
<local:CustomWebView Uri="foo.pdf"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand" />
The CustomWebView was taken from an article I found on the web.
public class CustomWebView : WebView
{
public static readonly BindableProperty UriProperty = BindableProperty.Create (propertyName:"Uri",
returnType:typeof(string),
declaringType:typeof(CustomWebView),
defaultValue:default(string));
public string Uri
{
get { return ( string ) GetValue( UriProperty ); }
set { SetValue( UriProperty, value ); }
}
}
This performs the magic of showing the PDF file, but how do we get it?
Continue reading →