Opening a PDF

There are several ways you can open a PDF using DynamicPDF Viewer for .NET within a Windows application. For example, you can open a PDF using a file, a byte array, open a password protected PDF, or open a PDF using a Stream.

The following examples illustrate the different ways you might open a PDF using the DynamicPDF Viewer for .NET control within a Windows Application. These simple examples demonstrate opening a PDF from a file, opening an encrypted PDF from a file, opening a PDF directly from a byte array, and opening a PDF using a Stream.

Installation

If this is your first time using DynamicPDF Viewer, ensure you install the software using the MSI installer provided by DynamicPDF at (https://www.dynamicpdf.com/View-PDF-.NET.aspx). After installing, add the DynamicPDFViewer control to your Visual Studio toolbox. You can then use the toolbox to add a DynamicPDFViewer control to your Windows form. See Overview for more details.

NOTE: The examples assume the C# form name is pdfViewer while the VB.NET form name is MyPdfViewer.

Opening a PDF from File

This example illustrates opening a PDF file using the Open method. As the example illustrates, opening a PDF from a file is straightforward.

pdfViewer.Open(pdfFilePath);       
MyPdfViewer.Open(pdfFilePath)

Opening a PDF from Byte Array

Opening a PDF directly from a byte array requires you first create a PdfDocument instance by passing a byte array to the constructor. You then pass the PdfDocument instance to your Viewer control using the Open method.

PdfDocument pdfDocument = new PdfDocument(pdfData);
pdfViewer.Open(pdfDocument);        
MyPdfDocument as PdfDocument = New PdfDocument(MyPdfBytes)
MyPdfViewer.Open(MyPdfDocument)

Opening a Password Protected PDF

If a PDF is encrypted and password protected, create a PdfDocument instance by passing the file path and password to the constructor. Then pass the PdfDocument instance to your DynamicPDF Viewer control instance using the Open method.

PdfDocument pdfDocument = new PdfDocument(pdfFilePath, "password");
pdfViewer.Open(pdfDocument);        
MyPdfDocument as PdfDocument = New PdfDocument(pdfFilePath, "password")
MyPdfViewer.Open(MyPdfDocument)

Opening a PDF from Stream

You can also open a PDF document directly using a System.IO.Stream instance. To accomplish this, create a PdfDocument instance from the stream. Then pass the PdfDocument instance to your Viewer control using the Open method.

PdfDocument pdfDocument = new PdfDocument(pdfStream);
pdfViewer.Open(pdfDocument);        
MyPdfDocument as PdfDocument = New PdfDocument(MyStream)
MyPdfViewer.Open(MyPdfDocument)

In this topic