C# PDF to Image Converter Library
How to convert PDF page to gif, bitmap images in byte array using C#.net. Free open source examples
Online C# Demo Codes for Converting PDF to Raster Images, .NET Graphics, and REImage in C#.NET Project
In this C# tutorial, you will learn how to convert PDF document to raster images, such as png, jpeg2000, gif, using C# in ASP.NET, Windows application
- Convert PDF to images with basic image settings in file or byte array
- Convert PDF to PNG with png image settings
- Convert PDF to JPEG2000 with JPEG2000 image settings
- Batch conversion
How to convert PDF to image files using C#
- Best PDF converter SDK for Visual Studio .NET for converting PDF to image in C#.NET application
- Free .NET DLLs for converting PDF to images in both .NET WinForms and ASP.NET application
- An advanced .NET control able to batch convert PDF documents to image formats in C#.NET
- Support exporting PDF to multiple image forms, including Jpg, Png, Bmp, Gif, Tiff, Bitmap, .NET Graphics, and REImage
- Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint
- Professional .NET library and Visual C# source code for creating high resolution images from PDF in C#.NET class
- Create image files including all PDF contents, like watermark and signature in .NET
- Turn multipage PDF file into single image files respectively in .NET framework
- Converter control easy to create thumbnails from PDF pages
- Selection for compressing to multiple image formats
- Cut and paste any areas in PDF pages to images
- Supports to resize images in 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. Besides raster image Jpeg, images forms
like Png, Bmp, Gif, .NET Graphics, and REImage (an intermediate class) are also supported. In the following parts, we provide some examples for these PDF conversions.
Image Formats Supported
With XDoc.PDF for .NET, you can easily convert Adobe PDF pages to any of the following raster image formats:
- ImageType.BMP
- ImageType.GIF
- ImageType.PNG
- ImageType.JPEG
- ImageType.JPEG2000
- ImageType.TIFF
Image Conversion Options in C#
Class ImageOutputOption allows you to apply image option settings during converting PDF pages to raster images in C#.
Bitmap (BMP), Gif, JPEG2000 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.
- Zoom: Set zoom value to 2F. Use more pixels to render the page.
- Resolution: Set image resolution value in the JPEG file.
PNG image options using C#
Please view PNG image option details at How to convert PDF pages to PNG images in C#.NET.
JPEG image options
Please go to How to convert PDF pages to JPEG images in C# for JPEG image options.
TIFF image options
Please go to How to convert PDF file to multipage TIFF image in C# for TIFF image options.
C# convert single pdf file to image with image settings
#region convert single pdf file to image with image settings(file to file)
internal static void pdf2Image()
{
String inputFilePath = @"C:\demo.pdf";
String outputDirectory = @"C:\output\";
ImageOutputOption ops = new ImageOutputOption();
ops.Color = ColorType.Monochrome;
ops.Resolution = 120;
PDFDocument doc = new PDFDocument(inputFilePath);
doc.ConvertToImages(ImageType.PNG, ops, outputDirectory, "fileName");
}
#endregion
#region convert single pdf file to image with image settings(Stream to Stream)
internal static void pdfStream2ImageStream()
{
String inputFilePath = @"C:\demo.pdf";
byte[] arr = File.ReadAllBytes(inputFilePath);
MemoryStream inputStream = new MemoryStream(arr);
PDFDocument doc = new PDFDocument(inputStream);
List<Stream> outputStreams = new List<Stream>();
for (int i = 0; i < doc.GetPageCount();i++ )
{
outputStreams.Add(new MemoryStream());
}
ImageOutputOption ops = new ImageOutputOption();
ops.Color = ColorType.Monochrome;
ops.Resolution = 120;
doc.ConvertToImages(ImageType.PNG, ops, outputStreams.ToArray());
}
#endregion
Convert the first page of PDF file to image to preview using C#.NET
The steps and C# code below will explain how to convert the first page of a PDF file to preview in C#.
- Create a new ImageOutputOption object to preview the first page of PDF file
- Set image type to Bitmap ImageType.BMP
- Set image color to ColorType.Color
- Set PDF page zoom is 0.25F
- Set image resolution to 300 dpi.
- Create a PDFDocument object with PDF file loaded
- Get the first page object PDFPage of the PDF document
- Use the method PDFPage.ConvertToImage() to convert the first page of PDF file to bitmap image file
String inputFilePath = @"W:\Projects\Test-Files\file1.pdf";
String outputFilePath = @"W:\Projects\Test-Output\RasterEdge.com\pdf-convert-pdf-to-bmp-preview.bmp";
ImageOutputOption options = new ImageOutputOption();
options.Type = ImageType.BMP;
// Output image is Monochrome, Gray, Color.
options.Color = ColorType.Color;
// Set zoom value to 2F. Use more pixels to render the page.
options.Zoom = 0.25F;
// Set resolution value in the bitmap file to 96 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 Bitmap (.bmp) image
page.ConvertToImage(options, outputFilePath);
C# convert single pdf file to jpeg2000 with image options
#region convert single pdf file to Jpeg2000 with image options
internal static void pdf2Jpeg2000Image()
{
String inputFilePath = @"C:\demo.pdf";
String outputDirectory = @"C:\output\";
ImageOutputOption ops = new ImageOutputOption();
ops.Color = ColorType.Monochrome;
ops.Resolution = 120;
ops.Zoom = 1.5f;
//To set more settings.....
PDFDocument doc = new PDFDocument(inputFilePath);
doc.ConvertToImages(ImageType.JPEG2000, ops, outputDirectory, "fileName");
}
#endregion
C# convert two or multiple pdf files to image (batch convert)
#region convert two or multiple pdf files to image(batch files and single tread)
internal static void pdfFilesToImage()
{
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.BMP, outputDirectory, docName);
}
}
#endregion
C# combine multiple pdf files, and convert to image
#region combine pdf files and convert to Bmp
internal static void combineAndConvertToBmp()
{
String[] files = new String[] { @"C:\demo1.pdf", @"C:\demo2.pdf", @"C:\demo3.pdf" };
Stream stream = new MemoryStream();
PDFDocument.CombineDocument(files, stream);
PDFDocument doc = new PDFDocument(stream);
String outputDirectory = @"C:\output\";
doc.ConvertToImages(ImageType.BMP, outputDirectory, "fileName");
}
#endregion