)
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: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to display PDF document from URL using SfPdfViewer in Xamarin.Android?

Platform: Xamarin.Android |
Control: PdfViewer |
Published Date: September 15, 2017 |
Last Revised Date: May 6, 2019

How to display PDF document from URL using SfPdfViewer in Xamarin.Android?

At present SfPdfViewer in Xamarin.Android do not have a direct support to display the PDF document from URL. However, as a workaround you can download the document or files from URL as Stream using WebClient class and load it in the PDF viewer.

The below code snippet illustrates how to download the PDF document from URL as Stream using WebClient:

C#:

/// <summary>
/// Download PDF document as stream from the given URL
/// </summary>
/// <param name="URL">URL which holds PDF document</param>
/// <returns></returns>
private Stream DownloadPdfStream(string URL)
{
//Initialize WebClient
WebClient webClient = new WebClient();
// Initialize Uri
var uri = new System.Uri(URL);
//Returns the document stream from the given URL
return webClient.OpenRead(uri);
 
}

 

Then we can load the downloaded PDF document Stream to display it in PDF viewer in Xamarin.Android. Please find the code snippet below for your reference:

C#:

protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
//Set the activity content from a layout resource
SetContentView(Resource.Layout.Main);
// Finds a SfPdfViewer that was identified by resource id
var pdfViewerControl = FindViewById<SfPdfViewer>(Resource.Id.pdfviewerControl);
//Download PDF document from the given URL as a stream
Stream pdfStream = DownloadPdfStream("http://www.syncfusion.com/downloads/support/directtrac/general/pd/Xamarin-Forms-Succinctly1843641035");
//Load the downloaded PDF document stream to display it in SfPdfViewer
pdfViewerControl.LoadDocument(pdfStream);
}

 

Sample Link:

http://www.syncfusion.com/downloads/support/directtrac/general/ze/PdfViewerSample-1610083496

 

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
Balakrishnan
Jun 12, 2018

It is not loading all the pages of the PDF file, It loads only one or two pages only. Is there any solution for that.

Reply
Balakrishnan
Jun 12, 2018

I have tested with Xamarin forms project it is not working, I tested with Xamarin android project it is working fine.

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

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

Live Chat Icon For mobile
Live Chat Icon