How do I display and store a PDF file from webservice? Xamarin Forms

AS_H 41 Reputation points
2021-06-29T14:47:18.047+00:00

How do I display and store a PDF file from webservice? In Android and Ios

I got base64binary from web services
Then I stored it in a byte

I don't know what is the next step
can i use this "Xamarin.Essentials"?

This is Cody:

string base64BinaryStr = await vm.DownloadETransAttFile(itemSelected.ATTCH_ID, itemSelected.ATTCH_VERSION, itemSelected.ATTCH_KND);

byte[] bytes = Convert.FromBase64String(base64BinaryStr);

   // Xamarin.Essentials.FilePicker.PickAsync....!!!!!

.
.
.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,377 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 81,191 Reputation points Microsoft External Staff
    2021-06-30T06:54:10.98+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    First of all, we should store the pdf in the local storage. We can create an dependence Service, then trasfer byte[] to Android or iOS platform by attribute of interface.

    For android, you can refer to this thread: https://stackoverflow.com/questions/60394507/xamarin-forms-save-file-pdf-in-local-storage-and-open-with-the-default-viewer

    For iOS, you could use File system access in Xamarin.iOS like following link.

    https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/file-system

    To display the PDF, you can use 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. On the Android and Windows Phone platforms, Mozilla's pdf.js can be used to add this support. pdf.js is a JavaScript library for parsing and rendering PDFs using the HTML5 canvas element.

    Here is official demo about how to use it.

    https://github.com/xamarin/docs-archive/tree/master/Recipes/xamarin-forms/Controls/display-pdf

    Best Regards,

    Leon Lu


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.