C# PDF to PNG Library
How to convert PDF to PNG image files using C#.net in web, windows application
C#.NET PDF to PNG Convertion without open source library, such as itextsharp, pdfsharp, imagemagick.
In this tutorial, you learn how to convert PDF to jpg using C# in ASP.NET web app, and Windows application.
How to PDF file to JPG images using C#
RasterEdge PDF to JPEG converting control SDK (XDoc.PDF for .NET) supports converting PDF file png image file in .NET developing platforms
using simple C# programming code.
You can view more C# PDF conversion functions at
c# convert bitmap to pdf,
c# convert pdf to jpg,
convert pdf to image using c#.net,
c# pdf to tiff converter,
docx to pdf c#,
convert csv to pdf c#.
Quick to convert PDF page to PNG image using C#.NET
The following steps and sample c# code will show how to quickly convert a PDF page to PNG image.
- Create a new PDFDocument with an existing PDF file loaded
- Get a PDFPage object from the first page of the PDF document
- Call PDFPage.ConvertToImage() to convert PDF page to a PNG image file
String inputFilePath = @"W:\Projects\Test-Files\file1.pdf";
String outputFilePath = @"W:\Projects\Test-Output\RasterEdge.com\pdf-convert-pdf-to-png-start.png";
// Open file and get the target page
PDFDocument doc = new PDFDocument(inputFilePath);
PDFPage page = (PDFPage)doc.GetPage(0);
// Convert page to a PNG image
page.ConvertToImage(ImageType.PNG, outputFilePath);
PDF to PNG Image Options Using C#
With XDoc.PDF for .NET, you can easily convert single PDF file or mutliple PDF documents into PNG images.
The following png image settings supported in class "ImageOutputOption":
- Color: Output png image is Monochrome, Gray, Color.
- PngInterlance: True, create an Interlaced PNG; False, create a Non-interlaced PNG.
Non-interlaced PNG encodes an image from start to finish; but Interlaced PNG encodes a whole
image at low quality at beginning and then on each successive pass it encodes more of the detail,
until the complete image has been processed.
- PngFilter:
In PNG, a filter algorithm could be applied before compression which makes the image data for optimum compression.
None: the scanline is transmitted unmodified.
Sub: it transmits the difference between each byte and the value of the corresponding byte of the prior pixel.
Up: it is just like the Sub filter except that the pixel immediately above the current pixel, rather than just to its left, is used as the predictor.
Average: it uses the average of the two neighboring pixels (left and above) to predict the value of a pixel.
Paeth: it computes a simple linear function of the 3 neighboring pixels (left, above, upper left), then chooses as predictor the neighboring pixel closest to the computed value.
- Zoom: Set zoom value to 2F. Use more pixels to render the page.
- Resolution: Set image resolution value in the PNG file.
String inputFilePath = @"C:\1.pdf";
String outputFilePath = @"C:\output.png";
ImageOutputOption options = new ImageOutputOption();
// Set output image type.
options.Type = ImageType.PNG;
// Output image is grayscale.
options.Color = ColorType.Gray;
// Set interlaced flag to true.
options.PngInterlance = true;
// Set filter type to SUB
options.PngFilter = FilterPNG.SUB;
// Set zoom value to 2F. Use more pixels to render the page.
options.Zoom = 2F;
// Set resolution value in the PNG file to 300 dpi.
options.Resolution = 300;
// Open file and get the target page
PDFDocument doc = new PDFDocument(inputFilePath);
PDFPage page = (PDFPage)doc.GetPage(0);
// Convert page to a PNG image
page.ConvertToImage(options, outputFilePath);
String inputFilePath = @"C:\1.pdf";
String outputFilePath = @"C:\output.png";
ImageOutputOption options = new ImageOutputOption();
// Set output image type.
options.Type = ImageType.PNG;
// Output image is color.
options.Color = ColorType.Color;
// Set interlaced flag to false.
options.PngInterlance = false;
// Set filter type to Average
options.PngFilter = FilterPNG.Average;
// Set resolution value in the PNG file to 192 dpi.
options.Resolution = 192;
// Open file and get the target page
PDFDocument doc = new PDFDocument(inputFilePath);
PDFPage page = (PDFPage)doc.GetPage(0);
// Convert page to a PNG image
page.ConvertToImage(options, outputFilePath);
How to convert multiple PDF files to PNG image files using C# .NET
The below steps and c# source code will instruct how to convert all PDF files in one file directory to PNG image files using C# .NET
- Get all PDF file paths under one directory
- For each PDF file, create a new PDFDocument with PDF content loaded.
- Call PDFPage.ConvertToImage() to convert each PDF page to a PNG image file
String inputDirectory = @"C:\input\";
String outputDirectory = @"C:\output\";
String[] files = Directory.GetFiles(inputDirectory, "*.pdf");
foreach (String filePath in files)
{
int startIdx = filePath.LastIndexOf("\\");
int endIdx = filePath.LastIndexOf(".");
String docName = filePath.Substring(startIdx + 1, endIdx - startIdx - 1);
PDFDocument doc = new PDFDocument(filePath);
doc.ConvertToImages(ImageType.PNG, outputDirectory, docName);
}