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. Image for the cookie policy date
close icon

PDFViewer Failing on Android

I just implemented the PDFViewer into a Xamarin.Forms project and it worked right out of the gate for UWP.  

However I am getting an exception on Android.  The error log is attached.

I have made sure that I have the necessary packages installed for Android.I am opening a downloaded pdf that is being written to disk via the PCLStorage library.  I have verified that a document exists at the location.  And my mp3 player works with downloaded files AND the pdfs work fine in UWP.  So I am fairly certain the downloaded PDF is being streamed properly.  

I am testing on a Nexus 5 with Android 6.0 

This is the code that handles the streaming, I am just using the XAML from the example in the documentation.

public SimplePdf(String filename)
  {
      InitializeComponent();

      FileName = filename;
      LoadStream();
  }

  private async void LoadStream()
  {
      IFolder rootFolder = FileSystem.Current.LocalStorage;
      IFolder folder = await rootFolder.GetFolderAsync("Downloads");
      IFile file = await folder.GetFileAsync(FileName);

      Debug.WriteLine("file: " + file.Path);

      var filebuffer = await file.OpenAsync(FileAccess.Read);

      var mStream = new MemoryStream();
      filebuffer.CopyTo(mStream);

      Debug.WriteLine("stream: " + mStream.Length.ToString());

      pdfViewerControl.LoadDocument(mStream);
}

Attachment: pdfviewer_error.txt_1a8fd27d.zip

3 Replies

SS Sathish Sivakumar Syncfusion Team April 28, 2017 12:47 PM UTC

Hi Jacob, 
 
Thank you for using Syncfusion products. 
 
In order to resolve the exception “Java.IO.IoException: cannot create document. Error 3” , we need to reset the memory stream position to 0 before loading it into SfPdfViewer. Please find the code snippet below which is used to resolve the exception:  
 
Code Snippet: 
 
IFolder rootFolder = FileSystem.Current.LocalStorage; 
IFolder folder = await rootFolder.GetFolderAsync("Downloads"); 
IFile file = await folder.GetFileAsync(FileName); 
 
Debug.WriteLine("file: " + file.Path); 
 
var filebuffer = await file.OpenAsync(FileAccess.Read); 
 
var mStream = new MemoryStream(); 
filebuffer.CopyTo(mStream); 
 
Debug.WriteLine("stream: " + mStream.Length.ToString()); 
mStream.Position = 0; 
pdfViewerControl.LoadDocument(mStream); 
 
 
Please get back to us with more details if you still reproducing the same issue. 
 
Regards, 
Sathish 



JB Jacob Bullock April 28, 2017 03:40 PM UTC

That fixed it.  Thanks so much.


NK Navaneetha Kannan Sudalai Muthu Syncfusion Team May 1, 2017 03:03 PM UTC

Hi Jacob, 

We are glad that the issue was fixed. Kindly let us know if you need any further assistance.  

Best, 
Navaneetha Kannan  


Loader.
Live Chat Icon For mobile
Up arrow icon