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

Loading a PDF from URL in MVVM

I have an application that utilizes several SF components, and on the particular page that I'm working on, I'm using SfCheckBox, SfTabView & SfPdfViewer.


My SfTabView has 3 Tabs (Search, Results & Details).

On the Search Tab, I select criteria, then pass that criteria to an API Request which returns a list of items that I display on the Results Tab.

From the Results Tab, I select an item and that passes more details to another API Request that returns a string URL. That URL points to a PDF file that I want to view with SfPdfViewer on the Details Tab.

Everything that I've tried from the documentation and through other forums points me to linking the Stream in the XAML.cs in OnAppearing, but I can't load the stream there since the page has already appeared before I have the URL link.


When I try to use MVVM binding like this, I get an error (Object reference not set to an instance of an object):

PdfStream = DependencyService.Get<IDownloader>().DownloadPdfStream("https://url_long_link.pdf", "Invoice PDF");

How can I perform LoadStream(documentStream) from within my ViewModel instead of the code behind page?

3 Replies

GR Gayathri Ramalingam Syncfusion Team September 5, 2019 12:33 PM UTC

Hi Matthew, 
We tried to reproduce the issue “Null reference exception occurs while loading the PDF document from given URL” in Xamarin.Forms. On further analysis the PDF document from URL which is shared by you is not opened in Browser page itself. Please find the below screen shot which shows that the given URL is invalid. 
 
Could you please ensure whether valid URL has been given to PDF Viewer? 
Kindly share the following details to analyze more on this issue  and it will be helpful for us to provide solution at the earliest.   
  1. Simple sample with which the issue could be reproduced. 
  2. Replication procedure to reproduce the issue or screen shot illustrating the issue. 
  3. Android / iOS device specification with the OS version. 
  4. PDF document or valid URL with which the issue could be reproduced 

 
With Regards, 
Gayathri R  
 



MB Matthew Bailey September 5, 2019 01:08 PM UTC

I removed the URL link, because the infomation within the PDF I'm trying to view has private data, but I can confirm that the URL link returned from the API is valid.

For sake of time, I replaced my API string return with this URL https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf -- and I receive the same error - yet this URL opens a PDF from a browser like I would expect.

Since there is a file size limitation of 30MB, I couldn't attach my video screengrab, so I hope that posting here will be suitable for you to see what my app is actually doing.

https://www.youtube.com/watch?v=vfSxfzBmbh4



GR Gayathri Ramalingam Syncfusion Team September 6, 2019 12:52 PM UTC

Hi Matthew,  
  
We have tried to reproduce the issue “Null reference exception occur while loading PDF document from URL using PDF Viewer” in Xamarin.Forms platform, but it is working fine as expected. Kindly refer the sample in the below link which we created to reproduce the reported issue.  
 
We created a video for illustrating the same and it can be downloaded from the below links, 
 
Note: Kindly ensure that the proper wi-fi connection is enabled in emulator/device before deploying. 
 
Kindly share the following details to analyze more on this issue  and it will be helpful for us to provide solution at the earliest.   
 
1.       Modify / Simple sample with which the issue could be reproduced.  
2.       Replication procedure to reproduce the issue or screen shot illustrating the issue.  
3.     Android device specification with the OS version.  
4.       SfPdfViewer version 
5.       Xamarin.Forms version 
 
 
With Regards, 
Gayathri R 
 



Loader.
Live Chat Icon For mobile
Up arrow icon