如何用 C# 从 Syncfusion PDF 迁移到 IronPDF
Full Comparison
Looking for a detailed feature-by-feature breakdown? See how IronPDF stacks up against Syncfusion PDF on pricing, HTML support, and licensing.
从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
许可配置
Syncfusion:
// Must register before anySyncfusioncalls
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR-SYNCFUSION-KEY");
// Must register before anySyncfusioncalls
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR-SYNCFUSION-KEY");
' Must register before any Syncfusion calls
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR-SYNCFUSION-KEY")
IronPDF:
// One-time at startup
IronPdf.License.LicenseKey = "YOUR-IRONPDF-KEY";
// One-time at startup
IronPdf.License.LicenseKey = "YOUR-IRONPDF-KEY";
' One-time at startup
IronPdf.License.LicenseKey = "YOUR-IRONPDF-KEY"
完整的 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;
Imports IronPdf
Imports IronPdf.Rendering
核心 API 映射
| Syncfusion | IronPDF |
|---|---|
PdfDocument |
ChromePdfRenderer |
PdfLoadedDocument |
PdfDocument.FromFile() |
HtmlToPdfConverter |
ChromePdfRenderer |
graphics.DrawString() |
HTML 文本元素 |
graphics.DrawImage() |
<img> 标签 |
PdfGrid |
HTML <table> |
PdfStandardFont |
CSS font-family |
PdfBrushes.Black |
CSS color: black |
document.Security |
pdf.SecuritySettings |
PdfTextExtractor |
pdf.ExtractAllText() |
ImportPageRange() |
PdfDocument.Merge() |
document.Save(stream) |
pdf.SaveAs(path) |
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();
}
}
Imports Syncfusion.HtmlConverter
Imports Syncfusion.Pdf
Imports System.IO
Module Program
Sub Main()
' Initialize HTML to PDF converter
Dim htmlConverter As New HtmlToPdfConverter()
' Convert URL to PDF
Dim document As PdfDocument = htmlConverter.Convert("https://www.example.com")
' Save the document
Dim fileStream As New FileStream("Output.pdf", FileMode.Create)
document.Save(fileStream)
document.Close(True)
fileStream.Close()
End Sub
End Module
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");
}
}
Imports IronPdf
Class Program
Shared Sub Main()
' Create a PDF from a URL
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderUrlAsPdf("https://www.example.com")
' Save the PDF
pdf.SaveAs("Output.pdf")
End Sub
End Class
本例展示了 API 的基本差异。Syncfusion PDF需要一个 HtmlToPdfConverter 实例,调用 Convert() 并返回一个 PdfDocument,然后手动创建一个 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();
}
}
Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Graphics
Imports Syncfusion.Drawing
Imports System.IO
Module Program
Sub Main()
' Create a new PDF document
Dim document As New PdfDocument()
' Add a page
Dim page As PdfPage = document.Pages.Add()
' Create a font
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
' Draw text
page.Graphics.DrawString("Hello, World!", font, PdfBrushes.Black, New PointF(10, 10))
' Save the document
Dim fileStream As New FileStream("Output.pdf", FileMode.Create)
document.Save(fileStream)
document.Close(True)
fileStream.Close()
End Sub
End Module
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");
}
}
Imports IronPdf
Imports IronPdf.Rendering
Class Program
Shared Sub Main()
' Create a PDF from HTML string
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Hello, World!</h1>")
' Save the document
pdf.SaveAs("Output.pdf")
End Sub
End Class
Syncfusion PDF 使用基于坐标的图形模型。 您创建了 PdfDocument,添加了 PdfPage,创建了 PdfFont,并使用 PdfFontFamily.Helvetica,然后使用显式坐标 (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();
}
}
Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Parsing
Imports System.IO
Class Program
Shared Sub Main()
' Load the first PDF document
Dim stream1 As New FileStream("Document1.pdf", FileMode.Open, FileAccess.Read)
Dim loadedDocument1 As New PdfLoadedDocument(stream1)
' Load the second PDF document
Dim stream2 As New FileStream("Document2.pdf", FileMode.Open, FileAccess.Read)
Dim loadedDocument2 As New PdfLoadedDocument(stream2)
' Merge the documents
Dim finalDocument As New PdfDocument()
finalDocument.ImportPageRange(loadedDocument1, 0, loadedDocument1.Pages.Count - 1)
finalDocument.ImportPageRange(loadedDocument2, 0, loadedDocument2.Pages.Count - 1)
' Save the merged document
Dim outputStream As 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()
End Sub
End Class
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");
}
}
Imports IronPdf
Imports System.Collections.Generic
Class Program
Shared Sub Main()
' Load PDF documents
Dim pdf1 = PdfDocument.FromFile("Document1.pdf")
Dim pdf2 = PdfDocument.FromFile("Document2.pdf")
' Merge PDFs
Dim merged = PdfDocument.Merge(New List(Of PdfDocument) From {pdf1, pdf2})
' Save the merged document
merged.SaveAs("Merged.pdf")
End Sub
End Class
合并 PDF 文件的效果对比鲜明。Syncfusion PDF需要为每个输入文档创建 FileStream 对象,将它们加载为 PdfLoadedDocument,创建一个新的 PdfDocument,使用每个源的起始和结束索引调用 ImportPageRange(),创建一个输出 FileStream,然后关闭六个单独的对象(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));
' Syncfusion: 手册 positioning
page.Graphics.DrawString("Text", font, PdfBrushes.Black, New PointF(100, 200))
page.Graphics.DrawRectangle(brush, New RectangleF(50, 50, 200, 100))
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);
' IronPDF: CSS-based positioning
Dim html As String = "
<div style='margin: 50px; padding: 20px; border: 1px solid black;'>
<p style='color: black;'>Text</p>
</div>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
对于网络开发人员来说,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();
' Syncfusion: 手册 cleanup
Dim fileStream As New FileStream("Output.pdf", FileMode.Create)
document.Save(fileStream)
document.Close(True)
fileStream.Close()
IronPDF 会自动处理清理工作:
// IronPDF:自动翻译cleanup
pdf.SaveAs("Output.pdf");
// IronPDF:自动翻译cleanup
pdf.SaveAs("Output.pdf");
功能对比
| 特征 | 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) 安装IronPdfNuGet 包 - 更新命名空间导入(
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替换为 CSSfont-family - 将
PdfBrushes替换为 CSScolor属性
测试
- PDF 输出的视觉比较
- 验证 CSS 渲染改进(flexbox、grid 现在可以正常工作)
- 测试文本提取
- 测试合并和拆分
- 性能比较

