question

ASH-1598 avatar image
0 Votes"
ASH-1598 asked LeonLu-MSFT answered

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

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....!!!!!

.
.
.

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

LeonLu-MSFT avatar image
0 Votes"
LeonLu-MSFT answered

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://docs.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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.