How to open various document formats from memory in Xamarin Forms

I have documents in different encrypted formats. The decryption process of these I do in memory without saving a copy of the document on disk. What I need is to be able to display these documents directly from memory with PDFTron in Xamarin Forms. How can I achieve this?

I’ve tried to figure out how to work with the OpenNonPDFUri method but it needs an Android.Net.Uri and it’s not possible to get a byte array to it.

Any suggestion would be of great help. Thank you

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Hi,
It is possible to load a document from memory.
You will need to create a PDFDoc object using your byte array.
Once you create the PDFDoc object you can set the PDFDoc in your PDFViewCtrl

PDFDoc mPdfDoc = new PDFDoc(yourArray, arraySize);
mPdfViewCtrl.SetDoc(mPdfDoc);

Please let us know if this solution works for you.

Try this way you tell me. For PDF files it works fine but for files for example with the following extensions which are the ones I need (docx, xlsx, pptx, rtf, txt, jpg) it doesn’t work I get the following error:

“Message: PDF header not found. The file is not a valid PDF document.”

Hi,

For non-pdf document, you’ll need to pre-convert it to a PDF:

Could you please give it a try?
Thanks.

I have tried the way you tell me. And if it lets me view MS Office documents, but other types of formats such as images (jpg, png, bmp or tif) or text files (txt) it does not display them, it gives me an error when converting.

Thank you for your answers

Hi,

You can follow the following steps to convert images or txt files to PDF without saving to disk:

Could you please give this a try?
Thanks.