IronPDF ハウツー メモリからのPDF MemoryStreamからPDFへのC カーティス・チャウ 更新日:2026年1月10日 IronPDF をダウンロード NuGet ダウンロード DLL ダウンロード Windows 版 無料トライアル LLM向けのコピー LLM向けのコピー LLM 用の Markdown としてページをコピーする ChatGPTで開く このページについてChatGPTに質問する ジェミニで開く このページについてGeminiに問い合わせる Grokで開く このページについてGrokに質問する 困惑の中で開く このページについてPerplexityに問い合わせる 共有する Facebook で共有 Xでシェア(Twitter) LinkedIn で共有 URLをコピー 記事をメールで送る This article was translated from English: Does it need improvement? Translated View the article in English IronPDF を使用すると、ファイル システムにアクセスせずに、C# で MemoryStream オブジェクトを PDF ドキュメントに直接変換できます。 FileStream、またはバイト配列を PdfDocument コンストラクターに渡すと、メモリ内で PDF が即座に作成され、操作されます。 ファイル システムに触れることなく、C# .NETで PDF ファイルに MemoryStream を読み込んで作成します。 これは、System.IO 名前空間の MemoryStream オブジェクトを通じて機能します。 この機能は、クラウド環境、Webアプリケーション、またはファイルシステムへのアクセスが制限されているシナリオに使用します。 クイックスタート: C# で MemoryStream から PDF を作成する IronPDFを使用して、1 行のコードで MemoryStream を PDF に変換します。 物理ファイルを処理せずに PDF 作成を C# アプリケーションに統合するには、MemoryStream から PdfDocument を初期化します。 インメモリデータ処理、ネットワーク通信、リアルタイムデータ変換に最適です。 IronPDF をNuGetパッケージマネージャでインストール PM > Install-Package IronPdf このコード スニペットをコピーして実行します。 var bytes = File.ReadAllBytes("sample.pdf"); var pdfDoc = new IronPdf.PdfDocument(myMemoryStream); 実際の環境でテストするためにデプロイする 今日プロジェクトで IronPDF を使い始めましょう無料トライアル Free 30 Day Trial 最小限のワークフロー(5ステップ) MemoryStreamをPDFに変換するIronPDF C#ライブラリをダウンロードする。 PDFファイルのバイトデータを取得する **PdfDocument**コンストラクタを使用して、バイト配列をPDFオブジェクトに読み込みます。 PDFオブジェクトに必要な変更を加える 更新されたPDFドキュメントをエクスポート メモリから PDF を読み込むには? これら for .NETメモリ内オブジェクトから IronPdf.PdfDocument を初期化します。 A MemoryStream A FileStream バイナリデータは byte[] として 以下は、PDF ファイルから直接ストリームを読み取り、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) $vbLabelText $csharpLabel どのような種類のストリームオブジェクトを使用できますか? この例では、ファイル システムから PDF ファイルを読み取り、PdfDocument オブジェクトを作成する方法を示します。 ネットワーク通信またはその他のデータ交換プロトコルを介して受信した byte[] から PdfDocument を初期化することもできます。 PDFデータを編集可能なオブジェクトに変換し、必要に応じて修正を加える。 以下は、さまざまなストリームソースを示す包括的な例です: using IronPdf; using System.IO; using System.Net.Http; // Example 1: From FileStream using (FileStream fileStream = File.OpenRead("document.pdf")) { var pdfFromFileStream = new PdfDocument(fileStream); } // Example 2: From MemoryStream byte[] pdfBytes = GetPdfBytesFromDatabase(); // Your method to get PDF bytes using (MemoryStream memoryStream = new MemoryStream(pdfBytes)) { var pdfFromMemoryStream = new PdfDocument(memoryStream); } // Example 3: From HTTP Response using (HttpClient client = new HttpClient()) { byte[] pdfData = await client.GetByteArrayAsync("https://example.com/document.pdf"); var pdfFromHttp = new PdfDocument(pdfData); } using IronPdf; using System.IO; using System.Net.Http; // Example 1: From FileStream using (FileStream fileStream = File.OpenRead("document.pdf")) { var pdfFromFileStream = new PdfDocument(fileStream); } // Example 2: From MemoryStream byte[] pdfBytes = GetPdfBytesFromDatabase(); // Your method to get PDF bytes using (MemoryStream memoryStream = new MemoryStream(pdfBytes)) { var pdfFromMemoryStream = new PdfDocument(memoryStream); } // Example 3: From HTTP Response using (HttpClient client = new HttpClient()) { byte[] pdfData = await client.GetByteArrayAsync("https://example.com/document.pdf"); var pdfFromHttp = new PdfDocument(pdfData); } Imports IronPdf Imports System.IO Imports System.Net.Http ' Example 1: From FileStream Using fileStream As FileStream = File.OpenRead("document.pdf") Dim pdfFromFileStream = New PdfDocument(fileStream) End Using ' Example 2: From MemoryStream Dim pdfBytes As Byte() = GetPdfBytesFromDatabase() ' Your method to get PDF bytes Using memoryStream As New MemoryStream(pdfBytes) Dim pdfFromMemoryStream = New PdfDocument(memoryStream) End Using ' Example 3: From HTTP Response Using client As New HttpClient() Dim pdfData As Byte() = Await client.GetByteArrayAsync("https://example.com/document.pdf") Dim pdfFromHttp = New PdfDocument(pdfData) End Using $vbLabelText $csharpLabel ファイル ベースの操作よりも MemoryStream を使用する必要があるのはどのような場合ですか? MemoryStream 操作は、次のシナリオで優れています。 1.Webアプリケーション:サーバーの一時ファイルを作成することなく、ASP.NETアプリケーションでPDFを動的に提供します。 2.クラウド環境:Azure Functions または AWS Lambda では、ファイルシステムへのアクセスが制限されていたり、一時ストレージにコストがかかる場合に使用します。 3.セキュリティ:機密文書をメモリ内で処理し、ディスク上に一時ファイルを残さないようにします。 4.パフォーマンス:メモリ操作は、特にソリッドステートまたはネットワーク接続ストレージでは、小から中規模のPDFではディスクI/Oよりも高速です。 PDFをMemoryStreamにエクスポートするには? 読み込まれた、または作成された PDF ドキュメントを、処理または転送のために MemoryStream にエクスポートします。 WebアプリケーションでPDFを提供するときや、データベースにPDFを格納するときに役立ちます。 PDFをMemoryStreamにエクスポートする方法は以下の通りです: using IronPdf; using System.IO; // Create or load a PDF document var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1><p>This is a PDF from HTML</p>"); // Export to MemoryStream using (MemoryStream memoryStream = new MemoryStream()) { pdf.SaveAs(memoryStream); // Example: Convert to byte array for database storage byte[] pdfBytes = memoryStream.ToArray(); // Example: Reset position to read from beginning memoryStream.Position = 0; // Use the stream as needed (e.g., return in web response) } using IronPdf; using System.IO; // Create or load a PDF document var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1><p>This is a PDF from HTML</p>"); // Export to MemoryStream using (MemoryStream memoryStream = new MemoryStream()) { pdf.SaveAs(memoryStream); // Example: Convert to byte array for database storage byte[] pdfBytes = memoryStream.ToArray(); // Example: Reset position to read from beginning memoryStream.Position = 0; // Use the stream as needed (e.g., return in web response) } Imports IronPdf Imports System.IO ' Create or load a PDF document Dim renderer As New ChromePdfRenderer() Dim pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1><p>This is a PDF from HTML</p>") ' Export to MemoryStream Using memoryStream As New MemoryStream() pdf.SaveAs(memoryStream) ' Example: Convert to byte array for database storage Dim pdfBytes As Byte() = memoryStream.ToArray() ' Example: Reset position to read from beginning memoryStream.Position = 0 ' Use the stream as needed (e.g., return in web response) End Using $vbLabelText $csharpLabel 高度なメモリストリームの操作 複数の MemoryStreams から PDF をマージする ファイルシステムにアクセスすることなく、複数のIronPDFドキュメントをメモリ内でマージします: using IronPdf; using System.Collections.Generic; using System.IO; public static byte[] MergePdfsFromMemory(List<byte[]> pdfBytesList) { List<PdfDocument> pdfs = new List<PdfDocument>(); // Load all PDFs from byte arrays foreach (var pdfBytes in pdfBytesList) { pdfs.Add(new PdfDocument(pdfBytes)); } // Merge PDFs PdfDocument merged = PdfDocument.Merge(pdfs); // Export merged PDF to byte array using (MemoryStream ms = new MemoryStream()) { merged.SaveAs(ms); return ms.ToArray(); } } using IronPdf; using System.Collections.Generic; using System.IO; public static byte[] MergePdfsFromMemory(List<byte[]> pdfBytesList) { List<PdfDocument> pdfs = new List<PdfDocument>(); // Load all PDFs from byte arrays foreach (var pdfBytes in pdfBytesList) { pdfs.Add(new PdfDocument(pdfBytes)); } // Merge PDFs PdfDocument merged = PdfDocument.Merge(pdfs); // Export merged PDF to byte array using (MemoryStream ms = new MemoryStream()) { merged.SaveAs(ms); return ms.ToArray(); } } Imports IronPdf Imports System.Collections.Generic Imports System.IO Public Shared Function MergePdfsFromMemory(pdfBytesList As List(Of Byte())) As Byte() Dim pdfs As New List(Of PdfDocument)() ' Load all PDFs from byte arrays For Each pdfBytes In pdfBytesList pdfs.Add(New PdfDocument(pdfBytes)) Next ' Merge PDFs Dim merged As PdfDocument = PdfDocument.Merge(pdfs) ' Export merged PDF to byte array Using ms As New MemoryStream() merged.SaveAs(ms) Return ms.ToArray() End Using End Function $vbLabelText $csharpLabel メモリ内のセキュリティ設定の適用 PDFにパスワードとアクセス許可を設定しながら、すべてをメモリに保持します: using IronPdf; using System.IO; // Load PDF from memory byte[] unsecuredPdfBytes = GetPdfFromDatabase(); PdfDocument pdf = new PdfDocument(unsecuredPdfBytes); // Apply security settings pdf.SecuritySettings.UserPassword = "user123"; pdf.SecuritySettings.OwnerPassword = "owner456"; pdf.SecuritySettings.AllowUserPrinting = false; pdf.SecuritySettings.AllowUserCopyPasteContent = false; // Export secured PDF to memory using (MemoryStream securedStream = new MemoryStream()) { pdf.SaveAs(securedStream); byte[] securedPdfBytes = securedStream.ToArray(); // Store or transmit secured PDF bytes } using IronPdf; using System.IO; // Load PDF from memory byte[] unsecuredPdfBytes = GetPdfFromDatabase(); PdfDocument pdf = new PdfDocument(unsecuredPdfBytes); // Apply security settings pdf.SecuritySettings.UserPassword = "user123"; pdf.SecuritySettings.OwnerPassword = "owner456"; pdf.SecuritySettings.AllowUserPrinting = false; pdf.SecuritySettings.AllowUserCopyPasteContent = false; // Export secured PDF to memory using (MemoryStream securedStream = new MemoryStream()) { pdf.SaveAs(securedStream); byte[] securedPdfBytes = securedStream.ToArray(); // Store or transmit secured PDF bytes } Imports IronPdf Imports System.IO ' Load PDF from memory Dim unsecuredPdfBytes As Byte() = GetPdfFromDatabase() Dim pdf As New PdfDocument(unsecuredPdfBytes) ' Apply security settings pdf.SecuritySettings.UserPassword = "user123" pdf.SecuritySettings.OwnerPassword = "owner456" pdf.SecuritySettings.AllowUserPrinting = False pdf.SecuritySettings.AllowUserCopyPasteContent = False ' Export secured PDF to memory Using securedStream As New MemoryStream() pdf.SaveAs(securedStream) Dim securedPdfBytes As Byte() = securedStream.ToArray() ' Store or transmit secured PDF bytes End Using $vbLabelText $csharpLabel メモリーストリームPDF操作のベストプラクティス 1.適切に破棄する: メモリ リークを防ぐために、using ステートメントを使用するか、MemoryStream および PdfDocument オブジェクトを明示的に破棄します。 2.メモリ制限を考慮する:大きなPDFや大量処理のメモリ使用量を監視してください。 圧縮の実装や、PDFを塊で処理することを検討してください。 3.エラー処理:ストリームを扱うとき、特に破損したり不正なPDFデータを扱うときに、例外を処理するためにtry-catchブロックを実装します。 4.非同期操作:WebアプリケーションでPDFを処理するときは、asyncメソッドを使用して応答性を維持します。 IronPDFの他の機能との統合 MemoryStreamsは、数多くのPDF操作の可能性を可能にします: ウェブサービスから受け取ったPDFに透かしを追加する。 アップロードされたPDFからテキストと画像を抽出する。 クラウドワークフローのドキュメントに電子署名を適用する。 HTMLをPDFに変換し、ユーザーに直接配信する。 次に何ができるのかを見てみましょうか? こちらのチュートリアルページをご覧ください: PDFの編集 よくある質問 ファイルシステムにアクセスせずにC#でMemoryStreamをPDFに変換するには? IronPDFはファイルシステムにアクセスすることなく、MemoryStreamオブジェクトをPDFドキュメントに直接変換することができます。PdfDocumentコンストラクタにMemoryStreamを渡すだけです: var pdfDoc = new IronPdf.PdfDocument(myMemoryStream).var pdfDoc = new IronPdf.PdfDocument(myMemoryStream) この方法はクラウド環境、ウェブアプリケーション、ファイルシステムへのアクセスが制限されているシナリオに最適です。 メモリ内でPDFを作成するために、どのような種類のストリームオブジェクトを使用できますか? IronPDFのPdfDocumentコンストラクタは3種類のインメモリオブジェクトを受け入れます:MemoryStream、FileStream、そしてバイト配列(byte[])です。PdfDocumentはこれらのどのソースからでも初期化することができ、ネットワーク通信やデータベースのブロブ、APIのレスポンスなどさまざまなデータソースに柔軟に対応することができます。 ファイルパスの代わりにバイト配列からPDFを読み込むことはできますか? はい、IronPDFはバイト配列から直接PDFをロードすることができます。バイナリデータからPdfDocumentオブジェクトを作成するには次のようにします: var pdfDoc = new IronPdf.PdfDocument(pdfBytes).これは特に、ネットワーク通信経由でPDFデータを受信したり、データベースから取得したりする場合に便利です。 HTTP レスポンスストリームから PDF を作成するには? IronPDFでは、まずレスポンスをバイト配列に変換することでHTTPレスポンスからPDFを作成することができます: byte[] pdfData = await client.GetByteArrayAsync(url); 次にPdfDocumentを初期化します: var pdfFromHttp = new IronPdf.PdfDocument(pdfData).これにより、ウェブAPIやリモートソースからのシームレスなPDF処理が可能になります。 PDF操作にMemoryStreamを使用する利点は何ですか? MemoryStreamをIronPDFと一緒に使うことで、ファイルシステムに依存しない、より高速なインメモリー処理、より優れたセキュリティ(テンポラリファイルがない)、ファイルシステムへのアクセスが制限されているクラウド環境やコンテナ化されたアプリケーションに最適、といった利点があります。 カーティス・チャウ 今すぐエンジニアリングチームとチャット テクニカルライター Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。 レビュー済み Jeffrey T. Fritz プリンシパルプログラムマネージャー - .NETコミュニティチーム Jeffはまた、.NETとVisual Studioチームのプリンシパルプログラムマネージャーです。彼は.NET Conf仮想会議シリーズのエグゼクティブプロデューサーであり、週に二回放送される開発者向けライブストリーム『Fritz and Friends』のホストを務め、テクノロジーについて話すことや視聴者と一緒にコードを書くことをしています。Jeffはワークショップ、プレゼンテーション、およびMicrosoft Build、Microsoft Ignite、.NET Conf、Microsoft MVPサミットを含む最大のMicrosoft開発者イベントのコンテンツを企画しています。 準備はできましたか? Nuget ダウンロード 18,049,106 | バージョン: 2026.4 リリース 無料トライアル NuGet 無料ダウンロード 総ダウンロード数: 18,049,106 ライセンスを見る まだスクロールしていますか? すぐに証拠が欲しいですか? PM > Install-Package IronPdf サンプルを実行するHTML が PDF に変換されるのを確認します。 NuGet 無料ダウンロード 総ダウンロード数: 18,049,106 ライセンスを見る