MemoryStream to PDF C#

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

C# .NET では、ファイルシステムに触れることなく、MemoryStream を PDF ファイルとしてロードおよび作成できます。 これは、System.IO .NETネームスペース内に存在するMemoryStreamオブジェクトを通じて可能です。

IronPDFを始めましょう

今日から無料トライアルでIronPDFをあなたのプロジェクトで使い始めましょう。

最初のステップ:
green arrow pointer



メモリからPDFを読み込む

IronPdf.PdfDocument の新しいインスタンスは、次のいずれかの .NET インメモリオブジェクトから初期化できます。

  • メモリストリーム (メモリーストリーム)
  • ファイルストリーム
  • バイナリデータをバイト配列として(バイト[])

    以下は、PDFファイルからストリームを直接読み取り、それを使用してPdfDocumentオブジェクトをC#で作成する例です。

: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データを編集可能なオブジェクトに変換することができ、必要に応じて変更を加えることができます。