如何在 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-first 函式庫。 本指南提供完整的逐步遷移路徑,可免除僅限套件的授權、複雜的部署要求以及基於坐標的定位。
為什麼要從Syncfusion PDF轉移到 IronPDF?
瞭解Syncfusion PDFFramework
Syncfusion PDF Framework 是一個全面的函式庫,提供廣泛的功能,可使用 C# 來建立、編輯和保護 PDF 文件。 它是 融合 的 Essential Studio 的一部分,其中包括跨越多種平台的一千多個元件。
然而,它最顯著的缺點之一就是不能作為獨立產品購買; 開發人員必須購買整套 融合 元件。 對於只對 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取得您的許可證密鑰。
NuGet 套件變更
# Remove 融合 packages
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
# Remove 融合 packages
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 any 融合 calls
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR-SYNCFUSION-KEY");
// Must register before any 融合 calls
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR-SYNCFUSION-KEY");
' Must register before any 融合 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: 融合 PDF
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: 融合 PDF
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: 融合 PDF
Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Graphics
Imports Syncfusion.Pdf.Parsing
Imports Syncfusion.HtmlConverter
Imports Syncfusion.Drawing
' After: IronPDF
Imports IronPdf
Imports IronPdf.Rendering
核心 API 對應
| 融合 | 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 to 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 使用基於坐標的圖形模型。 您創建了 @@--CODE-20099--@@,添加了 @@--CODE-20100--@@,創建了 @@--CODE-20101--@@,並添加了 @@--CODE-20102--@@,然後使用顯式坐標 (@@--CODE-20104--@@)、字體和筆刷 (@@--CODE-20105--@@) 呼叫 @@--CODE-20103--@@。 最後,您可以管理 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 需要為每個輸入文件建立 @@--CODE-20108--@@ 對象,將其載入為 @@--CODE-20109--@@,建立一個新的 @@--CODE-20110--@@,使用每個來源的起始和結束索引呼叫 @@--CODE-20111--@@,建立一個輸出 @@--CODE-20112--@@,然後關閉六個單獨的物件(@@--CODE-20113--@@、@@--CODE-20114--@@、@@--CODE-20115--@@、@@--CODE-20116--@@、@@--CODE-20117--@@、@@--CODE-20118--@@)。
IronPDF 使用 PdfDocument.FromFile() 載入每個 PDF,並使用靜態 PdfDocument.Merge() 方法接受文件清單。 無需流管理、無需手動計算頁面範圍、無需千鈞一髮。
API 理念的主要差異
基於座標 vs 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 方法對網頁開發人員而言更直覺、更容易維護,並能在不同大小的頁面上產生一致的結果。
串流管理 vs 自動清理
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");
' IronPDF:自動化cleanup
pdf.SaveAs("Output.pdf")
功能比較
| 特點 | Syncfusion PDF | IronPDF |
|---|---|---|
| Standalone 購買 | 無(僅套件) | 是 |
| 授權 | 商業與社群限制 | 簡化商業 |
| HTML至PDF | 需要 BlinkBinaries | 原生 Chromium |
| CSS3 支援。 | 限額 | 完整 (flexbox、grid) |
| API 風格 | 基於座標的圖形 | HTML/CSS 為先 |
| 流管理 | 手動的 | 自動化 |
| 依賴性 | 多種套件 | 單一 NuGet |
| 部署複雜性 | 潛在的複雜性 | 簡單直接 |
遷移清單
預遷移
- 清點程式碼庫中所有Syncfusion PDF的使用情況
- 文件許可成本和部署要求
- 辨識
PdfGrid、PdfGraphics和HtmlToPdfConverter的用法 - 從ironpdf.com取得IronPDF許可證金鑰
程式碼更新
- 移除 融合 軟體套件(
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 現在可以正常運作)
- 測試文字擷取
- 測試合併和拆分
- 效能比較

