迁移指南 如何用 C# 从 Syncfusion PDF 迁移到 IronPDF Curtis Chau 已发布:2026年2月1日 下载 IronPDF NuGet 下载 DLL 下载 Windows 安装程序 免费试用 法学硕士副本 法学硕士副本 将页面复制为 Markdown 格式,用于 LLMs 在 ChatGPT 中打开 向 ChatGPT 咨询此页面 在双子座打开 向 Gemini 询问此页面 在 Grok 中打开 向 Grok 询问此页面 打开困惑 向 Perplexity 询问有关此页面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 复制链接 电子邮件文章 从Syncfusion PDFFramework 迁移到IronPDF可将您的 PDF 生成工作流程从捆绑在大型套件中的基于坐标的图形 API 转变为具有现代 Chromium 渲染功能的独立、HTML/CSS 优先库。 本指南提供了一个完整的、循序渐进的迁移路径,消除了仅适用于套件的许可、复杂的部署要求和基于坐标的定位。 为什么要从Syncfusion PDF迁移到 IronPDF. 了解Syncfusion PDF框架 Syncfusion PDF Framework 是一个综合库,可为使用 C# 创建、编辑和保护 PDF 文档提供广泛的功能。 它是SyncfusionEssential Studio 的一部分,其中包括跨越多个平台的一千多个组件。 不过,它的一个最大缺点是不能作为独立产品购买; 开发人员必须购买整套Syncfusion组件。 对于只对 PDF 功能感兴趣的团队来说,这一要求可能会很麻烦,尤其是因为该捆绑包可能包括对他们的项目来说不必要的工具。 捆绑许可问题 Syncfusion 的 License 模式给只需要 PDF 功能的团队带来了巨大的挑战: 1.仅限套件购买:无法单独购买 PDF 库——必须购买整个 Essential Studio 套件。 2.社区许可限制:免费版要求收入低于 100 万美元且开发者人数少于 5 人。 3.复杂的部署许可:针对 Web、桌面和服务器部署采用不同的许可证 4.需每年续订:订阅模式,按年收费 5.按开发人员定价:成本与团队规模呈线性关系 6.套件臃肿:包含 1000 多个您可能不需要的组件 Syncfusion PDF与IronPDF对比 方面 Syncfusion PDF IronPDF 购买模式 仅套件捆绑包 单机版 许可 复杂的层级 针对每个开发人员的简单翻译 社区限制 <$1M AND <5 开发人员 免费试用,然后授权 部署 多种许可证类型 一个许可证涵盖所有 API 风格 基于坐标的图形 HTML/CSS 优先 HTML 支持 需要 BlinkBinaries 本地 Chromium CSS支持 有限的 完整的 CSS3/flexbox/grid 依赖关系 多个软件包 单一 NuGet 套件要求 是(整套) 否 聚焦 PDF 范围广泛; 大型套件的一部分 窄; 以 PDF 为重点 IronPDF 通过将其 PDF 功能作为独立产品提供,提供了一种更有针对性的方法。 这种差异对成本考虑和集成的难易程度都有很大影响。 对于计划在 2025 年和 2026 年之前采用 .NET 10 和 C# 14 的团队来说,IronPDF 的独立 License 和 HTML/CSS 优先方法提供了灵活性,而无需依赖套件。 开始之前 前提条件 .NET 环境: .NET Framework 4.6.2+ 或 .NET Core 3.1+ / .NET 5/6/7/8/9+ NuGet 访问权限:能够安装 NuGet 包 IronPDF 许可证:请从ironpdf.com获取您的许可证密钥。 NuGet 软件包变更 # RemoveSyncfusionpackages dotnet remove package Syncfusion.Pdf.Net.Core dotnet remove package Syncfusion.HtmlToPdfConverter.Net.Windows dotnet remove package Syncfusion.Licensing # Install IronPDF dotnet add package IronPdf # RemoveSyncfusionpackages dotnet remove package Syncfusion.Pdf.Net.Core dotnet remove package Syncfusion.HtmlToPdfConverter.Net.Windows dotnet remove package Syncfusion.Licensing # Install IronPDF dotnet add package IronPdf SHELL 许可配置 Syncfusion: // Must register before anySyncfusioncalls Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR-SYNCFUSION-KEY"); // Must register before anySyncfusioncalls Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR-SYNCFUSION-KEY"); $vbLabelText $csharpLabel IronPDF: // One-time at startup IronPdf.License.LicenseKey = "YOUR-IRONPDF-KEY"; // One-time at startup IronPdf.License.LicenseKey = "YOUR-IRONPDF-KEY"; $vbLabelText $csharpLabel 完整的 API 参考 命名空间变更 // Before:SyncfusionPDF using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Parsing; using Syncfusion.HtmlConverter; using Syncfusion.Drawing; // After: IronPDF using IronPdf; using IronPdf.Rendering; // Before:SyncfusionPDF using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Parsing; using Syncfusion.HtmlConverter; using Syncfusion.Drawing; // After: IronPDF using IronPdf; using IronPdf.Rendering; $vbLabelText $csharpLabel 核心 API 映射 Syncfusion IronPDF 备注 PDF 文档 ChromePdfRenderer 创建 PDF PDFLoadedDocument PdfDocument.FromFile() 加载 PDF HtmlToPdfConverter ChromePdfRenderer HTML 转换 graphics.DrawString() HTML 文本元素 <p></code>,` graphics.DrawImage() <img> 标记 HTML 图像 PdfGrid HTML <table> 表格 PDF 标准字体 CSS font-family 字体 PdfBrushes.Black CSS color: black 颜色 document.安全性 pdf.SecuritySettings 安全性 PDFTextExtractor pdf.ExtractAllText() 文本提取 ImportPageRange() PdfDocument.Merge() 合并 document.Save(流) pdf.SaveAs(路径) 节约 document.Close(true) 不需要 自动清理 代码迁移示例 示例 1:HTML/URL 到 PDF 的转换 之前(Syncfusion PDF): // NuGet: Install-Package Syncfusion.Pdf.Net.Core using Syncfusion.HtmlConverter; using Syncfusion.Pdf; using System.IO; class Program { static void Main() { // Initialize HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); // Convert URL to PDF PdfDocument document = htmlConverter.Convert("https://www.example.com"); // Save the document FileStream fileStream = new FileStream("Output.pdf", FileMode.Create); document.Save(fileStream); document.Close(true); fileStream.Close(); } } // NuGet: Install-Package Syncfusion.Pdf.Net.Core using Syncfusion.HtmlConverter; using Syncfusion.Pdf; using System.IO; class Program { static void Main() { // Initialize HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); // Convert URL to PDF PdfDocument document = htmlConverter.Convert("https://www.example.com"); // Save the document FileStream fileStream = new FileStream("Output.pdf", FileMode.Create); document.Save(fileStream); document.Close(true); fileStream.Close(); } } $vbLabelText $csharpLabel After (IronPDF): // NuGet: Install-Package IronPdf using IronPdf; class Program { static void Main() { // Create a PDF from a URL var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderUrlAsPdf("https://www.example.com"); // Save the PDF pdf.SaveAs("Output.pdf"); } } // NuGet: Install-Package IronPdf using IronPdf; class Program { static void Main() { // Create a PDF from a URL var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderUrlAsPdf("https://www.example.com"); // Save the PDF pdf.SaveAs("Output.pdf"); } } $vbLabelText $csharpLabel 本例展示了 API 的基本差异。Syncfusion PDF需要一个HtmlToPdfConverter实例,调用Convert()返回一个PDF 文档,然后手动创建一个FileStream` ,保存并关闭文档和流。 IronPDF 使用ChromePdfRenderer与 RenderUrlAsPdf() 仅三行代码。 无 FileStream 管理,无 Close() 调用-IronPDF 自动处理清理。 请参阅 HTML 转 PDF 文档,了解全面的示例。 示例 2:从文本创建 PDF. 之前(Syncfusion PDF): // NuGet: Install-Package Syncfusion.Pdf.Net.Core using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Drawing; using System.IO; class Program { static void Main() { // Create a new PDF document PdfDocument document = new PdfDocument(); // Add a page PdfPage page = document.Pages.Add(); // Create a font PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12); // Draw text page.Graphics.DrawString("Hello, World!", font, PdfBrushes.Black, new PointF(10, 10)); // Save the document FileStream fileStream = new FileStream("Output.pdf", FileMode.Create); document.Save(fileStream); document.Close(true); fileStream.Close(); } } // NuGet: Install-Package Syncfusion.Pdf.Net.Core using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Drawing; using System.IO; class Program { static void Main() { // Create a new PDF document PdfDocument document = new PdfDocument(); // Add a page PdfPage page = document.Pages.Add(); // Create a font PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12); // Draw text page.Graphics.DrawString("Hello, World!", font, PdfBrushes.Black, new PointF(10, 10)); // Save the document FileStream fileStream = new FileStream("Output.pdf", FileMode.Create); document.Save(fileStream); document.Close(true); fileStream.Close(); } } $vbLabelText $csharpLabel After (IronPDF): // NuGet: Install-Package IronPdf using IronPdf; using IronPdf.Rendering; class Program { static void Main() { // Create a PDF from HTML string var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderHtmlAsPdf("<h1>Hello, World!</h1>"); // Save the document pdf.SaveAs("Output.pdf"); } } // NuGet: Install-Package IronPdf using IronPdf; using IronPdf.Rendering; class Program { static void Main() { // Create a PDF from HTML string var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderHtmlAsPdf("<h1>Hello, World!</h1>"); // Save the document pdf.SaveAs("Output.pdf"); } } $vbLabelText $csharpLabel Syncfusion PDF 使用基于坐标的图形模型。 您创建了一个PDF 文档文件,添加了一个 PdfPage 页面,使用 PdfFontFamily.Helvetica 创建了一个 PdfFont 字体,然后使用明确的坐标(new PointF(10, 10) )、字体和笔刷(PdfBrushes.Black)调用 page.Graphics.DrawString() 。 最后,您需要管理 FileStream 的创建和处置。 IronPdf 采用 HTML/CSS 优先的方法。 Instead of coordinates, you write <h1>Hello, World!</h1> and let CSS handle positioning, fonts, and colors. 这种方法更简单、更易于维护,并能充分利用开发人员已有的技能。 在我们的教程中了解更多信息。 示例 3:合并 PDF 文档 之前(Syncfusion PDF): // NuGet: Install-Package Syncfusion.Pdf.Net.Core using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; using System.IO; class Program { static void Main() { // Load the first PDF document FileStream stream1 = new FileStream("Document1.pdf", FileMode.Open, FileAccess.Read); PdfLoadedDocument loadedDocument1 = new PdfLoadedDocument(stream1); // Load the second PDF document FileStream stream2 = new FileStream("Document2.pdf", FileMode.Open, FileAccess.Read); PdfLoadedDocument loadedDocument2 = new PdfLoadedDocument(stream2); // Merge the documents PdfDocument finalDocument = new PdfDocument(); finalDocument.ImportPageRange(loadedDocument1, 0, loadedDocument1.Pages.Count - 1); finalDocument.ImportPageRange(loadedDocument2, 0, loadedDocument2.Pages.Count - 1); // Save the merged document FileStream outputStream = new FileStream("Merged.pdf", FileMode.Create); finalDocument.Save(outputStream); // Close all documents finalDocument.Close(true); loadedDocument1.Close(true); loadedDocument2.Close(true); stream1.Close(); stream2.Close(); outputStream.Close(); } } // NuGet: Install-Package Syncfusion.Pdf.Net.Core using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; using System.IO; class Program { static void Main() { // Load the first PDF document FileStream stream1 = new FileStream("Document1.pdf", FileMode.Open, FileAccess.Read); PdfLoadedDocument loadedDocument1 = new PdfLoadedDocument(stream1); // Load the second PDF document FileStream stream2 = new FileStream("Document2.pdf", FileMode.Open, FileAccess.Read); PdfLoadedDocument loadedDocument2 = new PdfLoadedDocument(stream2); // Merge the documents PdfDocument finalDocument = new PdfDocument(); finalDocument.ImportPageRange(loadedDocument1, 0, loadedDocument1.Pages.Count - 1); finalDocument.ImportPageRange(loadedDocument2, 0, loadedDocument2.Pages.Count - 1); // Save the merged document FileStream outputStream = new FileStream("Merged.pdf", FileMode.Create); finalDocument.Save(outputStream); // Close all documents finalDocument.Close(true); loadedDocument1.Close(true); loadedDocument2.Close(true); stream1.Close(); stream2.Close(); outputStream.Close(); } } $vbLabelText $csharpLabel After (IronPDF): // NuGet: Install-Package IronPdf using IronPdf; using System.Collections.Generic; class Program { static void Main() { // Load PDF documents var pdf1 = PdfDocument.FromFile("Document1.pdf"); var pdf2 = PdfDocument.FromFile("Document2.pdf"); // Merge PDFs var merged = PdfDocument.Merge(new List<PdfDocument> { pdf1, pdf2 }); // Save the merged document merged.SaveAs("Merged.pdf"); } } // NuGet: Install-Package IronPdf using IronPdf; using System.Collections.Generic; class Program { static void Main() { // Load PDF documents var pdf1 = PdfDocument.FromFile("Document1.pdf"); var pdf2 = PdfDocument.FromFile("Document2.pdf"); // Merge PDFs var merged = PdfDocument.Merge(new List<PdfDocument> { pdf1, pdf2 }); // Save the merged document merged.SaveAs("Merged.pdf"); } } $vbLabelText $csharpLabel 合并 PDF 文件的效果对比鲜明。Syncfusion PDF要求为每个输入文档创建 FileStream 对象,将其加载为PDFLoadedDocument,创建一个新的PDF 文档,调用ImportPageRange()并为每个源设置开始和结束索引、创建输出 FileStream 并关闭 6 个独立对象(finalDocument, loadedDocument1, loadedDocument2, stream1, stream2, outputStream )。 IronPDF 使用PdfDocument.FromFile()加载每个 PDF,并使用静态PdfDocument.Merge()方法接受文档列表。 无需流式管理,无需手动计算页面范围,无需千钧一发。 API 理念的主要差异 基于坐标与 HTML/CSS 优先 Syncfusion PDF 使用从传统 PDF 库继承的基于坐标的图形模型: // Syncfusion: 手册 positioning page.Graphics.DrawString("Text", font, PdfBrushes.Black, new PointF(100, 200)); page.Graphics.DrawRectangle(brush, new RectangleF(50, 50, 200, 100)); // Syncfusion: 手册 positioning page.Graphics.DrawString("Text", font, PdfBrushes.Black, new PointF(100, 200)); page.Graphics.DrawRectangle(brush, new RectangleF(50, 50, 200, 100)); $vbLabelText $csharpLabel IronPdf 使用 HTML/CSS 进行排版: // IronPDF: CSS-based positioning var html = @" <div style='margin: 50px; padding: 20px; border: 1px solid black;'> <p style='color: black;'>Text</p> </div>"; var pdf = renderer.RenderHtmlAsPdf(html); // IronPDF: CSS-based positioning var html = @" <div style='margin: 50px; padding: 20px; border: 1px solid black;'> <p style='color: black;'>Text</p> </div>"; var pdf = renderer.RenderHtmlAsPdf(html); $vbLabelText $csharpLabel 对于网络开发人员来说,HTML/CSS 方法更直观、更易于维护,而且在不同页面尺寸下都能产生一致的效果。 流管理与自动清理 Syncfusion PDF 需要明确的流和文档处理: // Syncfusion: 手册 cleanup FileStream fileStream = new FileStream("Output.pdf", FileMode.Create); document.Save(fileStream); document.Close(true); fileStream.Close(); // Syncfusion: 手册 cleanup FileStream fileStream = new FileStream("Output.pdf", FileMode.Create); document.Save(fileStream); document.Close(true); fileStream.Close(); $vbLabelText $csharpLabel IronPdf 会自动处理清理工作: // IronPDF:自动翻译cleanup pdf.SaveAs("Output.pdf"); // IronPDF:自动翻译cleanup pdf.SaveAs("Output.pdf"); $vbLabelText $csharpLabel 功能对比 特征 Syncfusion PDF IronPDF 购买 否(仅限套件) 是 许可 有社区限制的商业翻译 简化商业 HTML 到 PDF 需要 BlinkBinaries 本地 Chromium CSS3 支持。 有限的 完整(flexbox、网格) API 风格 基于坐标的图形 HTML/CSS 优先 流管理 手册 自动翻译 依赖关系 多个软件包 单一 NuGet 部署复杂性 潜在的复杂性 简单明了 迁移清单 迁移前 清点代码库中所有Syncfusion PDF的使用情况 文档许可成本和部署要求 识别PdfGrid 、 PdfGraphics和HtmlToPdfConverter的用法 从ironpdf.com获取IronPDF许可证密钥 代码更新 移除Syncfusion包( Syncfusion.Pdf.Net.Core 、 Syncfusion.HtmlToPdfConverter.Net.Windows 、 Syncfusion.Licensing ) 安装IronPdf NuGet 包 更新命名空间导入( using Syncfusion.Pdf; → using IronPdf; ) 将Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense()替换为IronPdf.License.LicenseKey = "..." 将HtmlToPdfConverter.Convert()替换为ChromePdfRenderer.RenderUrlAsPdf()或RenderHtmlAsPdf() 将PdfDocument + Pages.Add() + Graphics.DrawString()替换为ChromePdfRenderer.RenderHtmlAsPdf() 将PdfLoadedDocument替换为PdfDocument.FromFile() 将ImportPageRange()替换为PdfDocument.Merge() 将document.Save(stream)替换为pdf.SaveAs(path) 删除所有document.Close(true)和stream.Close()调用 将PdfGrid替换为 HTML<table>元素 将PdfStandardFont替换为 CSS font-family 将PdfBrushes替换为 CSS color属性 测试 PDF 输出的视觉比较 验证 CSS 渲染改进(flexbox、grid 现在可以正常工作) 测试文本提取 测试合并和拆分 性能比较 Curtis Chau 立即与工程团队聊天 技术作家 Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。 相关文章 已发布2026年2月1日 如何用 C# 从 ZetPDF 迁移到 IronPDF 通过这本完整的 C# 指南,掌握从 ZetPDF 到 IronPDF 的迁移。从基于坐标的库转换到现代的 HTML 到 PDF 解决方案。包括 HTML 转换、合并 PDF 和移除 PDFSharp 依赖性的代码示例。 阅读更多 已发布2026年2月1日 如何用 C# 从 Scryber.Core 迁移到 IronPDF 通过这本完整的 C# 指南,掌握从 Scryber.Core 迁移到 IronPDF 的方法。从自定义 XML/HTML 解析转换到现代 Chromium 渲染器。包括 HTML 转换、URL 呈现和替换专有绑定的代码示例。 阅读更多 已发布2026年2月1日 如何用 C# 从 XFINIUM.PDF 迁移到 IronPDF 通过这本完整的 C# 指南,掌握从 XFINIUM.PDF 到 IronPDF 的迁移。从基于坐标的手动定位切换到声明式 HTML/CSS 渲染。包括替换图形基元和自动布局的代码示例。 阅读更多 如何用 C# 从 PDFmyURL 迁移到 IronPDF如何用 C# 从 Sumatra PDF 迁移...
已发布2026年2月1日 如何用 C# 从 ZetPDF 迁移到 IronPDF 通过这本完整的 C# 指南,掌握从 ZetPDF 到 IronPDF 的迁移。从基于坐标的库转换到现代的 HTML 到 PDF 解决方案。包括 HTML 转换、合并 PDF 和移除 PDFSharp 依赖性的代码示例。 阅读更多
已发布2026年2月1日 如何用 C# 从 Scryber.Core 迁移到 IronPDF 通过这本完整的 C# 指南,掌握从 Scryber.Core 迁移到 IronPDF 的方法。从自定义 XML/HTML 解析转换到现代 Chromium 渲染器。包括 HTML 转换、URL 呈现和替换专有绑定的代码示例。 阅读更多
已发布2026年2月1日 如何用 C# 从 XFINIUM.PDF 迁移到 IronPDF 通过这本完整的 C# 指南,掌握从 XFINIUM.PDF 到 IronPDF 的迁移。从基于坐标的手动定位切换到声明式 HTML/CSS 渲染。包括替换图形基元和自动布局的代码示例。 阅读更多