Crash when trying to preview a pdf loaded through a PdfLoadedDocument

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);
                }
            }



1 Reply

SS Sathish Sivakumar Syncfusion Team 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 


Loader.
Up arrow icon