使用 MemoryStream 將 PDF 點陣化為圖像
2022年1月19日
已更新 2024年10月20日
This article was translated from English: Does it need improvement?
TranslatedView the article in English
如何使用MemoryStream將PDF頁面轉換為圖像,而不觸碰檔案系統
IronPDF支持從MemoryStream加載PDF文件。 ( 操作說明 API 參考資料
使用PdfDocument.ToBitMap()
方法將 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
$vbLabelText $csharpLabel
有幫助的Stack Overflow 文章。