I download a pdf stream from my server. In my app I save the bytearray to a the local folder as pdf. But when I open it in the webview, it just shows a white page.
I followed this example: https://developer.xamarin.com/recipes/cross-platform/xamarin-forms/controls/display-pdf.
Here is customwebview in my xaml:
<local:CustomWebView x:Name="customView" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
Here is my code of the custom view:
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 is my method to retrieve the pdf byte array and store it locally:
private async void ReadPDF()
{
var response = CommonLibrary.Helpers.HTTPClientHelper.DownloadPDF(AccountBL.AccessToken, APISettings.APIURI("api/booking/pdf"));
var streamContent = response.Content as System.Net.Http.StreamContent;
var bytes = CommonLibrary.Helpers.FileHelper.ReadBytes(await streamContent.ReadAsStreamAsync());
var dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var fileName = "test.pdf";
CommonLibrary.Helpers.FileHelper.WriteFileFromByteArray(bytes, dir, fileName);
customView.Uri = System.IO.Path.Combine(dir, fileName);
}
Am I missing something?