2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
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.
This page will automatically be redirected to the sign-in page in 10 seconds.
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.
I have tested with Xamarin forms project it is not working, I tested with Xamarin android project it is working fine.
it is working on Xamarin.android. However, the hyperlinks in the pdf document shown are inaccessible, tapping on a hyperlink does nothing. Any help ?
it is working on Xamarin.android. However, the hyperlinks in the pdf document shown are inaccessible, tapping on a hyperlink does nothing. Any help ?