Skip to main content
A newer version of this page is available. .

How to: Load a PDF Document from a Stream

This example shows how to load a document from the Stream using the DocumentViewerControl.DocumentSource property. The stream is obtained from the assembly resources:

Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);

Note that when you load a document, the input stream will not be closed before the control finishes using a document (PdfViewerControl.DetachStreamOnLoadComplete is set to false by default). This allows the PDF Viewer to render a large PDF quickly.

using System.IO;
using System.Reflection;
using System.Windows;

namespace LoadPDFDocument {

    public partial class MainWindow : Window {

        public MainWindow() {
            InitializeComponent();
            Stream stream = GetResourceStream("LoadPDFDocument.Demo.pdf");           
            Viewer.DocumentSource = stream;
        }
        static Stream GetResourceStream(string resourceName) {
            return Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
        }
    }
}