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.
Syncfusion Feedback

Crash when trying to preview a pdf loaded through a PdfLoadedDocument

Thread ID:

Created:

Updated:

Platform:

Replies:

129026 Feb 22,2017 11:23 AM UTC Feb 23,2017 06:40 AM UTC Xamarin.Forms 1
loading
Tags: PdfViewer
Marc Marsiñach
Asked On February 22, 2017 11:23 AM UTC

I'm trying to preview a pdf loaded with a PdfLoadedDocument. The complet task should be, load a pdf template, fill the form and preview the pdf. When I try to add the pdf stream to the viewer I get the following crash "Java.IO.IoException: cannot create document. Error 3". 

The simplified code is as follows:

            using (Stream fileStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("MySolution.Template.pdf"))
            {
                var pdfLoadedDocument = new PdfLoadedDocument(fileStream, true);

                using (MemoryStream stream = new MemoryStream())
                {
                    pdfLoadedDocument.Save(stream);
                    pdfLoadedDocument.Close(true);

                    pdfViewerControl.LoadDocument(stream);
                }
            }



Sathish Sivakumar [Syncfusion]
Replied On February 23, 2017 06:40 AM UTC

Hi Marc, 
 
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: 
 
using (Stream fileStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream(files[0])) 
{ 
var pdfLoadedDocument = new PdfLoadedDocument(fileStream, true); 
 
using (MemoryStream stream = new MemoryStream()) 
{ 
pdfLoadedDocument.Save(stream); 
pdfLoadedDocument.Close(true); 
stream.Position = 0; 
pdfViewerControl.LoadDocument(stream); 
} 
} 
 
We have also attached simple sample for your reference in the below link to get rid of this exception: 
 
 
Please try this and let us know whether it resolved the issue at your end. 
 
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.

Warning Icon 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.Close Icon

;