.NET PDF to Image Converter SDK

Convert PDF to Image in C#
CnetSDK .NET PDF to Image Converter SDK is a top-notch PDF converter library component for C#.NET projects. It can be used to render, transform, and convert PDF to various raster images, such as converting PDF to JPEG/JPG, TIFF, GIF, BMP, PNG, etc. Mature .NET APIs and methods for PDF to image conversion can be applied to your Visual C#.NET programming. Detailed C# sample codes for rendering and converting PDF to images are offered on this page.
.NET PDF CONVERTER INTEGRATION IN C# PROJECT
In the free trail package, .NET PDF converter for images library is placed based on your Windows System (x86 & x64) and .NET Frameworks version (2.0 & greater). So, please choose the suitable .NET PDF converter library component for your Visual C# programming. Then, you may simply add the CnetSDK.PDFtoImage.Converter.Trial.dll to your C#.NET project reference to integrate and use all PDF to image converter functions.

Please Note: a watermark ("www.cnetsdk.com") will be shown on each converted image file randomly if you are using free trial package of CnetSDK .NET PDF to Image Converter SDK.

.NET PDF CONVERTER APIS FOR C# PROJECT
The following C#.NET APIs and methods can help you convert PDF to images for C#.NET applications. In details, you can easily load a PDF document from a file stream, memory stream or local file on your disk, and then convert the whole PDF file, one PDF page, or a range of PDF pages to raster image file(s). Moreover, image size (width and height) can be customized.    
1. How to Load PDF to C#.NET Program

// Load a PDF to C# project from a filestream or memorystream.
public bool LoadPdfFile(Stream Stream);


// Load a PDF to C# project from a local file.
public bool LoadPdfFile(string fileName);



2. How to Get the Number of PDF Pages

public int FilePageCount;


3. How to Convert PDF to Image in C#.NET Program

// Convert specified page(s) of PDF to image(s) in Visual C# project.
// With current DPI value, the converted image size is original size of PDF page.
public Bitmap ConvertToImage(int pageIndex);


// Convert specified page(s) of PDF to image(s) with defined image size.
public Bitmap ConvertToImage(int pageIndex, int ImageWidth, int ImageHeight);



4. How to Get Width and Height of PDF Page(s)

// Width and height will be changed with different DPI values.
public int GetPageSetHeight(int pageIndex);
public int GetPageSetWidth(int pageIndex);



5. How to Set or Return DPI Value

​public double SetDPI;
.NET PDF TO IMAGE CONVERSION C# SAMPLE CODE
In this section, you will see several pieces of Visual C# sample codes for rendering and converting PDF document to image files. And we only take JPEG image file format as an example in the last two C# demo code. To convert PDF to other image formats in your C#.NET project, please directly change image format to specific one. Please see details as below.
1. C# Sample Code: Load PDF from Local File and Get the Page Number


public void LoadPDFfromFile(string filename)
        {
                PdfFile PDFDoc = new PdfFile();
                PDFDoc.LoadPdfFile(filename);
                int Count = PDFDoc.FilePageCount;
                Console.WriteLine(Count);
        }
2. C# Sample Code: Load PDF from Stream and Get the Page Number


public void LoadPDFfromStream(Stream Stream)
        {
                PdfFile PDFDoc = new PdfFile();
                PDFDoc.LoadPdfFile(Stream);
                int Count = PDFDoc.FilePageCount;
                Console.WriteLine(Count);
        }
3. C# Sample Code: Convert PDF to Image with Original Page Size


public void ConvertPDFtoOriginalSizeImage(string filename)
        {
                PdfFile PDFConverter = new PdfFile();
                PDFConverter.LoadPdfFile(filename);
                PDFConverter.SetDPI = 72;
                int Count = PDFConverter.FilePageCount;
                for (int i = 0; i < Count; i++)
                        {
                                 Bitmap bmp = PDFConverter.ConvertToImage(i);
                         }
         }

4. C# Sample Code: Convert PDF to Image with Specified Size


public void ConvertPDFtoImagewithSpecifiedSize(string filename)
        {
                PdfFile ConvertPDF = new PdfFile();
                ConvertPDF.LoadPdfFile(filename);
                ConvertPDF.SetDPI = 72;
                int Count = ConvertPDF.FilePageCount;
                for (int i = 0; i < Count; i++)
                        {
                                int ImageWidth = 2 * ConvertPDF.GetPageSetWidth(i);
                                int ImageHeight = ConvertPDF.GetPageSetHeight(i) / 2;
                                Bitmap bmp = ConvertPDF.ConvertToImage(i, ImageWidth, ImageHeight);
                                bmp.Save("F:/CnetSDK" + i + ".bmp", ImageFormat.Bmp);
                         }
         }

5. C# Sample Code: How to Convert PDF to JPEG, with Original Page Size


public void ConvertPDFtoJPEGImage(string filename)
        {
                PdfFile PDFDoc = new PdfFile();
                PDFDoc.LoadPdfFile(filename);
                int Count = PDFDoc.FilePageCount;
                PDFDoc.SetDPI = 72;
                for (int i = 0; i < Count; i++)
                        {
                                 Bitmap bmp = PDFDoc.ConvertToImage(i);
                                 bmp.Save("F:/CnetSDK" + i + ".jpeg", ImageFormat.Jpeg);
                         }
         }

6. C# Sample Code: How to Convert PDF to JPEG, with Specified Image Size


public void ConvertPDFtoJPEGwithSpecifiedSize(string filename)
        {
                PdfFile PDFConverter = new PdfFile();
                PDFConverter.LoadPdfFile(filename);
                int Count = PDFConverter.FilePageCount;
                PDFConverter.SetDPI = 150;
                for (int i = 0; i < Count; i++)
                        {
                                 Bitmap bmp = PDFConverter.ConvertToImage(i, 768, 1024);
                                 bmp.Save("F:/CnetSDK" + i + ".jpeg", ImageFormat.Jpeg);
                         }
         }

For your reference, we provide online tutorial for ASP.NET web application PDF to image converting. Please see: How to render & convert PDF to images in ASP.NET web project. Besides, we provide VB.NET programming example for converting PDF document to image files.
CONVERT PDF TO IMAGES IN C# PROJECT

Convert PDF to JPEG/JPG in C#

Convert PDF to GIF in C#

Convert PDF to PNG in C#

Convert PDF to BMP in C#

Convert PDF to TIFF in C#

Convert PDF to Multi-page TIFF in C#