Back to Devexpress

How to: Load a PDF Document from a Uri

wpf-114459-controls-and-libraries-pdf-viewer-examples-file-operations-how-to-load-a-pdf-document-from-a-uri.md

latest1.9 KB
Original Source

How to: Load a PDF Document from a Uri

  • May 16, 2019

This example shows how to use the DocumentViewerControl.DocumentSource property to load a document from a Uri.

View Example

csharp
using System;
using System.Windows;
using System.Reflection;

namespace LoadPDFDocument
{

    public partial class MainWindow : Window
    {

        public MainWindow()
        {
            InitializeComponent();

            Uri baseUri = new Uri(Assembly.GetEntryAssembly().Location);
            Uri uri = new Uri(baseUri, "..\\..\\Demo.pdf");
            Viewer.DocumentSource = uri;
        }
    }
}
vb
Imports System
Imports System.Windows
Imports System.Reflection

Namespace LoadPDFDocument

    Partial Public Class MainWindow
        Inherits Window

        Public Sub New()
            InitializeComponent()

            Dim baseUri As New Uri(System.Reflection.Assembly.GetEntryAssembly().Location)
            Dim uri As New Uri(baseUri, "..\..\Demo.pdf")
            Viewer.DocumentSource = uri
        End Sub
    End Class
End Namespace
xaml
<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dxpdf="http://schemas.devexpress.com/winfx/2008/xaml/pdf" 
        x:Class="LoadPDFDocument.MainWindow"
        Title="MainWindow" Height="350" Width="525">

    <Grid>
        <dxpdf:PdfViewerControl x:Name="Viewer"
                                DocumentSource="pack://application:,,,/DxPdfViewer;component/Demo.pdf"/>
    </Grid>
</Window>