Load PDF file in C#

8 Dec 20232 minutes to read

User can load a PDF as a stream using PdfToImageConverter, and then we can convert the PDF pages into images.

Loading an existing PDF document using constructor

You can load an existing document to PdfToImageConverter. When creating an instance of the PdfToImageConverter class, pass the PDF document as a stream. The following example shows how to load an existing document from stream using the constructor.

//Load an existing PDF document from stream through constructor of `PdfToImageConverter` class. 
FileStream inputPDFStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
PdfToImageConverter imageConverter = new PdfToImageConverter(inputPDFStream);

Loading an existing PDF document using load method

You can load an existing document to PdfToImageConverter. When using the ‘load’ method of the PdfToImageConverter class, pass the PDF document as a stream. The following example shows how to load an existing document from a stream using the ‘load’ method.

//Load an existing PDF document from stream through load method of `PdfToImageConverter` class.
PdfToImageConverter imageConverter = new PdfToImageConverter();
FileStream inputPDFStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
imageConverter.Load(inputPDFStream);

Loading an Encrypted PDF document using constructor

You can load an existing encrypted document to PdfToImageConverter. When creating an instance of the PdfToImageConverter class, pass the PDF document as a stream and the password required to decrypt the provided PDF file. The following example shows how to load an existing enrypted document from a stream using the constructor.

//Load an encrypted PDF document from stream through constructor of `PdfToImageConverter` class. 
FileStream inputPDFStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
PdfToImageConverter imageConverter = new PdfToImageConverter(inputPDFStream, "password");

Loading an Encrypted PDF document using load method

You can load an existing encrypted document into PdfToImageConverter.When using the ‘load’ method of the PdfToImageConverter class, pass the PDF document as a stream and the password required to decrypt the provided PDF file. The following example shows how to load an existing enrypted document from a stream using the ‘load’ method.

//Load an encrypted PDF document from stream through constructor of `PdfToImageConverter` class.
PdfToImageConverter imageConverter = new PdfToImageConverter();
FileStream inputPDFStream = new FileStream(@"Input.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
imageConverter.Load(inputPDFStream, "password");