IRONSOFTWAREHOME
影片

如何使用 iTextSharp | IronPDF 在 C# 中為 PDF 新增數位簽章

Curtis Chau
Curtis Chau
Updated: 2026年7月19日

從Syncfusion PDF Framework遷移到IronPDF,將您的PDF生成工作流程從一個大型套件中以坐標為基礎的圖形API轉變為以HTML/CSS為優先、使用現代Chromium渲染的獨立程式庫。 此指南提供完整的逐步遷移路徑,消除僅限套件的授權、複雜的部署要求以及以坐標為基礎的定位。

為什麼從Syncfusion PDF遷移到IronPDF

了解Syncfusion PDF Framework

Syncfusion PDF Framework是一個全面的程式庫,提供使用C#建立、編輯和保護PDF文件的廣泛功能。 它作為Syncfusion's Essential Studio的一部分提供,其中包括多個平台上的上千個組件。

PDF程式庫不能作為單一組件購買。 Syncfusion現提供一個"Document SDK"層級,將PDF、Word、Excel和PowerPoint程式庫與完整的Essential Studio套件一起捆綁,沒有UI組件。需要僅PDF功能的團隊至少必須選擇Document SDK,當其他文件程式庫未使用時,這可能會顯得繁瑣。

捆綁授權問題

Syncfusion的授權模式對僅需要PDF功能的團隊造成顯著挑戰:

  1. **無法按程式庫購買:**PDF被捆綁至Document SDK(PDF + Word + Excel + PowerPoint)或完整的Essential Studio中 — 無法單獨授權
  2. **社區授權限制:**免費層級要求年收入小於100萬美元,開發者不超過5人,且總員工不超過10人,外部資本終生限制為300萬美元
  3. **複雜的部署授權:**網頁、桌面、伺服器部署需不同授權
  4. **需要年度續約:**訂閱模式,需支付年度費用(最短1年期)
  5. **按開發者定價:**費用隨團隊規模線性增長
  6. 捆綁冗餘: Document SDK即使您只需要PDF,也會引入Word/Excel/PowerPoint的依賴; 完整的Essential Studio更增加1000+ UI組件

Syncfusion PDF與IronPDF比較

|方面| Syncfusion PDF |IronPDF| |--------|----------------|---------| | 購買模式 | Document SDK捆綁或完整的Essential Studio(沒有按程式庫SKU)| 獨立 | |授權| 複雜的層級 | 簡單的按開發者 | | 社區限制 | <$1M revenue, ≤5 devs, ≤10 employees, ≤$3M outside capital | 免費試用,之後授權 | |部署| 多種授權型別 | 一個授權涵蓋所有 | | API風格| 以坐標為基礎的圖形 + HTML轉換器 | HTML/CSS優先 | | HTML引擎 | Blink(單獨的Windows/Linux/Mac NuGets) | 捆綁Chromium | | CSS 支援 | 現代(Blink)— 接近Chromium平價 | 完整CSS3/flexbox/grid | | 依賴關係 |多個套件| 單一NuGet | | 捆綁要求 | 是(Document SDK或Essential Studio) | 否 | | 專注於PDF | 廣泛; 是更大捆綁的一部分 | 狹窄; 專注於PDF |

IronPDF通過將PDF功能作為獨立產品提供更專注的方法。 這一差異顯著影響成本考量和整合的便利性。

對於採用現代.NET的團隊,IronPDF的獨立授權和HTML/CSS優先的方法提供了沒有捆綁依賴的靈活性。


開始之前

前提條件

  1. .NET環境:.NET Framework 4.6.2+ 或.NET Core 3.1+ / .NET 5/6/7/8/9+
  2. NuGet存取: 有能力安裝NuGet套件
  3. IronPDF授權:ironpdf.com獲取您的授權金鑰

NuGet包變更

# Remove Syncfusion 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
SHELL

授權配置

Syncfusion:

// Must register before any Syncfusion calls
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR-SYNCFUSION-KEY");

IronPDF:

// One-time at startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";

完整API參考

名稱空間變更

// Before: Syncfusion 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;

核心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();
    }
}

之後(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");
    }
}

此範例展示了基本API差異。 Syncfusion PDF需要一個FileStream,保存並關閉文件和流。

IronPDF使用RenderUrlAsPdf(), 僅需三行程式碼。 無需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();
    }
}

之後(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");
    }
}

Syncfusion PDF使用坐標為基礎的圖形模型。 您建立一個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();
    }
}

之後(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");
    }
}

合併PDF的對比是顯著的。 Syncfusion PDF需要為每個輸入文件建立FileStream,然後關閉六個獨立物件 (finalDocument, loadedDocument1, loadedDocument2, stream1, stream2, outputStream)。

IronPDF使用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));
C#

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);

HTML/CSS方法對網頁開發者更直觀、更易於維護,並在不同頁面尺寸下產生一致的結果。

流管理與自動清理

Syncfusion PDF需要明確流和文件處理:

// Syncfusion: 手動 cleanup
FileStream fileStream = new FileStream("Output.pdf", FileMode.Create);
document.Save(fileStream);
document.Close(true);
fileStream.Close();
C#

IronPDF自動處理清理:

// IronPDF:自動cleanup
pdf.SaveAs("Output.pdf");
C#

功能比較

| 功能 | Syncfusion PDF |IronPDF| |---------|----------------|---------| | 獨立購買 | 否(Document SDK或Essential Studio)| 是 | |授權| 商業授權附社區限制 | 簡化的商業 | | HTML引擎 | Blink(平台專用NuGets) | 捆綁Chromium | | CSS3支援 | 通過Blink現代 | 完整(flexbox, grid) | | API風格| 以坐標為基礎的圖形 + HTML轉換器 | HTML/CSS優先 | | 流管理 | 手動 |自動| | 依賴關係 |多個套件| 單一NuGet | |部署複雜性| 潛在複雜 | 簡單明了 |


遷移檢查表

遷移前

  • 編目所有程式碼庫中的Syncfusion PDF使用
  • 記錄授權成本和部署要求
  • 確認PdfGrid, PdfGraphics, 和HtmlToPdfConverter的使用
  • 獲取IronPDF授權金鑰來自ironpdf.com

程式碼更新

  • 移除Syncfusion套件 (Syncfusion.Pdf.Net.Core, Syncfusion.HtmlToPdfConverter.Net.Windows, Syncfusion.Licensing)
  • 安裝IronPdf NuGet套件
  • 更新命名空間導入 (using Syncfusion.Pdf;using IronPdf;)
  • 替換IronPdf.License.LicenseKey = "..."
  • 替換RenderHtmlAsPdf()
  • 替換PdfDocument + Pages.Add() + ChromePdfRenderer.RenderHtmlAsPdf()
  • 替換PdfDocument.FromFile()
  • 替換PdfDocument.Merge()
  • 替換pdf.SaveAs(path)
  • 移除所有stream.Close()調用
  • 替換PdfGrid為HTML <table>元素
  • 替換PdfStandardFont為CSS font-family
  • 替換PdfBrushes為CSS color屬性

測試

  • PDF輸出的視覺比較
  • 驗證CSS渲染改進(flexbox、grid現在可用)
  • 測試文字提取
  • 測試合併和分割
  • 性能比較

Please note: Syncfusion為其各自擁有者的註冊商標。 本站與Syncfusion無關,不受其認可或贊助。 所有產品名稱、標誌和品牌均為其各自所有者的財產。 比較僅供參考,反映撰寫時公開可用的資訊。
Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...
Read More

Related Articles

Key in blue circle

立即免費取得 30 天試用金鑰

bullet_checked無需信用卡或建立帳號
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
預訂您的免費現場演示
Booking Badge related to IronPDF Product Demo

受到全球數百萬工程師的信任

Iron Software的客戶標誌
獲取您的無義務諮詢
填寫以下表格或電子郵件sales@ironsoftware.com
您的詳細資訊將始終保密
受到全球數百萬工程師的信任
Iron Software的客戶標誌
立即獲取您的30天試用金鑰
無需信用卡或帳戶建立