Syncfusion AI Assistant

How can I help you?

Open PDF file in C# and VB.NET

9 Jun 20267 minutes to read

Namespace required

The following namespaces of Essential® PDF need to be included in your application to load the PDF document.

using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Parsing;
Imports Syncfusion.Pdf.Parsing

Opening an existing PDF document

You can open an existing PDF document by using the PdfLoadedDocument class. The following example shows how to load an existing document from physical path.

//Open an existing PDF document from stream through constructor of `PdfLoadedDocument` class. 
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(@"Input.pdf");
//Open an existing document from file system. 
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
'Open an existing document from file system. 
Dim loadedDocument As New PdfLoadedDocument("Input.pdf")

Opening an existing PDF document from Stream

You can open an existing document from stream by using PdfLoadedDocument class as shown below.

//Open an existing PDF document from stream through constructor of `PdfLoadedDocument` class. 
FileStream inputPDFStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputPDFStream);
//Opens an existing document from stream. 
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputPDFStream);
'Opens an existing document from stream. 
Dim loadedDocument As New PdfLoadedDocument(inputPDFStream)

Opening an existing PDF document from byte array

You can open an existing document from byte array by using PdfLoadedDocument class as shown in the below code example.

//Open an existing document from byte array. 
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputPDFByteArray);
//Open an existing document from byte array. 
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputPDFByteArray);
'Opens an existing document from byte array.
Dim loadedDocument As New PdfLoadedDocument(inputPDFByteArray)

Opening an Encrypted PDF document

You can open an existing encrypted PDF document from either the file system or the stream or the byte array using PdfLoadedDocument class as shows in the below code example.

//Open an encrypted PDF document from stream through constructor of `PdfLoadedDocument` class.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(@"Input.pdf", "password");
//Open an existing encrypted document from disk.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf", "password");
'Open an existing encrypted document from disk. 
Dim loadedDocument As New PdfLoadedDocument("Input.pdf","password")
//Open an encrypted PDF document from stream through constructor of `PdfLoadedDocument` class. 
FileStream inputPDFStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputPDFStream, "password");
//Open an existing encrypted document from byte array. 
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputPDFStream, "password");
'Open an existing encrypted document from stream.
Dim loadedDocument As New PdfLoadedDocument(inputPDFStream,"password")
//Open an existing encrypted document from byte array. 
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputPDFByteArray, "password");
//Open an existing encrypted document from byte array. 
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputPDFByteArray, "password");
'Open an existing encrypted document from byte array. 
Dim loadedDocument As New PdfLoadedDocument(inputPDFByteArray,"password")

Opening a corrupted PDF document

You can open a corrupted PDF document from either the file system or the stream or the byte array using the PdfLoadedDocument as shown below.

//Open an existing corrupted PDF document from stream through constructor of `PdfLoadedDocument` class.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(@"Input.pdf", true);
//Open an existing corrupted document from disk. 
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf", true);
'Open an existing corrupted document from disk. 
Dim loadedDocument As New PdfLoadedDocument("Input.pdf", True)
//Open an existing corrupted PDF document from stream through constructor of `PdfLoadedDocument` class. 
FileStream inputPDFStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputPDFStream, true);
//Open an existing corrupted document from stream. 
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputPDFStream, true);
'Open an existing corrupted document from stream. 
Dim loadedDocument As New PdfLoadedDocument(inputPDFStream, True)
//Open an existing corrupted document from byte array. 
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputPDFByteArray, true);
//Open an existing corrupted document from byte array. 
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputPDFByteArray, true);
'Open an existing corrupted document from byte array. 
Dim loadedDocument As New PdfLoadedDocument(inputPDFByteArray, True)

NOTE

  1. The OpenAndRepair overload is capable of resolving basic cross reference offset issues and cannot repair complex document corruption.
  2. Using this overload may cause performance delay when compared with other overloads, due to the repairing process.