PDFs are great for documents, but sometimes you need images. Thumbnails for web galleries, pages for OCR processing, or rasterized versions for systems that don't handle PDFs. Here's how to convert PDF pages to PNG, JPEG, and other formats in C#.
using IronPdf;
// Install via NuGet: Install-Package IronPdf
var pdf = PdfDocument.FromFile("document.pdf");
pdf.RasterizeToImageFiles("page-*.png");
Each page becomes a separate PNG file: page-1.png, page-2.png, and so on.
Why Convert PDFs to Images?
Common use cases:
- Thumbnails - Preview images for document management systems
- Web display - Show PDFs in browsers without PDF.js
- OCR preparation - Image-based text recognition requires rasterized pages
- Social sharing - Platforms that don't embed PDFs
- Print workflows - Some printers prefer image formats
The challenge: PDFs are vector-based. Converting them to raster images requires choosing resolution, format, and quality settings.
How Do I Control Image Quality?
Default DPI (96) produces blurry output. Increase it for sharper images:
using IronPdf;
// Install via NuGet: Install-Package IronPdf
var pdf = PdfDocument.FromFile("contract.pdf");
// Higher DPI = sharper images
pdf.RasterizeToImageFiles("page-*.png", 300); // 300 DPI
// For print quality
pdf.RasterizeToImageFiles("print-*.png", 600); // 600 DPI
DPI guidelines:
- 72-96: Web thumbnails, quick previews
- 150: Readable text on screen
- 300: Print-ready, professional quality
- 600: High-end printing, archival
Higher DPI means larger files and longer processing time. Balance quality against your needs.
How Do I Convert to JPEG Instead of PNG?
Specify the image format in the file extension or explicitly:
using IronPdf;
// Install via NuGet: Install-Package IronPdf
var pdf = PdfDocument.FromFile("brochure.pdf");
// PNG (lossless, larger files)
pdf.RasterizeToImageFiles("page-*.png", 300);
// JPEG (lossy, smaller files)
pdf.RasterizeToImageFiles("page-*.jpg", 300);
// TIFF (multi-page support)
pdf.RasterizeToImageFiles("page-*.tiff", 300);
// BMP (uncompressed)
pdf.RasterizeToImageFiles("page-*.bmp", 300);
Format recommendations:
- PNG: Text-heavy documents, screenshots, diagrams
- JPEG: Photos, full-color pages where some quality loss is acceptable
- TIFF: Archival, OCR processing, fax systems
How Do I Convert a Specific Page?
Extract individual pages rather than the whole document:
using IronPdf;
// Install via NuGet: Install-Package IronPdf
var pdf = PdfDocument.FromFile("report.pdf");
// Convert only page 1 (0-indexed)
var pageImages = pdf.ToBitmap(300);
pageImages[0].Save("first-page.png");
// Convert specific pages
var pages = new[] { 0, 4, 9 }; // Pages 1, 5, and 10
foreach (var pageIndex in pages)
{
var images = pdf.ToBitmap(300);
images[pageIndex].Save($"page-{pageIndex + 1}.png");
}
For large PDFs, converting individual pages saves memory.
How Do I Get Images as Byte Arrays?
For in-memory processing without saving files:
using IronPdf;
using System.Drawing;
using System.Drawing.Imaging;
// Install via NuGet: Install-Package IronPdf
var pdf = PdfDocument.FromFile("document.pdf");
var bitmaps = pdf.ToBitmap(300);
var imageBytes = new List<byte[]>();
foreach (var bitmap in bitmaps)
{
using var stream = new MemoryStream();
bitmap.Save(stream, ImageFormat.Png);
imageBytes.Add(stream.ToArray());
}
// Now imageBytes contains PNG data for each page
This pattern works well for uploading to cloud storage or returning from APIs.
How Do I Create Thumbnails?
Generate small preview images:
using IronPdf;
using System.Drawing;
// Install via NuGet: Install-Package IronPdf
var pdf = PdfDocument.FromFile("presentation.pdf");
var bitmaps = pdf.ToBitmap(150); // Lower DPI for thumbnails
for (int i = 0; i < bitmaps.Length; i++)
{
// Resize to thumbnail dimensions
var thumb = ResizeImage(bitmaps[i], 200, 260);
thumb.Save($"thumb-{i + 1}.jpg", ImageFormat.Jpeg);
}
static Bitmap ResizeImage(Bitmap original, int maxWidth, int maxHeight)
{
var ratio = Math.Min(
(double)maxWidth / original.Width,
(double)maxHeight / original.Height);
var newWidth = (int)(original.Width * ratio);
var newHeight = (int)(original.Height * ratio);
var resized = new Bitmap(newWidth, newHeight);
using var graphics = Graphics.FromImage(resized);
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.DrawImage(original, 0, 0, newWidth, newHeight);
return resized;
}
Lower DPI + resizing produces fast, small thumbnails.
How Do I Handle Multi-Page PDFs Efficiently?
For large documents, process pages sequentially to manage memory:
using IronPdf;
// Install via NuGet: Install-Package IronPdf
var pdf = PdfDocument.FromFile("large-manual.pdf");
var pageCount = pdf.PageCount;
for (int i = 0; i < pageCount; i++)
{
// Extract single page
var singlePage = pdf.CopyPage(i);
var bitmap = singlePage.ToBitmap(300)[0];
bitmap.Save($"page-{i + 1}.png");
// Clean up
bitmap.Dispose();
singlePage.Dispose();
}
This approach prevents loading all pages into memory simultaneously.
How Do I Convert PDFs in Parallel?
Speed up batch processing with parallel execution:
using IronPdf;
// Install via NuGet: Install-Package IronPdf
var pdfFiles = Directory.GetFiles("input", "*.pdf");
Parallel.ForEach(pdfFiles, pdfPath =>
{
var pdf = PdfDocument.FromFile(pdfPath);
var baseName = Path.GetFileNameWithoutExtension(pdfPath);
pdf.RasterizeToImageFiles($"output/{baseName}-page-*.png", 300);
pdf.Dispose();
});
This processes multiple PDFs concurrently, utilizing all CPU cores.
What About Transparent Backgrounds?
PDFs often have white backgrounds. For transparent PNG output:
using IronPdf;
using System.Drawing;
// Install via NuGet: Install-Package IronPdf
var pdf = PdfDocument.FromFile("logo-page.pdf");
var bitmap = pdf.ToBitmap(300)[0];
// Make white pixels transparent
bitmap.MakeTransparent(Color.White);
bitmap.Save("logo-transparent.png", ImageFormat.Png);
Note: This makes all white pixels transparent, not just the background.
How Do I Handle Color Profiles?
For accurate color reproduction:
using IronPdf;
// Install via NuGet: Install-Package IronPdf
var pdf = PdfDocument.FromFile("color-critical.pdf");
// Standard sRGB rendering (default)
pdf.RasterizeToImageFiles("srgb-*.png", 300);
// For grayscale output
var bitmaps = pdf.ToBitmap(300);
foreach (var bitmap in bitmaps)
{
// Convert to grayscale if needed
var grayscale = ConvertToGrayscale(bitmap);
grayscale.Save("gray.png");
}
Most web and screen uses work fine with default color handling.
Quick Troubleshooting
| Issue | Solution |
|---|---|
| Blurry images | Increase DPI (try 300) |
| Large file sizes | Use JPEG, reduce DPI, or resize |
| Missing fonts | Ensure fonts are embedded in PDF |
| Slow processing | Lower DPI or process pages individually |
| Memory errors | Process pages sequentially, dispose properly |
Complete Example: PDF Gallery Generator
using IronPdf;
using System.Drawing;
using System.Drawing.Imaging;
// Install via NuGet: Install-Package IronPdf
public class PdfGalleryGenerator
{
public void GenerateGallery(string pdfPath, string outputFolder)
{
Directory.CreateDirectory(outputFolder);
var pdf = PdfDocument.FromFile(pdfPath);
var bitmaps = pdf.ToBitmap(200); // Medium quality for web
for (int i = 0; i < bitmaps.Length; i++)
{
// Full-size preview
var fullPath = Path.Combine(outputFolder, $"page-{i + 1}.jpg");
bitmaps[i].Save(fullPath, ImageFormat.Jpeg);
// Thumbnail
var thumbPath = Path.Combine(outputFolder, $"thumb-{i + 1}.jpg");
using var thumb = ResizeImage(bitmaps[i], 150, 200);
thumb.Save(thumbPath, ImageFormat.Jpeg);
bitmaps[i].Dispose();
}
pdf.Dispose();
}
private Bitmap ResizeImage(Bitmap original, int maxWidth, int maxHeight)
{
var ratio = Math.Min(
(double)maxWidth / original.Width,
(double)maxHeight / original.Height);
var resized = new Bitmap(
(int)(original.Width * ratio),
(int)(original.Height * ratio));
using var g = Graphics.FromImage(resized);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(original, 0, 0, resized.Width, resized.Height);
return resized;
}
}
PDF to image conversion opens up possibilities beyond traditional document handling. Whether you need thumbnails, OCR input, or web-friendly previews, rasterizing PDFs gives you flexibility.
For the complete API reference, see the IronPDF rasterization documentation.
Written by Jacob Mellor, CTO at Iron Software. Jacob created IronPDF and leads a team of 50+ engineers building .NET document processing libraries.
Top comments (0)