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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to load PDF document in SfPdfViewer Xamarin.Forms from given URL?

PDF documents can be loaded into the PdfViewer from a given URL by downloading the PDF and then loading the stream of the downloaded file to the PdfViewer. Refer to the following code snippets.

 

Add a new ViewModel class named PdfViewerViewModel to the PCL or .NET Standard project. The class must implement the INotifyPropertyChanged interface.

C#

 

Define a new property named PdfDocumentStream in the class. In the setter accessor of the property raise the PropertyChanged event once the value is set to the private field of the property.

C#

 

Define an asynchronous method that gets the stream from the given URL.

C#

 

The stream returned by the previous method must be set to the PdfDocumentStream property in the constructor. As the constructor cannot be executed asynchronously, define another asynchronous method and call the DownloadPdfStream method from inside it.

C#

Call this method from the constructor synchronously.

C#

 

Bind the InputFileStream property of PdfViewer to the PdfDocumentStream property.

XAML

 

 

Sample link:

http://www.syncfusion.com/downloads/support/directtrac/general/ze/LoadPDFFromURL-1169310981 

Note

PdfViewer loads the PDF as soon as the InputFileStream property is set to a stream. In the previous sample PDFs may not load immediately. This is due to the time taken for the stream to be fetched from the URL asynchronously. This must not be taken as a PdfViewer defect.

Article ID: Published Date: Last Revised Date: Platform: Control: .NET Framework:
8730 05/07/2018 06/05/2018 Xamarin.Forms PdfViewer 4.5.1
Did you find this information helpful?
Comments
Danny Ackerman Jun 06, 2018

I tried doing this, but the PDF Viewer spinner just goes on forever, never loading the document.

Reply
Navaneetha Kannan Sudalai Muthu [Syncfusion] Jun 07, 2018

Hi Danny,

 

The sample attached in this KB article works as expected if run as such. It will take approximately 2 seconds to fetch the PDF from the given URL during which PdfViewer’s loading indicator will rotate as you have mentioned.

 

If you have changed the URL provided in the sample and the PDF at the URL is very large it may take longer to fetch the PDF from the URL. Until the PDF stream is obtained the loading indicator will rotate in PdfViewer. If this is the case kindly wait until the PDF is fetched and loaded. As we have mentioned in the article it is not the responsibility of PdfViewer to read the PDF from URL. The PdfViewer loads the PDF as soon as it is read from the URL. So the delay occurs in reading the PDF and this is not a defect of PdfViewer.

 

If you still face the issue after trying the above suggestion, please contact Syncfusion support (support@syncfusion.com) to get further assistance.

Best,

Navaneetha Kannan 

Navaneetha Kannan Sudalai Muthu [Syncfusion] Jun 07, 2018

Hi Danny,

 

The issue may also occur if the device (iPhone or Android) to which the application is deployed does not have an active internet connection. It is not enough that the machine in which the sample is built and deployed is connected to the network, but the device in which the application runs has to be connected to the internet. Kindly ensure that the device is connected to either internet (if the URL is online) or the local network (if the URL is hosted locally).

 

Best,

Navaneetha Kannan

Add Comment
You must log in to leave a comment

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