Opening a PDF

The PdfViewer provides an overloaded Open method to open a PDF using a PdfDocument instance or a path to a PDF. The PdfDocument class supports password-protected PDFs and getting the PDF from a Stream. The PdfDocument is then used by the PdfViewer instances' Open method.

The following examples illustrate four ways you can open a PDF using the PDFViewer:

Opening a PDF from File

Use the PdfViewer class's Open method and pass a file path as a string to open a PDF from a file.

public void Open(string filePath)

This example illustrates opening a PDF file using the Open method.

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

Opening a PDF from Byte Array

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

public void Open(PdfDocument document)

The following example illustrates.

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)

More Examples

For more complete examples, refer to the API documentation or refer to the GitHub examples project.

In this topic