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

PDF Viewer Not Displaying Documents?

I'm having trouble getting the new SfPdfViewer to work properly. When looking at the component documentation for other platforms (none exist for Xamarin at the moment), it says to create a "PdfLoadedDocument" from a Stream and use it as the arg in LoadDocument(). However, LoadDocument() only accepts Stream as an argument type, so I tried the stream from GetManifestResourceStream() of an embeded resource, but nothing is popping up. I tried multiple PDFs and made sure to set the Content of ContentPage to the created PdfViewerControl with no luck. No syntax errors appear and I can see at runtime the PdfViewerControl accepts the stream, but it doesn't seem to parse it and get page numbers, etc. Any ideas?

3 Replies

BS Balasubramanian Sundararajan Syncfusion Team October 12, 2016 02:23 PM UTC

Hi Adeem,  

Thanks you for using Syncfusion product. 

We have created a simple sample which loads and display the PDF document in our PDF viewer Xamarin Forms (iOS/Android). Please find the sample from the following link, 



XAML Design: 

Please find the xaml design page which describes adding the PDF viewer control to a Grid. 

 
<Grid >    
    <sfpdfviewer:PdfViewerControl x:Name="pdfViewerControl"/> 
</Grid> 



C# Code: 

The below code example is for loading the PDF document in the PDF viewer control. 

 
protected override void OnAppearing() 
{ 
 
     base.OnAppearing(); 
 
     var fileStream = typeof(App).GetTypeInfo().Assembly. 
            GetManifestResourceStream("GettingStarted_PDFViewer.Assets.GIS Succinctly.pdf); 
 
      // Loads the PDF document in PDF viewer control. 
      pdfViewerControl.LoadDocument(fileStream);             
} 


Note: We are recommending to load the PDF document in the OnAppearing Method.  

We have also published the Xamarin Store PDF viewer getting Started documentation which explain the step by step procedure for Viewing the PDF document in PDF viewer Xamarin Forms. Kindly refer the following link for more details on the component. 


Please try the above sample and the code snippet in your project and let us know if you face any problems in adding the PDF viewer control. 

Thanks, 
Balasubramanian S 



AD Adeem October 13, 2016 12:16 AM UTC

Thanks for the reply, unfortunately I still can't get it to work properly. I made sure i have all the DLLs refrenced and "new SfPdfDocumentViewRenderer()" in the iOS project, but still no PDF is showing up. On a physical Android phone the app crashes and on the iOS simulator only a white screen appears. I used the same code sample you mentioned, no compilation errors happen, but when i run the app the reader doesn't seem to be correctly parsing the input stream. From what I can tell, it can get the pdf data from the stream, but it can't read or parse into page numbers etc

protected override void OnAppearing()
        {
            base.OnAppearing();
            Stream documenStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("The_Complete_Guide_To_APUSH.iOS.Docs.AMSCO2016Key.pdf");

            PdfViewerControl pdfViewer = new PdfViewerControl();
            pdfViewer.LoadDocument(documenStream);

            Content = pdfViewer;
        }


BS Balasubramanian Sundararajan Syncfusion Team October 13, 2016 12:44 PM UTC

Hi Adeem, 

Thank you for your update. 

A support incident to track the status of this query has been created under your account for your last updated query. Please log on to our support website to check for further updates 
 
Thanks, 
Balasubramanian S  


Loader.
Live Chat Icon For mobile
Up arrow icon