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.

PDFViewer Failing on Android

Thread ID:

Created:

Updated:

Platform:

Replies:

130196 Apr 26,2017 08:52 PM May 1,2017 11:03 AM Xamarin.Forms 3
loading
Tags: PdfViewer
Jacob Bullock
Asked On April 26, 2017 08:52 PM

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

Sathish Sivakumar [Syncfusion]
Replied On April 28, 2017 08:47 AM

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 


Jacob Bullock
Replied On April 28, 2017 11:40 AM

That fixed it.  Thanks so much.

Navaneetha Kannan Sudalai Muthu [Syncfusion]
Replied On May 1, 2017 11:03 AM

Hi Jacob, 

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

Best, 
Navaneetha Kannan  


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.

;