We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to open file from external storage and load to pdfreader?

Thread ID:

Created:

Updated:

Platform:

Replies:

132597 Sep 11,2017 09:32 AM Sep 12,2017 03:26 AM Xamarin.Android 1
loading
Tags: PdfViewer
Ishwor Khanal
Asked On September 11, 2017 09:32 AM

I tried this way but got nothing in return

 var directoryPath = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads);
            using (FileStream stream = new FileStream(directoryPath.AbsolutePath + "/" + "test.pdf",FileMode.Open,FileAccess.Read) )
            {
                pdfViewer.LoadDocument(stream);
            }

Sathish Sivakumar [Syncfusion]
Replied On September 12, 2017 03:26 AM

Hi Ishwor, 

Thank you for using Syncfusion products. 

We can read the PDF document from External Storage and display it into SfPdfViewer in Xamarin.Android. The following code snippet illustrates how to open the PDF document from external storage and read it as a Stream. 

private Stream ReadPdfStreamFromExternalStorage() 
{ 
//Get the path of external storage directory. Here we used download directory to read PDF document 
String path = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).AbsolutePath; 
//Read the specific PDF document from the download directory 
Java.IO.File filePath = new Java.IO.File(path+"/test.pdf"); 
// Check whether the file is exist in the download directory 
if (filePath.Exists()) 
{ 
// Convert the file path to stream to display it into SfPdfViewer 
return new FileStream(filePath.AbsolutePath, FileMode.Open, FileAccess.Read); 
} 
else 
{ 
// throw exception if the file is not found in the appropriate directory 
throw new FileNotFoundException("File not found"+ filePath.AbsolutePath.ToString()); 
} 
} 

We have also attached the sample in the below link for your reference. 


Note: Kindly ensure the PDF document that you want display in SfPdfViewer is available in the appropriate external storage directory. 

Please let us know if you need any other assistance. 

Regards, 
Sathish 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;