Back to Devexpress

PdfViewer.LoadDocument(Stream) Method

windowsforms-devexpress-dot-xtrapdfviewer-dot-pdfviewer-dot-loaddocument-x28-system-dot-io-dot-stream-x29.md

latest4.4 KB
Original Source

PdfViewer.LoadDocument(Stream) Method

Loads a PDF document from the specified stream.

Namespace : DevExpress.XtraPdfViewer

Assembly : DevExpress.XtraPdfViewer.v25.2.dll

NuGet Package : DevExpress.Win.PdfViewer

Declaration

csharp
public void LoadDocument(
    Stream stream
)
vb
Public Sub LoadDocument(
    stream As Stream
)

Parameters

NameTypeDescription
streamStream

A Stream class descendant.

|

Example

The following example illustrates how to load a document into the PDF Viewer from a stream at runtime.

Create a FileStream object with the specified file path to open the existing file, and call one of the PdfViewer.LoadDocument overloaded method with this stream object passed as a parameter.

Note

The PDF Viewer expects that the input stream is not modified or closed before the component finishes using a document. Set true as the PdfViewer.DetachStreamAfterLoadComplete property value to force the PDF Viewer to complete all input operations after loading a document. Set this property to false to lock files by the input stream (i.e., make it impossible to edit or delete the document until it is opened in the PDF Viewer) and render large PDF files faster.

View Example

csharp
using System.IO;
using System.Windows.Forms;

namespace LoadDocumentFromStream {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();

            // Load a document from the stream.
            FileStream stream = new FileStream("..\\..\\Demo.pdf", FileMode.Open);
            pdfViewer1.LoadDocument(stream);
        }
    }
}
vb
Imports System.IO
Imports System.Windows.Forms

Namespace LoadDocumentFromStream
    Partial Public Class Form1
        Inherits Form

        Public Sub New()
            InitializeComponent()

            ' Load a document from the stream.
            Dim stream As New FileStream("..\..\Demo.pdf", FileMode.Open)
            pdfViewer1.LoadDocument(stream)
        End Sub
    End Class
End Namespace

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the LoadDocument(Stream) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

how-to-show-a-pdf-file-in-the-pdfviewer-winforms/CS/PdfViewerSample/Form1.cs#L23

csharp
stream = new FileStream(@"..\..\Report2.pdf", FileMode.Open);
    pdfViewer1.LoadDocument(stream);
}

how-to-show-a-pdf-file-in-the-pdfviewer-winforms/VB/PdfViewerSample/Form1.vb#L21

vb
If stream Is Nothing Then stream = New FileStream("..\..\Report2.pdf", FileMode.Open)
    pdfViewer1.LoadDocument(stream)
End Sub

See Also

File Operations

PdfViewer Class

PdfViewer Members

DevExpress.XtraPdfViewer Namespace