This question is locked. New answers and comments are not allowed.
Hi,
I want to load pdf files dynamically to the pdf viewer but the file is not displaying.
DocumentStream is binded on the DocumentSource and assigned by this code:
Converter for the DocumentStream
It's not displaying even if i tried to load from absolute/relative uri
Please help.
Thanks,
Cielo
I want to load pdf files dynamically to the pdf viewer but the file is not displaying.
<
telerik:RadPdfViewer Grid.Row="1" HorizontalAlignment="Stretch" Margin="0" DocumentSource="{Binding DocumentStream, Converter={StaticResource DocumentConverter}, ConverterParameter=1}" VerticalAlignment="Stretch" />
DocumentStream is binded on the DocumentSource and assigned by this code:
#Region "Property" Private m_DocumentStream As Stream Public Property DocumentStream As Stream Get Return m_DocumentStream End Get Set(value As Stream) m_DocumentStream = value Me.RaisePropertyChanged("DocumentStream") End Set End Property#End Region #Region "Sub" Private Sub ReadStream(absolutePath As String) Dim wc = New WebClient() AddHandler wc.OpenReadCompleted, AddressOf OnWebReadCompleted wc.OpenReadAsync(New Uri(absolutePath, UriKind.Absolute)) End Sub Private Sub OnWebReadCompleted(sender As Object, e As OpenReadCompletedEventArgs) ' Read your stream from e.Result DocumentStream = e.Result End Sub#End Region #Region "Navigation" Public Sub ConfirmNavigationRequest(navigationContext As Microsoft.Practices.Prism.Regions.NavigationContext, continuationCallback As System.Action(Of Boolean)) Implements Microsoft.Practices.Prism.Regions.IConfirmNavigationRequest.ConfirmNavigationRequest continuationCallback(True) End Sub Public Function IsNavigationTarget(navigationContext As Microsoft.Practices.Prism.Regions.NavigationContext) As Boolean Implements Microsoft.Practices.Prism.Regions.INavigationAware.IsNavigationTarget End Function Public Sub OnNavigatedFrom(navigationContext As Microsoft.Practices.Prism.Regions.NavigationContext) Implements Microsoft.Practices.Prism.Regions.INavigationAware.OnNavigatedFrom End Sub Public Sub OnNavigatedTo(navigationContext As Microsoft.Practices.Prism.Regions.NavigationContext) Implements Microsoft.Practices.Prism.Regions.INavigationAware.OnNavigatedTo Dim strDocument As String = navigationContext.Parameters("DocumentPath") ReadStream(strDocument) End Sub Public ReadOnly Property KeepAlive As Boolean Implements Microsoft.Practices.Prism.Regions.IRegionMemberLifetime.KeepAlive Get Return True End Get End Property#End RegionConverter for the DocumentStream
Namespace Converter Public Class DocumentConverter Implements IValueConverter Public Function Convert(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert Dim file As PdfDocumentSource Dim intParam As Integer = CInt(parameter) If Not value Is Nothing Then Select Case intParam Case 1 'pdf Using stream As Stream = Application.GetResourceStream(GetResourceUri("documents/test.pdf")).Stream Dim x As Uri x = New Uri("http://localhost:50609/documents/test.pdf") file = New PdfDocumentSource(stream) Return file End Using Case 2 'word Case 3 'excel End Select Else Return Nothing End If End Function Public Function ConvertBack(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack End Function Public Shared Function GetResourceUri(resource As String) As Uri Dim assemblyName As New AssemblyName(GetType(DocumentConverter).Assembly.FullName) Dim resourcePath As String = "/" + assemblyName.Name + ";component/" + resource Dim resourceUri As New Uri(resourcePath, UriKind.Relative) Return resourceUri End Function End ClassIt's not displaying even if i tried to load from absolute/relative uri
Please help.
Thanks,
Cielo
