Rasterize to Image using MemoryStream

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

IronPDF offer 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;

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

// or make one using Chrome Renderer
IronSoftware.Drawing.AnyBitmap[] pageImages = pdf.ToBitmap();

foreach (var bitmap in pageImages)
{
    using (MemoryStream memoryStream = new MemoryStream())
    {
        // save to PNG
        bitmap.ExportStream(memoryStream, IronSoftware.Drawing.AnyBitmap.ImageFormat.Png);

        // use memoryStream
    }
    bitmap.Dispose();
}
using IronPdf;

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

// or make one using Chrome Renderer
IronSoftware.Drawing.AnyBitmap[] pageImages = pdf.ToBitmap();

foreach (var bitmap in pageImages)
{
    using (MemoryStream memoryStream = new MemoryStream())
    {
        // save to PNG
        bitmap.ExportStream(memoryStream, IronSoftware.Drawing.AnyBitmap.ImageFormat.Png);

        // use memoryStream
    }
    bitmap.Dispose();
}
Imports IronPdf

' Example rendering PDF documents to Images or Thumbnails
Private pdf = PdfDocument.FromFile("Example.pdf")

' or make one using Chrome Renderer
Private pageImages() As IronSoftware.Drawing.AnyBitmap = pdf.ToBitmap()

For Each bitmap In pageImages
	Using memoryStream As New MemoryStream()
		' save to PNG
		bitmap.ExportStream(memoryStream, IronSoftware.Drawing.AnyBitmap.ImageFormat.Png)

		' use memoryStream
	End Using
	bitmap.Dispose()
Next bitmap
VB   C#

Helpful Stack Overflow article.