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

可以从以下任何 .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数据转换为可编辑的对象,从而可以根据需要进行修改。