Skip to main content

Opening a PDF

Version: 2.0

Opening a PDF

Below are examples for opening a PDF within 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 and opening a PDF directly from a byte array.

If this is the first time using DynamicPDF Viewer make sure that you have downloaded (https://www.dynamicpdf.com/View-PDF-.NET.aspx) and ran our MSI installer on this machine and make sure that our DynamicPDFViewer control has been added to your toolbox inside of Visual Studio.Once that has been done, drag DynamicPdfViewer from the toolbox onto your form. For more details on this procedure please review the Overview section above.

The below examples assume that the forms name in C# is pdfViewer and in VB.NET is MyPdfViewer.

Opening a PDF from File​

A PDF file can be opened using the Open method.

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

Opening a PDF from Byte Array​

To open a PDF directly from a byte array, first create a PdfDocument object out of the byte array then pass that PdfDocument to the Open method of the Viewer control.

The below example assume that the forms name in C# is pdfViewer and in VB.NET is MyPdfViewer.

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

Opening a Password Protected PDF​

If the PDF is encrypted and protected with a password, first create a PdfDocument object specifying the file path and password in the constructor then pass that PdfDocument object to the Open method of the Viewer control.

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

Opening a PDF from Stream​

To open a PDF directly from a System.IO.Stream object, first create a PdfDocument object out of the stream then pass that PdfDocument to the Open method of the Viewer control.

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