How to C#: PDF
Use PDF SDK for C#.NET
Convert PDF to Image (Jpeg ...)

Convert PDF to Jpeg, Png, Bmp, Gif Images, .NET Graphics, or REImage

Home ›› XDoc.PDF ›› C# PDF: PDF to Image

C# PDF - Render PDF to Raster Images


Online C# Tutorial for How to Convert PDF to Raster Images, .NET Graphics, and REImage




PDF to Multiple Image Forms Conversion



RasterEdge.com provides C# developers with mature PDF document processing and rendering library SDK. Our XDoc.PDF allows C# developers to perform high performance conversions from PDF document to multiple image forms, including raster images Jpeg, Png, Bmp, and Gif, .NET Graphics, and REImage (an intermediate class). In the following parts, we provide some examples for these PDF conversions.




C# Sample Code for PDF to Jpeg



Copy demo code below to achieve fast conversion from PDF file to Jpeg image.




// Used to register all DLL assemblies.
WorkRegistry.Reset();

// Load a PDF file.
String inputFilePath = Program.RootPath + "\\" + "1.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);

// Get the first page of PDF file.
PDFPage page = (PDFPage)doc.GetPage(0);

// Convert the first PDF page to a JPEG file.
page.ConvertToImage(ImageType.JPEG, Program.RootPath + "\\Output.jpg");





C# Sample Code for PDF to Png



You may choose to convert PDF file to Png image.




// Used to register all DLL assemblies.
WorkRegistry.Reset();

// Load a PDF file.
String inputFilePath = Program.RootPath + "" + "1.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);

// Get the first page of PDF file.
PDFPage page = (PDFPage)doc.GetPage(0);

// Convert the first PDF page to a PNG file.
page.ConvertToImage(ImageType.PNG, Program.RootPath + "Output.png");





C# Sample Code for PDF to Bmp



Or use this piece of C# code to implement PDF to Bmp conversion.




// Used to register all DLL assemblies.
WorkRegistry.Reset();

// Load a PDF file.
String inputFilePath = Program.RootPath + "\\" + "1.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);

// Get the first page of PDF file.
PDFPage page = (PDFPage)doc.GetPage(0);

// Convert the first PDF page to a BMP file.
page.ConvertToImage(ImageType.BMP, Program.RootPath + "\\Output.bmp");





C# Sample Code for PDF to Gif



You can also directly change PDF to Gif image file in C# program.




// Used to register all DLL assemblies.
WorkRegistry.Reset();

// Load a PDF file.
String inputFilePath = Program.RootPath + "\\" + "1.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);

// Get the first page of PDF file.
PDFPage page = (PDFPage)doc.GetPage(0);

// Convert the first PDF page to a GIF file.
page.ConvertToImage(ImageType.GIF, Program.RootPath + "\\Output.gif");





C# Sample Code for PDF to REImage



Instead, you may render PDF to REImage (an intermidate class) and then do further manipulations.




// Used to register all DLL assemblies.
WorkRegistry.Reset();

// Load a PDF.
String inputFilePath = Program.RootPath + "\\" + "1.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);

// Get the first page of PDF.
PDFPage page = (PDFPage)doc.GetPage(0);

// Convert the first page to a REImage object.
REImage image = page.ConvertToImage();

// Do something ...





C# Sample Code for PDF to .NET Bitmap



Moreover, you can render PDF to .NET Bitmap in C# programming.




// Used to register all DLL assemblies.
WorkRegistry.Reset();

// Load a PDF file.
String inputFilePath = Program.RootPath + "\\" + "1.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);

// Get the first page of PDF.
PDFPage page = (PDFPage)doc.GetPage(0);

// Render the page to a Bitmap with default setting.
Bitmap bitmap1 = page.GetBitmap();
bitmap1.Save(inputFilePath + "_1.bmp");
//  ...

// Enlarge the page with factor 2.
float zoomRatio = 2.0F;
Bitmap bitmap2 = page.GetBitmap(zoomRatio);
bitmap2.Save(inputFilePath + "_2.bmp");
//  ...

// Render the page with a resolution of 300 dpi.
int targetResolution = 300;
Bitmap bitmap3 = page.GetBitmap(targetResolution);
bitmap3.Save(inputFilePath + "_3.bmp");
//  ...