Rasterización de PDF a imágenes con MemoryStream

This article was translated from English: Does it need improvement?
Translated
View the article in English

¿Cómo convierto páginas PDF en imágenes utilizando MemoryStream, sin tocar el sistema de archivos?

IronPDF ofrece cargar documentos PDF desde MemoryStream. (How-Tos|Referencia API)

Utilice el método PdfDocument.ToBitmap() para exportar páginas PDF como imágenes. Esto devolverá un array de objetos IronSoftware.Drawing.AnyBitmap, que se pueden usar para un procesamiento adicional.

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();
}
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();
}
$vbLabelText   $csharpLabel

Aquí tienes un artículo útil de Stack Overflow artículo para más detalles sobre cómo guardar un bitmap en un MemoryStream.

Curtis Chau
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más
¿Listo para empezar?
Nuget Descargas 17,803,474 | Versión: 2026.3 recién lanzado
Still Scrolling Icon

¿Aún desplazándote?

¿Quieres una prueba rápida? PM > Install-Package IronPdf
ejecutar una muestra Mira cómo tu HTML se convierte en PDF.