IronPDF 故障排除 将PDF转换为Base64 将 PDF 转换为 Base64. Curtis Chau 已更新:2025年6月9日 下载 IronPDF NuGet 下载 DLL 下载 Windows 安装程序 免费试用 LLM副本 LLM副本 将页面复制为 Markdown 格式,用于 LLMs 在 ChatGPT 中打开 向 ChatGPT 咨询此页面 在双子座打开 向 Gemini 询问此页面 在 Grok 中打开 向 Grok 询问此页面 打开困惑 向 Perplexity 询问有关此页面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 复制链接 电子邮件文章 This article was translated from English: Does it need improvement? Translated View the article in English 如何将 PDF 转换为 Base64? PdfDocument 对象不包含直接获取 Base64 编码的属性。但是,您可以获取字节数组,然后使用该字节数组获取 Base64 字符串。 using System; using SomePdfLibrary; // Make sure to import the library used for handling PDF files class Program { static void Main() { // Create a PdfDocument object for the specified PDF file var pdf = new PdfDocument("MyPDF.pdf"); // Get the binary data (byte array) from the PDF document var byteArray = pdf.BinaryData; // Convert the byte array to a Base64 string var base64Result = Convert.ToBase64String(byteArray); // Output the Base64 result Console.WriteLine("Base64 of PDF: " + base64Result); } } using System; using SomePdfLibrary; // Make sure to import the library used for handling PDF files class Program { static void Main() { // Create a PdfDocument object for the specified PDF file var pdf = new PdfDocument("MyPDF.pdf"); // Get the binary data (byte array) from the PDF document var byteArray = pdf.BinaryData; // Convert the byte array to a Base64 string var base64Result = Convert.ToBase64String(byteArray); // Output the Base64 result Console.WriteLine("Base64 of PDF: " + base64Result); } } $vbLabelText $csharpLabel PdfWriter:此对象负责写入PDF文件。它作用于文件路径,并写入有效PDF文档所需的结构。 PdfDocument 初始化:使用要转换的 PDF 的文件名初始化 PdfDocument 对象。 请将 SomePdfLibrary 替换为您实际使用的库。 BinaryData 检索:检索给定 PDF 的二进制数据(作为字节数组)。 Base64 转换:使用 Convert.ToBase64String 方法将字节数组转换为 Base64 字符串。 输出 Base64 字符串: 将 Base64 编码字符串打印到控制台以供验证。 Curtis Chau 立即与工程团队聊天 技术作家 Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。 准备开始了吗? Nuget 下载 17,803,474 | 版本: 2026.3 刚刚发布 免费试用 免费 NuGet 下载 总下载量:17,803,474 查看许可证 还在滚动吗? 想快速获得证据? PM > Install-Package IronPdf 运行示例看着你的HTML代码变成PDF文件。 免费 NuGet 下载 总下载量:17,803,474 查看许可证