MemoryStream 到 PDF C
This article was translated from English: Does it need improvement?
TranslatedView the article in English
我們可以在 C# .NET 中載入和建立 MemoryStream 成 PDF 文件,而不需接觸檔案系統。 這可以透過位於 System.IO .NET 命名空間內的 MemoryStream 物件來實現。
開始使用 IronPDF
立即在您的專案中使用IronPDF,並享受免費試用。
如何在 C# 中將 MemoryStream 轉換為 PDF
- 下載 IronPDF C# 庫將 MemoryStream 轉換為 PDF
- 檢索 PDF 檔案的位元組資料
- 使用 PdfDocument 構造函數將位元數組加載到 PDF 對象中
- 對 PDF 物件進行必要的更改
- 匯出已更新的 PDF 文件
從記憶體載入PDF
可以從以下任何 .NET 內存對象初始化一個新的 IronPdf.PdfDocument 實例:
- 記憶體流
- 檔案流
作為位元組陣列的二進位數據(位元組[])
下面是直接從 PDF 檔案中讀取流並使用 C# 從中創建 PdfDocument 物件的範例:
:path=/static-assets/pdf/content-code-examples/how-to/pdf-memory-stream-from-stream.cs
using IronPdf;
using System.IO;
// Read PDF file as stream
var fileByte = File.ReadAllBytes("sample.pdf");
// Instantiate PDF object from stream
PdfDocument pdf = new PdfDocument(fileByte);
Imports IronPdf
Imports System.IO
' Read PDF file as stream
Private fileByte = File.ReadAllBytes("sample.pdf")
' Instantiate PDF object from stream
Private pdf As New PdfDocument(fileByte)
VB C#
所提供的範例展示了如何直接從檔案系統讀取PDF檔案並創建一個PdfDocument物件。 不過,您也可以從經由網路通訊或任何其他資料交換協議接收的位元組陣列初始化 PdfDocument。 這使您可以將 PDF 資料轉換為可編輯的對象,從而根據需要進行修改。