I've successfully read a pdf from the project and displayed in a WebView. What I want to do is to get the pdf file path from my project and check if it exists to display it, and if not, to give it another URI to open with. Anyone knows how I can get the path of the pdf and it works for both Android and iOS.
Here is my C# code:
string internalstorageurl = string.Format("file:///android_asset/Content/{0}", WebUtility.UrlEncode("Conctionprofile.pdf"));
public pdfviewer ()
{
InitializeComponent ();
PDFReading();
}
private void PDFReading()
{
pdfwebview.Uri = internalstorageurl;
}
XAML:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:AppXamarin.CustomRenders"
x:Class="AppXamarin.Pages.pdfviewer"
Padding="0,20,0,0">
<ContentPage.Content>
<local:CustomWebView x:Name="pdfwebview" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
</ContentPage.Content>
</ContentPage>
I'm checking if the file exist in my project with this code:
[assembly: Dependency(typeof(GetPdfFilePath_Android))]
namespace AppXamarin.Droid.CustomRender
{
public class GetPdfFilePath_Android : Java.Lang.Object, IGetPdfFilePath
{
public string filePath(string fileName)
{
string internalstorageurl = string.Format("file:///android_asset/Content/{0}", WebUtility.UrlEncode(fileName));
if (File.Exists(internalstorageurl))
return internalstorageurl;
else
return "not found";
}
}
}
The if statement is always false