使用内存流光栅化为图像
如何使用memorystream将PDF页面转换为图像,而不****接触文件系统?
IronPDF支持从MemoryStream加载PDF文档。 ( 操作指南 API文档)
使用PdfDocument.ToBitmap
方法将PDF页面转换为位图图像。()将PDF页面导出为图片的方法。 这将返回一个 IronSoftware.Drawing.AnyBitmap 对象数组,可用于进一步处理。
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
有用的 Stack Overflow条.