How to Convert PDF File to Images in C#
- PDF to Image Converter
- Convert PDF File to Images in C# Using the PDFium Package
- Convert PDF File to Images in C# Using the Syncfusion Package
- Convert PDF File to Images in C# Using PDFRasterizer
This article demonstrates the conversion of PDF files to images in C#.
We will explore two methods to convert PDF files into images. To elaborate thoroughly, we will create C# projects step by step and provide all the code snippets.
PDF to Image Converter
There are multiple ways to convert PDF files to images using C#. You can use third-party assemblies to create a converter or create your own.
We will make a converter to convert PDF files to images using two different assemblies. These are:
- PDFium
- Syncfusion
These two NuGet packages can be installed from nuget.org into your projects. Let’s create a C# project and guide to install these packages step by step.
Convert PDF File to Images in C# Using the PDFium Package
-
Create a
Console Applicationin Visual Studio. We recommend Visual Studio 2019 or later to install and work with these packages.
-
Click on the
Projecttab and selectManage NuGet Packages, or click on theToolstab, selectNuGet Package Manager, and selectManage NuGet Packages for Solution.

-
Select the
Browsetab and set thePackage Sourceasnuget.org. -
Suppose you do not find
nuget.orgin thePackage Sourcewindow; add it by clicking on theSettingstab. Click the+icon and type the name and source shown in the image.
-
Type
PDFiumin the search bar. Install PdfiumViewer, PdfiumViewer.Native.x86.v8-xfa, and PDFium.x86.

-
After you install these packages, a reference to PdfiumViewer will be available in the
Referenceswindow. Create a folder in your project directory namedSamplesand place the PDF file you want to convert in this folder.
-
Add a reference to
System.Drawingto import this assembly into your project. Right-click on theReferencestab in theSolution Explorerwindow, selectAdd Reference, navigate toFramework, and selectSystem.Drawing.

-
Add the following code snippet to the
Program.csfile. You can customize the input and output file name as per your requirement. -
This code snippet will convert single-page and multi-page documents. After executing the code, your PDF file should be converted to images (each PDF file page as an image).
using PdfiumViewer; using System; using System.Drawing.Imaging; using System.IO; using System.Linq; namespace PdfToImage { class Program { static void Main(string[] args) { var projectDirectory = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName; try { using (var document = PdfDocument.Load(projectDirectory + @"\Samples\document.pdf")) { var pageCount = document.PageCount; for (int i = 0; i < pageCount; i++) { var dpi = 300; using (var image = document.Render(i, dpi, dpi, PdfRenderFlags.CorrectFromDpi)) { var encoder = ImageCodecInfo.GetImageEncoders().First(c => c.FormatID == ImageFormat.Jpeg.Guid); var encoderParams = new EncoderParameters(1); encoderParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L); image.Save(projectDirectory + @"\Samples\image_" + i + ".jpg", encoder, encoderParams); } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.WriteLine("Pdf converted to images. Press any key to exit..."); Console.ReadKey(); } } } -
If you face the exception
Unable to find an entry point named 'FPDF_AddRef' in DLL 'pdfium.dll.', you need to change the target platform in your build setting. -
Navigate to the
Buildtab and select the platform target according to your system, i.e., x86 or x64. If you do not find the platform target underBuild, select theProjecttab, select project properties, and find the platform target underBuild.

Convert PDF File to Images in C# Using the Syncfusion Package
-
Create a
Console Applicationin Visual Studio 2019 or a higher version by following step 1 as discussed above. -
Follow steps 2 and 3, described in the above section, to browse the Syncfusion package from NuGet.org.
-
Search for the
Syncfusion.pdfViewer.Windowspackage and install it.
-
Add references to
System.DrawingandSystem.Windows.Formsby following step 6 mentioned above.
-
Copy the following code snippet into your
Program.csfile to convert a single page of a PDF file to an image. You can customize it for multipage conversion using theforloop. -
Customize the input and output file names as per your requirement. You can select the specific page to convert by passing the appropriate parameter in the
ExportAsImage()method.using Syncfusion.Pdf.Parsing; using Syncfusion.Windows.Forms.PdfViewer; using System.Drawing; using System.Drawing.Imaging; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PDFToJPEG { class Program { static void Main(string[] args) { // Initialize the PdfViewer Control PdfViewerControl pdfViewer = new PdfViewerControl(); // Load the input PDF file PdfLoadedDocument document = new PdfLoadedDocument("../../Data/document.pdf"); pdfViewer.Load(document); Bitmap image = pdfViewer.ExportAsImage(0); // Save the image. image.Save("output.jpg", ImageFormat.Jpeg); } } }Navigate to the project directory->bin->Debug to find the output image file.
Convert PDF File to Images in C# Using PDFRasterizer
PDFRasterizer is a tool to convert PDF files to images developed in C#. It provides the GUI using Windows form.
You can download the source code and can use it without any errors. Navigate to PDFRasterizer to download the component.