Rastérisation vers une image en utilisant MemoryStream
Comment convertir des pages PDF en images en utilisant memorystream, sans que ne touche le système de fichiers ?
IronPDF permet de charger des documents PDF à partir de MemoryStream. ( Comment faire Référence API)
Utiliser la fonction PdfDocument.ToBitMap()
méthode pour exporter des pages PDF en tant qu'images. Cela renvoie un tableau d'objets IronSoftware.Drawing.AnyBitmap, qui peuvent être utilisés pour d'autres traitements.
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
Aide Stack Overflow article.