Rasterizing PDFs to Images with MemoryStream

Curtis Chau
Curtis Chau
Updated: April 22, 2026

How do I convert PDF pages to images using MemoryStream, without touching the file system?

IronPDF offers loading PDF documents from MemoryStream. (How-Tos | API Reference)

Use the PdfDocument.ToBitmap() method to export PDF pages as images. This will return an array of IronSoftware.Drawing.AnyBitmap objects, which can be used for further processing.

using IronPdf;
using System.IO;

// Example rendering PDF documents to Images or Thumbnails
using var pdf = PdfDocument.FromFile("Example.pdf");

// Convert each page of the PDF document to a bitmap image
IronSoftware.Drawing.AnyBitmap[] pageImages = pdf.ToBitmap();

foreach (var bitmap in pageImages)
{
    // Use MemoryStream to handle the image data in memory
    using (MemoryStream memoryStream = new MemoryStream())
    {
        // Export the image to MemoryStream as a PNG format
        bitmap.ExportStream(memoryStream, IronSoftware.Drawing.AnyBitmap.ImageFormat.Png);
        
        // MemoryStream can now be used for further processing without touching the file system
        // Example: Send it over a network, save to a database, etc.
    }
    
    // Dispose of the bitmap once processing is complete to free resources
    bitmap.Dispose();
}

Here is a helpful Stack Overflow article for more details on saving a bitmap into a MemoryStream.

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

Read More

Ready to Get Started?

Nuget Downloads 22,024,882Version:2026.11just released