Reputation: 121
I want to get PDF file which is Base64 encoded and is presented as string. At first I save file locally on my mobile phone by this method and returns path to the file:
byte[] byteBuffer = Encoding.UTF8.GetBytes(pdfString);
public string SaveBinary(string filename, byte[] bytes)
{
string filepath = GetFilePath(filename);
if (File.Exists((filepath)))
{
File.Delete(filepath);
}
File.WriteAllBytes(filepath, bytes);
return filepath;
}
string GetFilePath(string filename)
{
return Path.Combine(GetDocsPath(), filename);
}
string GetDocsPath()
{
return System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
}
Then I try to open PDF in browser but nothing happens.
string filename = DependencyService.Get<IFileWorker>().SaveBinary($"name.pdf", byteBuffer);
try
{
Device.OpenUri(new Uri(filename));
Upvotes: 2
Views: 3903
Reputation: 629
You can do it simply with webview (there goes an example: https://developer.xamarin.com/recipes/cross-platform/xamarin-forms/controls/display-pdf/)
Example: https://github.com/xamarin/recipes/tree/master/Recipes/xamarin-forms/Controls/display-pdf
Upvotes: 1