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.
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.
Define an asynchronous method that gets the stream from the given URL.
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.
Call this method from the constructor synchronously.
Bind the InputFileStream property of PdfViewer to the PdfDocumentStream property.
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:|