MemoryStream 到 PDF C
我们可以在 C# .NET 中加载和创建 MemoryStream 到 PDF 文件,而无需接触文件系统。 这是通过存在于 System.IO .NET 命名空间中的 MemoryStream 对象实现的。
开始使用IronPDF
立即在您的项目中开始使用IronPDF,并享受免费试用。
如何在C#中将MemoryStream转换为PDF
- 下载 IronPDF C# 库以将 MemoryStream 转换为 PDF
- 检索 PDF 文件的字节数据
- 使用PdfDocument构造函数将字节数组加载到PDF对象中
- 对 PDF 对象进行必要的更改。
- 导出更新后的PDF文档
从内存加载PDF
IronPdf.PdfDocument 的新实例可以从以下任何 .NET 内存对象初始化:
- 内存流
- 文件流
二进制数据作为字节数组(byte[])
以下是直接从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)
所提供的示例演示了如何直接从文件系统读取PDF文件并创建PdfDocument对象。 但是,您也可以通过网络通信或任何其他数据交换协议接收到的字节数组初始化一个 PdfDocument。 这使您可以将PDF数据转换为可编辑的对象,从而可以根据需要进行修改。