跳過到頁腳內容
產品比較

IronPDF對比GemBox.Pdf:完整.NET PDF庫比較指南,用於HTML轉PDF轉換

當開發需要 PDF 產生與操作的 .NET 應用程式時,選擇正確的 C# PDF 函式庫會大大影響專案的成功。 本綜合比較研究 IronPDF 適用於 .NET 和 GemBox.Pdf 這兩個著名的 .NET PDF 函式庫,以協助開發人員根據功能、效能、定價和實際使用案例做出明智的決定。

快速比較概述

產品比較概述
適用於 .NET 開發的 IronPDF 與 GemBox.Pdf 的功能比較
類別 功能/外觀 IronPDF GemBox.Pdf 主要優勢
核心架構 設計理念 HTML 為先、Chrome 瀏覽器渲染 PDF 原生操作 依據上下文
API 的複雜性 RenderHtmlAsPdf() 之類的簡單方法 低階 PDF 物件 IronPDF:更快的開發速度
學習曲線 一般需時 1-2 天 一般需時 3-5 天 IronPDF:快速採用
平台支援 跨平台 Windows、Linux、macOS、Docker Windows、Linux、macOS、Android、iOS GemBox:行動支援
.NET 版本 .NET 10、9、8、7、6、5、Core 3.1 以上、Framework 4.6.2 以上 .NET 6、Standard 2.0、Framework 3.5+ IronPDF:最新的 .NET 支援
雲端平台 Azure/AWS 已優化 標準雲端支援 IronPDF:雲端就緒
HTML至PDF 渲染引擎 完整的 Chrome V8 引擎 無內建 HTML 支援* IronPDF:原生 HTML 至 PDF
支援 CSS3/HTML5 完整支援 需要 GemBox.Document IronPDF:現代網路標準
JavaScript 執行 完整的 JavaScript 支援 不支援 JavaScript IronPDF:動態內容
渲染速度 ~125ms 典型值 不適用 (不支援 HTML) IronPDF:快速渲染
開發人員經驗 代碼範例 100+ 個可立即執行的範例 提供 100+ 個範例 兩者皆有:廣泛的資源
文件 教學、操作方法、影片 API 文件著重於 IronPDF:多種學習途徑
內容處理 合併/分割 PDF 內建方法 內建方法 兩者:標準功能
文字抽取 支援 Unicode、整合 OCR 支援 Unicode、內建 OCR GemBox:內建 OCR
表單支援 HTML 表單至 PDF 表單 建立、填寫、扁平化表單 依據上下文
效能指標 記憶體使用 一般在 10MB 以下 低記憶體佔用量 兩者兼具:高效
線程支援 原生 async/await 最佳化 線程安全操作 IronPDF:更好的動態支援
Security & Encryption 加密等級 AES-256、自訂處理器 AES-256 標準 兩者:行業標準
數位簽名 整合、可視化的簽名 數字簽名支援 兩者兼具:簽名支援
Licensing & Pricing 入門級 Lite: $999 (1 dev, 1 project) 單一開發人員:890 美元(1 名開發人員,無限制專案) IronPDF:較低的入門成本
再發行 +$1,999 免版稅 包含在內,無限制部署 GemBox:更好的部署術語
套件選項 Iron Suite: $1,498 (9 products) GemBox 套件:2,200 美元(7 個產品) IronPDF:更好的套件價值
<強>支援 支援包括 是,24/5 工程支援 是,1 年專業支援 兩者兼具:良好的支援
回應時間 一般需時 24-48 小時 1 個工作天內 兩者兼具:快速回應
最適合 用例 HTML 至 PDF、Web 應用程式、報告 PDF 操作、表格、OCR 依據上下文
GemBox.Pdf 著重於 PDF 操作,需要 GemBox.Document 進行 HTML 轉換。IronPDF 提供本地 HTML 到 PDF 的轉換,並具有完整的瀏覽器渲染功能。 *GemBox 中的 HTML 支援需要額外購買產品。

請注意GemBox.Pdf 需要單獨的 GemBox.Document 庫(需額外支付 890 美元)才能將 HTML 轉換為 PDF。

什麼是 IronPDF Library?

IronPDF 脫穎而出,它是一個全面的 .NET PDF 函式庫,專門用於讓 HTML 轉換為 PDF 對開發人員來說無懈可擊。 IronPDF 以 Chrome 渲染引擎為核心,改變了開發人員在 C#、F# 和 VB.NET 應用程式中生成 PDF 的方式。

圖書館的理念以利用現有的網路開發技能為中心。 開發人員不需要學習複雜的 PDF API,而是可以使用熟悉的 HTML、CSS 和 JavaScript 來建立複雜的 PDF 文件。 此方法可大幅縮短開發時間,同時確保符合現代網路標準的完美畫素呈現。

IronPDF 的核心功能

IronPDF 提供廣泛的功能集,幾乎涵蓋開發人員可能遇到的所有 PDF 相關工作:

HTML 至 PDF 的卓越轉換

  • Chrome V8 引擎:使用與 Google Chrome 相同的引擎渲染 HTML,確保 98% 以上的瀏覽器顯示效果。 -完全支援 CSS3/HTML5:全面支援現代 Web 標準,包括 flexbox、grid 和動畫。
  • JavaScript 執行:在渲染之前處理 JavaScript,完美捕捉動態內容 -響應式設計:支援響應式佈局和可自訂的視口設置 -網頁字體支援:能夠準確渲染 Google 字體、自訂字體和圖示字體。

進階 PDF 操作

-合併和拆分 PDF透過簡單的方法呼叫合併多個 PDF 或提取特定頁面。 -數位簽名應用支援證書的加密簽名 -表單管理從 HTML 建立可填寫表單或修改現有 PDF 表單 -浮水印和圖章添加可控制透明度的文字或圖像浮水印 -頁首和頁尾帶有頁碼的動態頁首/頁尾

安全性與合規性

-加密採用自訂權限設定的 AES-256 加密

  • PDF/A 合規性產生可長期保存的存檔級 PDF 文件 -內容編輯永久移除敏感內容 -密碼保護:支援使用者和所有者密碼,並提供精細權限控制。

IronPDF 程式碼範例:具備進階功能的 HTML 至 PDF

using IronPdf;
using IronPdf.Rendering;

// Configure the Chrome renderer with advanced options
var renderer = new ChromePdfRenderer
{
    RenderingOptions = new ChromePdfRenderOptions
    {
        // Set paper orientation and size
        PaperOrientation = PdfPaperOrientation.Portrait,
        PaperSize = PdfPaperSize.A4,

        // Configure margins (in millimeters)
        MarginTop = 25,
        MarginBottom = 25,
        MarginLeft = 20,
        MarginRight = 20,

        // Enable JavaScript execution
        EnableJavaScript = true,
        RenderDelay = 1000, // Wait 1 second for JS to complete

        // Print background colors and images
        PrintHtmlBackgrounds = true,

        // Create PDF forms from HTML form elements
        CreatePdfFormsFromHtml = true,

        // Custom header and footer
        HtmlHeader = new HtmlHeaderFooter
        {
            Height = 20,
            HtmlFragment = "<div style='text-align: center; font-size: 12px;'>Company Report - {page} of {total-pages}</div>",
            DrawDividerLine = true
        },

        HtmlFooter = new HtmlHeaderFooter
        {
            Height = 15,
            HtmlFragment = "<div style='text-align: center; font-size: 10px;'>© 2025 Company Name. Confidential.</div>"
        }
    }
};

// Convert complex HTML with CSS and JavaScript
string htmlContent = @"
<!DOCTYPE html>
<html>
<head>
    <style>
        body { font-family: 'Segoe UI', Arial, sans-serif; line-height: 1.6; }
        .invoice-header { 
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 30px;
            border-radius: 10px;
            margin-bottom: 30px;
        }
        .data-table { 
            width: 100%; 
            border-collapse: collapse; 
            margin-top: 20px;
        }
        .data-table th { 
            background-color: #f8f9fa; 
            padding: 12px; 
            text-align: left;
            border-bottom: 2px solid #dee2e6;
        }
        .data-table td { 
            padding: 10px; 
            border-bottom: 1px solid #dee2e6;
        }
        .total-section {
            margin-top: 30px;
            text-align: right;
            font-size: 18px;
            font-weight: bold;
        }
        @media print {
            .no-print { display: none; }
        }
    </style>
</head>
<body>
    <div class='invoice-header'>
        <h1>Invoice #INV-2025-001</h1>
        <p>Date: <span id='current-date'></span></p>
    </div>

    <table class='data-table'>
        <thead>
            <tr>
                <th>Item Description</th>
                <th>Quantity</th>
                <th>Unit Price</th>
                <th>Total</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Professional PDF Library License</td>
                <td>1</td>
                <td>$999.00</td>
                <td>$999.00</td>
            </tr>
            <tr>
                <td>Priority Support (1 Year)</td>
                <td>1</td>
                <td>$299.00</td>
                <td>$299.00</td>
            </tr>
        </tbody>
    </table>

    <div class='total-section'>
        <p>Subtotal: $1,048.00</p>
        <p>Tax (8%): $83.84</p>
        <p style='color: #667eea; font-size: 24px;'>Total: $1,131.84</p>
    </div>

    <script>
        // Dynamic date insertion
        document.getElementById('current-date').textContent = new Date().toLocaleDateString('en-US', {
            year: 'numeric',
            month: 'long',
            day: 'numeric'
        });
    </script>
</body>
</html>";

// Render the HTML to PDF
PdfDocument pdf = renderer.RenderHtmlAsPdf(htmlContent);

// Apply additional security settings
pdf.SecuritySettings.OwnerPassword = "admin123";
pdf.SecuritySettings.UserPassword = "user123";
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.NoPrint;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserFormData = true;

// Add metadata
pdf.MetaData.Author = "Invoice System";
pdf.MetaData.Title = "Invoice INV-2025-001";
pdf.MetaData.Subject = "Customer Invoice";
pdf.MetaData.Keywords = "invoice, payment, 2025";
pdf.MetaData.CreationDate = DateTime.Now;

// Save the PDF
pdf.SaveAs("invoice-2025-001.pdf");

// Optional: Save as PDF/A for archival
pdf.SaveAsPdfA("invoice-2025-001-archive.pdf", PdfAVersions.PdfA3);
using IronPdf;
using IronPdf.Rendering;

// Configure the Chrome renderer with advanced options
var renderer = new ChromePdfRenderer
{
    RenderingOptions = new ChromePdfRenderOptions
    {
        // Set paper orientation and size
        PaperOrientation = PdfPaperOrientation.Portrait,
        PaperSize = PdfPaperSize.A4,

        // Configure margins (in millimeters)
        MarginTop = 25,
        MarginBottom = 25,
        MarginLeft = 20,
        MarginRight = 20,

        // Enable JavaScript execution
        EnableJavaScript = true,
        RenderDelay = 1000, // Wait 1 second for JS to complete

        // Print background colors and images
        PrintHtmlBackgrounds = true,

        // Create PDF forms from HTML form elements
        CreatePdfFormsFromHtml = true,

        // Custom header and footer
        HtmlHeader = new HtmlHeaderFooter
        {
            Height = 20,
            HtmlFragment = "<div style='text-align: center; font-size: 12px;'>Company Report - {page} of {total-pages}</div>",
            DrawDividerLine = true
        },

        HtmlFooter = new HtmlHeaderFooter
        {
            Height = 15,
            HtmlFragment = "<div style='text-align: center; font-size: 10px;'>© 2025 Company Name. Confidential.</div>"
        }
    }
};

// Convert complex HTML with CSS and JavaScript
string htmlContent = @"
<!DOCTYPE html>
<html>
<head>
    <style>
        body { font-family: 'Segoe UI', Arial, sans-serif; line-height: 1.6; }
        .invoice-header { 
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 30px;
            border-radius: 10px;
            margin-bottom: 30px;
        }
        .data-table { 
            width: 100%; 
            border-collapse: collapse; 
            margin-top: 20px;
        }
        .data-table th { 
            background-color: #f8f9fa; 
            padding: 12px; 
            text-align: left;
            border-bottom: 2px solid #dee2e6;
        }
        .data-table td { 
            padding: 10px; 
            border-bottom: 1px solid #dee2e6;
        }
        .total-section {
            margin-top: 30px;
            text-align: right;
            font-size: 18px;
            font-weight: bold;
        }
        @media print {
            .no-print { display: none; }
        }
    </style>
</head>
<body>
    <div class='invoice-header'>
        <h1>Invoice #INV-2025-001</h1>
        <p>Date: <span id='current-date'></span></p>
    </div>

    <table class='data-table'>
        <thead>
            <tr>
                <th>Item Description</th>
                <th>Quantity</th>
                <th>Unit Price</th>
                <th>Total</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Professional PDF Library License</td>
                <td>1</td>
                <td>$999.00</td>
                <td>$999.00</td>
            </tr>
            <tr>
                <td>Priority Support (1 Year)</td>
                <td>1</td>
                <td>$299.00</td>
                <td>$299.00</td>
            </tr>
        </tbody>
    </table>

    <div class='total-section'>
        <p>Subtotal: $1,048.00</p>
        <p>Tax (8%): $83.84</p>
        <p style='color: #667eea; font-size: 24px;'>Total: $1,131.84</p>
    </div>

    <script>
        // Dynamic date insertion
        document.getElementById('current-date').textContent = new Date().toLocaleDateString('en-US', {
            year: 'numeric',
            month: 'long',
            day: 'numeric'
        });
    </script>
</body>
</html>";

// Render the HTML to PDF
PdfDocument pdf = renderer.RenderHtmlAsPdf(htmlContent);

// Apply additional security settings
pdf.SecuritySettings.OwnerPassword = "admin123";
pdf.SecuritySettings.UserPassword = "user123";
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.NoPrint;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserFormData = true;

// Add metadata
pdf.MetaData.Author = "Invoice System";
pdf.MetaData.Title = "Invoice INV-2025-001";
pdf.MetaData.Subject = "Customer Invoice";
pdf.MetaData.Keywords = "invoice, payment, 2025";
pdf.MetaData.CreationDate = DateTime.Now;

// Save the PDF
pdf.SaveAs("invoice-2025-001.pdf");

// Optional: Save as PDF/A for archival
pdf.SaveAsPdfA("invoice-2025-001-archive.pdf", PdfAVersions.PdfA3);
Imports IronPdf
Imports IronPdf.Rendering

' Configure the Chrome renderer with advanced options
Dim renderer As New ChromePdfRenderer With {
    .RenderingOptions = New ChromePdfRenderOptions With {
        ' Set paper orientation and size
        .PaperOrientation = PdfPaperOrientation.Portrait,
        .PaperSize = PdfPaperSize.A4,

        ' Configure margins (in millimeters)
        .MarginTop = 25,
        .MarginBottom = 25,
        .MarginLeft = 20,
        .MarginRight = 20,

        ' Enable JavaScript execution
        .EnableJavaScript = True,
        .RenderDelay = 1000, ' Wait 1 second for JS to complete

        ' Print background colors and images
        .PrintHtmlBackgrounds = True,

        ' Create PDF forms from HTML form elements
        .CreatePdfFormsFromHtml = True,

        ' Custom header and footer
        .HtmlHeader = New HtmlHeaderFooter With {
            .Height = 20,
            .HtmlFragment = "<div style='text-align: center; font-size: 12px;'>Company Report - {page} of {total-pages}</div>",
            .DrawDividerLine = True
        },

        .HtmlFooter = New HtmlHeaderFooter With {
            .Height = 15,
            .HtmlFragment = "<div style='text-align: center; font-size: 10px;'>© 2025 Company Name. Confidential.</div>"
        }
    }
}

' Convert complex HTML with CSS and JavaScript
Dim htmlContent As String = "
<!DOCTYPE html>
<html>
<head>
    <style>
        body { font-family: 'Segoe UI', Arial, sans-serif; line-height: 1.6; }
        .invoice-header { 
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 30px;
            border-radius: 10px;
            margin-bottom: 30px;
        }
        .data-table { 
            width: 100%; 
            border-collapse: collapse; 
            margin-top: 20px;
        }
        .data-table th { 
            background-color: #f8f9fa; 
            padding: 12px; 
            text-align: left;
            border-bottom: 2px solid #dee2e6;
        }
        .data-table td { 
            padding: 10px; 
            border-bottom: 1px solid #dee2e6;
        }
        .total-section {
            margin-top: 30px;
            text-align: right;
            font-size: 18px;
            font-weight: bold;
        }
        @media print {
            .no-print { display: none; }
        }
    </style>
</head>
<body>
    <div class='invoice-header'>
        <h1>Invoice #INV-2025-001</h1>
        <p>Date: <span id='current-date'></span></p>
    </div>

    <table class='data-table'>
        <thead>
            <tr>
                <th>Item Description</th>
                <th>Quantity</th>
                <th>Unit Price</th>
                <th>Total</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Professional PDF Library License</td>
                <td>1</td>
                <td>$999.00</td>
                <td>$999.00</td>
            </tr>
            <tr>
                <td>Priority Support (1 Year)</td>
                <td>1</td>
                <td>$299.00</td>
                <td>$299.00</td>
            </tr>
        </tbody>
    </table>

    <div class='total-section'>
        <p>Subtotal: $1,048.00</p>
        <p>Tax (8%): $83.84</p>
        <p style='color: #667eea; font-size: 24px;'>Total: $1,131.84</p>
    </div>

    <script>
        // Dynamic date insertion
        document.getElementById('current-date').textContent = new Date().toLocaleDateString('en-US', {
            year: 'numeric',
            month: 'long',
            day: 'numeric'
        });
    </script>
</body>
</html>"

' Render the HTML to PDF
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf(htmlContent)

' Apply additional security settings
pdf.SecuritySettings.OwnerPassword = "admin123"
pdf.SecuritySettings.UserPassword = "user123"
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.NoPrint
pdf.SecuritySettings.AllowUserCopyPasteContent = False
pdf.SecuritySettings.AllowUserAnnotations = False
pdf.SecuritySettings.AllowUserFormData = True

' Add metadata
pdf.MetaData.Author = "Invoice System"
pdf.MetaData.Title = "Invoice INV-2025-001"
pdf.MetaData.Subject = "Customer Invoice"
pdf.MetaData.Keywords = "invoice, payment, 2025"
pdf.MetaData.CreationDate = DateTime.Now

' Save the PDF
pdf.SaveAs("invoice-2025-001.pdf")

' Optional: Save as PDF/A for archival
pdf.SaveAsPdfA("invoice-2025-001-archive.pdf", PdfAVersions.PdfA3)
$vbLabelText   $csharpLabel

本範例展示了 IronPDF 處理複雜 HTML 佈局的能力,包括漸層、表格、動態 JavaScript 內容,以及進階 PDF 功能(如安全性設定和元資料)。 資料庫能無縫處理一切,產生與 HTML 設計完全相符的專業 PDF。

什麼是 GemBox.Pdf Library?

GemBox.Pdf 代表了一種在 .NET 中操作 PDF 的不同方法。 GemBox.Pdf 並非專注於 HTML 至 PDF 的轉換,而是專精於低階 PDF 作業和直接 PDF 操作。 因此特別適合開發人員需要精確控制 PDF 結構和內容的場景。

該函式庫擅長於處理現有的 PDF 文件,提供強大的讀取、編輯和細階處理 PDF 檔案的功能。 GemBox.Pdf 的運作不需依賴 Adobe Acrobat,因此可在各種環境中直接部署。

GemBox.Pdf 的核心功能

GemBox.Pdf 提供全面的 PDF 操作功能:

PDF 文件操作

-讀取和寫入 PDF:直接存取 PDF 結構和內容 -合併與分割:合併多個 PDF 檔案或提取特定頁面 -複製頁面:在不同的 PDF 文件之間匯入頁面 -頁面管理:以程式設計方式新增、刪除或重新排序頁面

內容擷取與操作

-文本提取:提取帶有定位訊息的Unicode文本 -影像擷取:從 PDF 文件中擷取嵌入的影像

  • OCR 支援:內建光學字元辨識功能,用於識別掃描文檔 內容編輯:永久刪除敏感訊息

表單與互動性

-互動式表單:建立、填寫、展平並匯出 PDF 表單 -表單欄位管理:以程式設計方式存取所有表單欄位類型 -註釋:新增超連結和其他 PDF 註釋

圖形和視覺元素

-繪圖操作:新增文字、圖像和向量圖形 -形狀和路徑:建立複雜的向量圖 -浮水印:添加文字和圖片浮水印 -內容分組:將內容組織成邏輯分組

GemBox.Pdf 程式碼範例:PDF 操作和表單

using GemBox.Pdf;
using GemBox.Pdf.Content;
using GemBox.Pdf.Forms;
using GemBox.Pdf.Security;

// Set license (use FREE-LIMITED-KEY for evaluation)
ComponentInfo.SetLicense("FREE-LIMITED-KEY");

// Create a new PDF document from scratch
using (var document = new PdfDocument())
{
    // Add a page with custom size
    var page = document.Pages.Add();

    // Create formatted text with multiple styles
    using (var formattedText = new PdfFormattedText())
    {
        formattedText.FontSize = 24;
        formattedText.FontFamily = new PdfFontFamily("Arial");
        formattedText.Color = PdfColor.FromRgb(0.2, 0.2, 0.6);
        formattedText.AppendLine("GemBox.Pdf Document Example");

        formattedText.FontSize = 12;
        formattedText.Color = PdfColor.FromRgb(0, 0, 0);
        formattedText.AppendLine("This document demonstrates PDF creation and manipulation features.");

        // Draw text to the page
        page.Content.DrawText(formattedText, new PdfPoint(50, 700));
    }

    // Add a form to the document
    var form = document.Form;

    // Create text field
    var textField = form.Fields.AddText(page, 50, 600, 200, 30);
    textField.Name = "CustomerName";
    textField.Value = "Enter your name";
    textField.Format.Fill.Color = PdfColor.FromRgb(0.95, 0.95, 0.95);

    // Create checkbox
    var checkBox = form.Fields.AddCheck(page, 50, 550, 20, 20);
    checkBox.Name = "Agreement";
    checkBox.Checked = false;

    // Add descriptive text next to checkbox
    using (var checkboxLabel = new PdfFormattedText())
    {
        checkboxLabel.Append("I agree to the terms and conditions");
        page.Content.DrawText(checkboxLabel, new PdfPoint(80, 555));
    }

    // Create submit button
    var submitButton = form.Fields.AddButton(page, 50, 500, 100, 30);
    submitButton.Name = "Submit";
    submitButton.Actions.Activate = PdfActionType.Named;

    // Add button appearance
    using (var buttonText = new PdfFormattedText())
    {
        buttonText.Append("Submit Form");
        buttonText.FontSize = 14;
        buttonText.Color = PdfColor.FromRgb(1, 1, 1);

        // Create button appearance stream
        var appearance = submitButton.Appearance.Normal;
        appearance.Fill.Color = PdfColor.FromRgb(0.2, 0.4, 0.8);
        appearance.Stroke.Color = PdfColor.FromRgb(0.1, 0.2, 0.4);
        appearance.Stroke.Width = 1;

        // Draw button background
        appearance.DrawRectangle(new PdfPoint(0, 0), new PdfSize(100, 30), true, true);

        // Draw button text
        appearance.DrawText(buttonText, new PdfPoint(20, 10));
    }

    // Add a table using low-level graphics
    var tableTop = 400;
    var tableLeft = 50;
    var cellWidth = 150;
    var cellHeight = 30;

    // Draw table headers
    page.Content.DrawRectangle(new PdfPoint(tableLeft, tableTop), 
        new PdfSize(cellWidth * 3, cellHeight), true, true);

    using (var headerText = new PdfFormattedText())
    {
        headerText.FontSize = 12;
        headerText.Color = PdfColor.FromRgb(1, 1, 1);
        headerText.Append("Product");
        page.Content.DrawText(headerText, new PdfPoint(tableLeft + 10, tableTop + 10));

        headerText.Clear();
        headerText.Append("Quantity");
        page.Content.DrawText(headerText, new PdfPoint(tableLeft + cellWidth + 10, tableTop + 10));

        headerText.Clear();
        headerText.Append("Price");
        page.Content.DrawText(headerText, new PdfPoint(tableLeft + cellWidth * 2 + 10, tableTop + 10));
    }

    // Draw table data rows
    var rowData = new[]
    {
        new { Product = "PDF Library", Quantity = "1", Price = "$890" },
        new { Product = "Support Plan", Quantity = "1", Price = "$299" },
        new { Product = "Training", Quantity = "2", Price = "$500" }
    };

    var currentY = tableTop - cellHeight;
    foreach (var row in rowData)
    {
        // Draw cell borders
        page.Content.DrawRectangle(new PdfPoint(tableLeft, currentY), 
            new PdfSize(cellWidth, cellHeight), false, true);
        page.Content.DrawRectangle(new PdfPoint(tableLeft + cellWidth, currentY), 
            new PdfSize(cellWidth, cellHeight), false, true);
        page.Content.DrawRectangle(new PdfPoint(tableLeft + cellWidth * 2, currentY), 
            new PdfSize(cellWidth, cellHeight), false, true);

        // Draw cell content
        using (var cellText = new PdfFormattedText())
        {
            cellText.FontSize = 11;
            cellText.Append(row.Product);
            page.Content.DrawText(cellText, new PdfPoint(tableLeft + 10, currentY + 10));

            cellText.Clear();
            cellText.Append(row.Quantity);
            page.Content.DrawText(cellText, new PdfPoint(tableLeft + cellWidth + 10, currentY + 10));

            cellText.Clear();
            cellText.Append(row.Price);
            page.Content.DrawText(cellText, new PdfPoint(tableLeft + cellWidth * 2 + 10, currentY + 10));
        }

        currentY -= cellHeight;
    }

    // Apply security settings
    var securitySettings = document.SecuritySettings;
    securitySettings.DocumentOpenPassword = "user123";
    securitySettings.PermissionsPassword = "owner123";
    securitySettings.Permissions = PdfPermissions.AllowPrint | PdfPermissions.AllowFormFill;

    // Save the document
    document.Save("gembox-example.pdf");
}

// Example: Manipulating existing PDF
using (var existingDoc = PdfDocument.Load("existing-document.pdf"))
{
    // Extract text from first page
    var page = existingDoc.Pages[0];
    var text = page.Content.GetText();
    Console.WriteLine($"Extracted text: {text}");

    // Add watermark to all pages
    foreach (var p in existingDoc.Pages)
    {
        using (var watermark = new PdfFormattedText())
        {
            watermark.Append("CONFIDENTIAL");
            watermark.FontSize = 50;
            watermark.Color = PdfColor.FromRgb(0.5, 0.5, 0.5);
            watermark.Opacity = 0.3;

            // Calculate center position
            var pageWidth = p.MediaBox.Width;
            var pageHeight = p.MediaBox.Height;
            var textWidth = watermark.Width;
            var textHeight = watermark.Height;

            var x = (pageWidth - textWidth) / 2;
            var y = (pageHeight - textHeight) / 2;

            // Draw watermark diagonally
            p.Content.SaveGraphicsState();
            p.Content.SetTransform(1, 0, 0, 1, x, y);
            p.Content.SetTransform(0.7071, 0.7071, -0.7071, 0.7071, 0, 0);
            p.Content.DrawText(watermark, new PdfPoint(0, 0));
            p.Content.RestoreGraphicsState();
        }
    }

    existingDoc.Save("watermarked-document.pdf");
}
using GemBox.Pdf;
using GemBox.Pdf.Content;
using GemBox.Pdf.Forms;
using GemBox.Pdf.Security;

// Set license (use FREE-LIMITED-KEY for evaluation)
ComponentInfo.SetLicense("FREE-LIMITED-KEY");

// Create a new PDF document from scratch
using (var document = new PdfDocument())
{
    // Add a page with custom size
    var page = document.Pages.Add();

    // Create formatted text with multiple styles
    using (var formattedText = new PdfFormattedText())
    {
        formattedText.FontSize = 24;
        formattedText.FontFamily = new PdfFontFamily("Arial");
        formattedText.Color = PdfColor.FromRgb(0.2, 0.2, 0.6);
        formattedText.AppendLine("GemBox.Pdf Document Example");

        formattedText.FontSize = 12;
        formattedText.Color = PdfColor.FromRgb(0, 0, 0);
        formattedText.AppendLine("This document demonstrates PDF creation and manipulation features.");

        // Draw text to the page
        page.Content.DrawText(formattedText, new PdfPoint(50, 700));
    }

    // Add a form to the document
    var form = document.Form;

    // Create text field
    var textField = form.Fields.AddText(page, 50, 600, 200, 30);
    textField.Name = "CustomerName";
    textField.Value = "Enter your name";
    textField.Format.Fill.Color = PdfColor.FromRgb(0.95, 0.95, 0.95);

    // Create checkbox
    var checkBox = form.Fields.AddCheck(page, 50, 550, 20, 20);
    checkBox.Name = "Agreement";
    checkBox.Checked = false;

    // Add descriptive text next to checkbox
    using (var checkboxLabel = new PdfFormattedText())
    {
        checkboxLabel.Append("I agree to the terms and conditions");
        page.Content.DrawText(checkboxLabel, new PdfPoint(80, 555));
    }

    // Create submit button
    var submitButton = form.Fields.AddButton(page, 50, 500, 100, 30);
    submitButton.Name = "Submit";
    submitButton.Actions.Activate = PdfActionType.Named;

    // Add button appearance
    using (var buttonText = new PdfFormattedText())
    {
        buttonText.Append("Submit Form");
        buttonText.FontSize = 14;
        buttonText.Color = PdfColor.FromRgb(1, 1, 1);

        // Create button appearance stream
        var appearance = submitButton.Appearance.Normal;
        appearance.Fill.Color = PdfColor.FromRgb(0.2, 0.4, 0.8);
        appearance.Stroke.Color = PdfColor.FromRgb(0.1, 0.2, 0.4);
        appearance.Stroke.Width = 1;

        // Draw button background
        appearance.DrawRectangle(new PdfPoint(0, 0), new PdfSize(100, 30), true, true);

        // Draw button text
        appearance.DrawText(buttonText, new PdfPoint(20, 10));
    }

    // Add a table using low-level graphics
    var tableTop = 400;
    var tableLeft = 50;
    var cellWidth = 150;
    var cellHeight = 30;

    // Draw table headers
    page.Content.DrawRectangle(new PdfPoint(tableLeft, tableTop), 
        new PdfSize(cellWidth * 3, cellHeight), true, true);

    using (var headerText = new PdfFormattedText())
    {
        headerText.FontSize = 12;
        headerText.Color = PdfColor.FromRgb(1, 1, 1);
        headerText.Append("Product");
        page.Content.DrawText(headerText, new PdfPoint(tableLeft + 10, tableTop + 10));

        headerText.Clear();
        headerText.Append("Quantity");
        page.Content.DrawText(headerText, new PdfPoint(tableLeft + cellWidth + 10, tableTop + 10));

        headerText.Clear();
        headerText.Append("Price");
        page.Content.DrawText(headerText, new PdfPoint(tableLeft + cellWidth * 2 + 10, tableTop + 10));
    }

    // Draw table data rows
    var rowData = new[]
    {
        new { Product = "PDF Library", Quantity = "1", Price = "$890" },
        new { Product = "Support Plan", Quantity = "1", Price = "$299" },
        new { Product = "Training", Quantity = "2", Price = "$500" }
    };

    var currentY = tableTop - cellHeight;
    foreach (var row in rowData)
    {
        // Draw cell borders
        page.Content.DrawRectangle(new PdfPoint(tableLeft, currentY), 
            new PdfSize(cellWidth, cellHeight), false, true);
        page.Content.DrawRectangle(new PdfPoint(tableLeft + cellWidth, currentY), 
            new PdfSize(cellWidth, cellHeight), false, true);
        page.Content.DrawRectangle(new PdfPoint(tableLeft + cellWidth * 2, currentY), 
            new PdfSize(cellWidth, cellHeight), false, true);

        // Draw cell content
        using (var cellText = new PdfFormattedText())
        {
            cellText.FontSize = 11;
            cellText.Append(row.Product);
            page.Content.DrawText(cellText, new PdfPoint(tableLeft + 10, currentY + 10));

            cellText.Clear();
            cellText.Append(row.Quantity);
            page.Content.DrawText(cellText, new PdfPoint(tableLeft + cellWidth + 10, currentY + 10));

            cellText.Clear();
            cellText.Append(row.Price);
            page.Content.DrawText(cellText, new PdfPoint(tableLeft + cellWidth * 2 + 10, currentY + 10));
        }

        currentY -= cellHeight;
    }

    // Apply security settings
    var securitySettings = document.SecuritySettings;
    securitySettings.DocumentOpenPassword = "user123";
    securitySettings.PermissionsPassword = "owner123";
    securitySettings.Permissions = PdfPermissions.AllowPrint | PdfPermissions.AllowFormFill;

    // Save the document
    document.Save("gembox-example.pdf");
}

// Example: Manipulating existing PDF
using (var existingDoc = PdfDocument.Load("existing-document.pdf"))
{
    // Extract text from first page
    var page = existingDoc.Pages[0];
    var text = page.Content.GetText();
    Console.WriteLine($"Extracted text: {text}");

    // Add watermark to all pages
    foreach (var p in existingDoc.Pages)
    {
        using (var watermark = new PdfFormattedText())
        {
            watermark.Append("CONFIDENTIAL");
            watermark.FontSize = 50;
            watermark.Color = PdfColor.FromRgb(0.5, 0.5, 0.5);
            watermark.Opacity = 0.3;

            // Calculate center position
            var pageWidth = p.MediaBox.Width;
            var pageHeight = p.MediaBox.Height;
            var textWidth = watermark.Width;
            var textHeight = watermark.Height;

            var x = (pageWidth - textWidth) / 2;
            var y = (pageHeight - textHeight) / 2;

            // Draw watermark diagonally
            p.Content.SaveGraphicsState();
            p.Content.SetTransform(1, 0, 0, 1, x, y);
            p.Content.SetTransform(0.7071, 0.7071, -0.7071, 0.7071, 0, 0);
            p.Content.DrawText(watermark, new PdfPoint(0, 0));
            p.Content.RestoreGraphicsState();
        }
    }

    existingDoc.Save("watermarked-document.pdf");
}
Imports GemBox.Pdf
Imports GemBox.Pdf.Content
Imports GemBox.Pdf.Forms
Imports GemBox.Pdf.Security

' Set license (use FREE-LIMITED-KEY for evaluation)
ComponentInfo.SetLicense("FREE-LIMITED-KEY")

' Create a new PDF document from scratch
Using document = New PdfDocument()
	' Add a page with custom size
	Dim page = document.Pages.Add()

	' Create formatted text with multiple styles
	Using formattedText = New PdfFormattedText()
		formattedText.FontSize = 24
		formattedText.FontFamily = New PdfFontFamily("Arial")
		formattedText.Color = PdfColor.FromRgb(0.2, 0.2, 0.6)
		formattedText.AppendLine("GemBox.Pdf Document Example")

		formattedText.FontSize = 12
		formattedText.Color = PdfColor.FromRgb(0, 0, 0)
		formattedText.AppendLine("This document demonstrates PDF creation and manipulation features.")

		' Draw text to the page
		page.Content.DrawText(formattedText, New PdfPoint(50, 700))
	End Using

	' Add a form to the document
	Dim form = document.Form

	' Create text field
	Dim textField = form.Fields.AddText(page, 50, 600, 200, 30)
	textField.Name = "CustomerName"
	textField.Value = "Enter your name"
	textField.Format.Fill.Color = PdfColor.FromRgb(0.95, 0.95, 0.95)

	' Create checkbox
	Dim checkBox = form.Fields.AddCheck(page, 50, 550, 20, 20)
	checkBox.Name = "Agreement"
	checkBox.Checked = False

	' Add descriptive text next to checkbox
	Using checkboxLabel = New PdfFormattedText()
		checkboxLabel.Append("I agree to the terms and conditions")
		page.Content.DrawText(checkboxLabel, New PdfPoint(80, 555))
	End Using

	' Create submit button
	Dim submitButton = form.Fields.AddButton(page, 50, 500, 100, 30)
	submitButton.Name = "Submit"
	submitButton.Actions.Activate = PdfActionType.Named

	' Add button appearance
	Using buttonText = New PdfFormattedText()
		buttonText.Append("Submit Form")
		buttonText.FontSize = 14
		buttonText.Color = PdfColor.FromRgb(1, 1, 1)

		' Create button appearance stream
		Dim appearance = submitButton.Appearance.Normal
		appearance.Fill.Color = PdfColor.FromRgb(0.2, 0.4, 0.8)
		appearance.Stroke.Color = PdfColor.FromRgb(0.1, 0.2, 0.4)
		appearance.Stroke.Width = 1

		' Draw button background
		appearance.DrawRectangle(New PdfPoint(0, 0), New PdfSize(100, 30), True, True)

		' Draw button text
		appearance.DrawText(buttonText, New PdfPoint(20, 10))
	End Using

	' Add a table using low-level graphics
	Dim tableTop = 400
	Dim tableLeft = 50
	Dim cellWidth = 150
	Dim cellHeight = 30

	' Draw table headers
	page.Content.DrawRectangle(New PdfPoint(tableLeft, tableTop), New PdfSize(cellWidth * 3, cellHeight), True, True)

	Using headerText = New PdfFormattedText()
		headerText.FontSize = 12
		headerText.Color = PdfColor.FromRgb(1, 1, 1)
		headerText.Append("Product")
		page.Content.DrawText(headerText, New PdfPoint(tableLeft + 10, tableTop + 10))

		headerText.Clear()
		headerText.Append("Quantity")
		page.Content.DrawText(headerText, New PdfPoint(tableLeft + cellWidth + 10, tableTop + 10))

		headerText.Clear()
		headerText.Append("Price")
		page.Content.DrawText(headerText, New PdfPoint(tableLeft + cellWidth * 2 + 10, tableTop + 10))
	End Using

	' Draw table data rows
	Dim rowData = {
		New With {
			Key .Product = "PDF Library",
			Key .Quantity = "1",
			Key .Price = "$890"
		},
		New With {
			Key .Product = "Support Plan",
			Key .Quantity = "1",
			Key .Price = "$299"
		},
		New With {
			Key .Product = "Training",
			Key .Quantity = "2",
			Key .Price = "$500"
		}
	}

	Dim currentY = tableTop - cellHeight
	For Each row In rowData
		' Draw cell borders
		page.Content.DrawRectangle(New PdfPoint(tableLeft, currentY), New PdfSize(cellWidth, cellHeight), False, True)
		page.Content.DrawRectangle(New PdfPoint(tableLeft + cellWidth, currentY), New PdfSize(cellWidth, cellHeight), False, True)
		page.Content.DrawRectangle(New PdfPoint(tableLeft + cellWidth * 2, currentY), New PdfSize(cellWidth, cellHeight), False, True)

		' Draw cell content
		Using cellText = New PdfFormattedText()
			cellText.FontSize = 11
			cellText.Append(row.Product)
			page.Content.DrawText(cellText, New PdfPoint(tableLeft + 10, currentY + 10))

			cellText.Clear()
			cellText.Append(row.Quantity)
			page.Content.DrawText(cellText, New PdfPoint(tableLeft + cellWidth + 10, currentY + 10))

			cellText.Clear()
			cellText.Append(row.Price)
			page.Content.DrawText(cellText, New PdfPoint(tableLeft + cellWidth * 2 + 10, currentY + 10))
		End Using

		currentY -= cellHeight
	Next row

	' Apply security settings
	Dim securitySettings = document.SecuritySettings
	securitySettings.DocumentOpenPassword = "user123"
	securitySettings.PermissionsPassword = "owner123"
	securitySettings.Permissions = PdfPermissions.AllowPrint Or PdfPermissions.AllowFormFill

	' Save the document
	document.Save("gembox-example.pdf")
End Using

' Example: Manipulating existing PDF
Using existingDoc = PdfDocument.Load("existing-document.pdf")
	' Extract text from first page
	Dim page = existingDoc.Pages(0)
	Dim text = page.Content.GetText()
	Console.WriteLine($"Extracted text: {text}")

	' Add watermark to all pages
	For Each p In existingDoc.Pages
		Using watermark = New PdfFormattedText()
			watermark.Append("CONFIDENTIAL")
			watermark.FontSize = 50
			watermark.Color = PdfColor.FromRgb(0.5, 0.5, 0.5)
			watermark.Opacity = 0.3

			' Calculate center position
			Dim pageWidth = p.MediaBox.Width
			Dim pageHeight = p.MediaBox.Height
			Dim textWidth = watermark.Width
			Dim textHeight = watermark.Height

			Dim x = (pageWidth - textWidth) \ 2
			Dim y = (pageHeight - textHeight) \ 2

			' Draw watermark diagonally
			p.Content.SaveGraphicsState()
			p.Content.SetTransform(1, 0, 0, 1, x, y)
			p.Content.SetTransform(0.7071, 0.7071, -0.7071, 0.7071, 0, 0)
			p.Content.DrawText(watermark, New PdfPoint(0, 0))
			p.Content.RestoreGraphicsState()
		End Using
	Next p

	existingDoc.Save("watermarked-document.pdf")
End Using
$vbLabelText   $csharpLabel

本範例展示 GemBox.Pdf 在低階 PDF 操作方面的優勢,並示範表格建立、圖形繪製和文件安全功能。 雖然代碼比 IronPDF 的 HTML 方式更為冗長,但它提供了對 PDF 各方面的精確控制。

這些函式庫如何處理 HTML 至 PDF 的轉換?

HTML 到 PDF 的轉換方式代表了 IronPDF 與 GemBox.Pdf 最顯著的差異之一。

IronPDF 的 HTML 轉 PDF 方法

IronPDF 從一開始就以 HTML 轉換為 PDF 為主要重點。 該函式庫包含完整的 Chrome 渲染引擎,可完全按照網頁瀏覽器的方式處理 HTML、CSS 和 JavaScript。 這意味著

-真正的瀏覽器渲染:使用與 Google Chrome 相同的 Blink 引擎 -完全符合 Web 標準:全面支援 CSS3、HTML5、Flexbox、Grid 和現代 JavaScript -動態內容:在渲染之前執行 JavaScript,捕捉 AJAX 內容和動態元素 -響應式設計:處理媒體查詢和響應式佈局 -外部資源:自動從 URL 取得圖像、樣式表和字體

GemBox 對 HTML 的有限支援

GemBox.Pdf 本身不支援 HTML 至 PDF 的轉換。 要使用 GemBox 將 HTML 轉換為 PDF,開發人員必須

1.單獨購買 GemBox.Document(額外費用為 890 美元) 2.使用 GemBox.Document 將 HTML 轉換為 DOCX 3.然後將 DOCX 轉換為 PDF

這種方法有很大的限制:

-不支援 JavaScript:無法處理動態內容

  • CSS 支援有限:不支援許多現代 CSS 特性。 -樣式問題:已知邊框和複雜佈局有問題,詳情請參閱Stack Overflow 討論。 -僅限列印最佳化:需要專門針對列印進行格式化的 HTML 程式碼 -額外費用:需要購買兩個獨立的圖書館

現代 CSS 架構支援:關鍵差異

在使用 Bootstrap、Tailwind CSS 和 Foundation 等現代 CSS 框架時,IronPDF 基於 Chrome 瀏覽器的最顯著優勢之一就顯而易見了。 這些框架已成為現代網路應用程式的骨幹,而它們在 PDF 中正確呈現的能力對許多使用個案而言是不可或缺的。

IronPDF:完整的現代框架支援

IronPDF 的 Chrome 渲染引擎為所有現代 CSS 框架提供完整的本機支援:

  • Bootstrap 5:全面支援 flexbox 和 CSS Grid,實現響應式佈局
  • Tailwind CSS:完全支援實用性優先的 CSS 框架 -實際應用範例:完美渲染Bootstrap 首頁Bootstrap 範本。 -現代 CSS3 特性:動畫、變換、轉換、自訂屬性 -響應式設計:媒體查詢和基於視窗的佈局無縫協作

程式碼範例:將 Bootstrap 表單轉換為 PDF

using IronPdf;

var renderer = new ChromePdfRenderer();

string bootstrapForm = @"
<!DOCTYPE html>
<html>
<head>
    <link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css' rel='stylesheet'>
</head>
<body>
    <div class='container mt-5'>
        <h1 class='mb-4'>Customer Registration</h1>
        <form class='needs-validation'>
            <div class='row g-3'>
                <div class='col-md-6'>
                    <label class='form-label'>First Name</label>
                    <input type='text' class='form-control' value='John'>
                </div>
                <div class='col-md-6'>
                    <label class='form-label'>Last Name</label>
                    <input type='text' class='form-control' value='Smith'>
                </div>
            </div>
            <div class='mt-4'>
                <button class='btn btn-primary' type='submit'>Submit</button>
            </div>
        </form>
    </div>
</body>
</html>";

var pdf = renderer.RenderHtmlAsPdf(bootstrapForm);
pdf.SaveAs("bootstrap-form.pdf");
using IronPdf;

var renderer = new ChromePdfRenderer();

string bootstrapForm = @"
<!DOCTYPE html>
<html>
<head>
    <link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css' rel='stylesheet'>
</head>
<body>
    <div class='container mt-5'>
        <h1 class='mb-4'>Customer Registration</h1>
        <form class='needs-validation'>
            <div class='row g-3'>
                <div class='col-md-6'>
                    <label class='form-label'>First Name</label>
                    <input type='text' class='form-control' value='John'>
                </div>
                <div class='col-md-6'>
                    <label class='form-label'>Last Name</label>
                    <input type='text' class='form-control' value='Smith'>
                </div>
            </div>
            <div class='mt-4'>
                <button class='btn btn-primary' type='submit'>Submit</button>
            </div>
        </form>
    </div>
</body>
</html>";

var pdf = renderer.RenderHtmlAsPdf(bootstrapForm);
pdf.SaveAs("bootstrap-form.pdf");
Imports IronPdf

Dim renderer As New ChromePdfRenderer()

Dim bootstrapForm As String = "
<!DOCTYPE html>
<html>
<head>
    <link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css' rel='stylesheet'>
</head>
<body>
    <div class='container mt-5'>
        <h1 class='mb-4'>Customer Registration</h1>
        <form class='needs-validation'>
            <div class='row g-3'>
                <div class='col-md-6'>
                    <label class='form-label'>First Name</label>
                    <input type='text' class='form-control' value='John'>
                </div>
                <div class='col-md-6'>
                    <label class='form-label'>Last Name</label>
                    <input type='text' class='form-control' value='Smith'>
                </div>
            </div>
            <div class='mt-4'>
                <button class='btn btn-primary' type='submit'>Submit</button>
            </div>
        </form>
    </div>
</body>
</html>"

Dim pdf = renderer.RenderHtmlAsPdf(bootstrapForm)
pdf.SaveAs("bootstrap-form.pdf")
$vbLabelText   $csharpLabel

GemBox:不支援現代框架

由於 GemBox.Pdf 缺乏原生 HTML 渲染功能,必須依賴 GemBox.Document 進行 HTML 轉換,因此現代 CSS 框架面臨嚴重的限制:

-不支援 Bootstrap: Flexbox 和 CSS Grid 功能將無法正確渲染。 -不支援 Tailwind CSS:不支援實用類別和現代佈局 -需要手動調整:必須建立針對列印最佳化的 HTML 版本。

  • CSS3 功能受限:許多現代 CSS 功能根本無法使用。 -額外的複雜性:兩步驟轉換過程(HTML → DOCX → PDF)引入了不一致性

根據開發人員的討論,使用 GemBox 的 HTML 轉換方式時,即使是邊框和版面設計等基本 CSS 功能也會出現問題。

實際影響:如果您的應用程式使用 Bootstrap 作為其 UI,並且您需要產生與 Web 介面相符的 PDF 報告或匯出文件,IronPDF 提供了一個簡單的解決方案,而 GemBox 則需要進行大量的重新設計或手動變通。

有關 CSS 架構相容性的詳細資訊,請參閱 Bootstrap & Flexbox CSS 指南

哪個函式庫擅長不同的 PDF 任務?

瞭解每個函式庫的優點有助於開發人員選擇適合其特定需求的工具。

IronPDF 的優勢所在

IronPDF 在這些情境中展現了卓越的性能:

1.Web 應用程式 PDF 產生

非常適合 SaaS 應用程式、網路入口網站,以及任何需要將網路內容轉換為 PDF 的系統。 Chrome 的渲染引擎可確保複雜的網頁佈局,包括使用 Bootstrap、Tailwind CSS 或自訂框架的網頁,都能完美呈現。

2.動態報表產製

當報告包含圖表 (Chart.js、D3.js)、動態資料可視化或 JavaScript 渲染的內容時,IronPDF 會準確地捕捉所有內容。 這使得它成為商業智慧儀表板和資料驅動應用程式的理想選擇。

3.發票和文件範本

使用 HTML/CSS 範本來製作發票、收據和商業文件,可讓設計師在不學習 PDF 特定 API 的情況下製作範本。可以使用熟悉的網頁技術快速進行變更。

4.快速開發專案

簡單的 API 和基於 HTML 的方法可大幅縮短開發時間。開發人員可以在幾分鐘而不是幾小時內建立複雜的 PDF。

5.跨平台部署

IronPdf.Linux 原生支援 Windows、Linux、macOS、Docker 和雲端平台,可簡化跨不同環境的部署。

GemBox.Pdf 的優勢所在

GemBox.Pdf 在這些方面展現了其優勢:

1.低階 PDF 操作

當需要精確控制 PDF 結構時,GemBox.Pdf 的物件導向方式可直接存取 PDF 元素、串流和字典。

2.表格繁重的應用程式

對於廣泛使用 PDF 表單的應用程式,GemBox.Pdf 提供全面的表單欄位操作,包括以程式化方式建立複雜的互動表單。

3.OCR 要求

GemBox.Pdf 內建 OCR 功能,可從掃描的文件中萃取文字,不需要額外的程式庫,因此適用於文件數位化專案。

4.行動開發

對 Android 和 iOS 平台的原生支援讓 GemBox.Pdf 成為需要 PDF 功能的行動應用程式的好選擇。

5.現有 PDF 的修改

當主要處理現有的 PDF 而非產生新的 PDF 時,GemBox.Pdf 的萃取、操作和修改工具非常適合這項任務。

安裝和設定如何比較?

兩個函式庫都可透過 NuGet 直接安裝,但複雜程度不同。

安裝 IronPDF。

IronPDF 的安裝非常簡單:

Install-Package IronPdf

或透過 .NET CLI:

dotnet add package IronPdf

該套件包含所需的一切,包括 Chrome 渲染引擎。在大多數使用情況下,不需要額外的設定或依賴。

針對特定的部署情境,IronPDF 提供:

  • IronPdf.Slim:輕量級軟體包,可在執行時下載平台特定元件。
  • IronPdf.Linux:已預先設定為 Linux 部署
  • IronPdf.MacOs:針對 macOS 環境進行了最佳化

安裝 GemBox.Pdf

GemBox.Pdf 的安裝同樣簡單,可進行基本的 PDF 操作:

Install-Package GemBox.Pdf

然而,要將 HTML 轉換成 PDF,您需要

Install-Package GemBox.Document

這兩個函式庫都需要授權金鑰組態:

// IronPDF
License.LicenseKey = "YOUR-LICENSE-KEY";

// GemBox.Pdf
ComponentInfo.SetLicense("YOUR-LICENSE-KEY");
// IronPDF
License.LicenseKey = "YOUR-LICENSE-KEY";

// GemBox.Pdf
ComponentInfo.SetLicense("YOUR-LICENSE-KEY");
' IronPDF
License.LicenseKey = "YOUR-LICENSE-KEY"

' GemBox.Pdf
ComponentInfo.SetLicense("YOUR-LICENSE-KEY")
$vbLabelText   $csharpLabel

授權與定價有何差異?

瞭解授權模式有助於確定每個解決方案的總擁有成本。

IronPDF 授權。

IronPDF 提供透明的分層授權(價格截至 2025 年):

-精簡版授權: $999

  • 1 名開發人員
  • 1 個專案
  • 1 年的支援與更新
  • Plus 許可證: $1,499
    • 3 名開發人員
    • 3 個專案
    • 1 年的支援與更新

專業許可證: $2,999

  • 10 位開發人員
  • 10 個專案
  • 1 年的支援與更新

其他選項:

  • 免版稅再分發:+$2,999
  • 提供 SaaS/OEM 授權
  • Iron Suite 套裝:$1,498,包含 9 款產品

主要優勢:

  • 30 天退款保證
  • 永久授權 (一次性購買)
  • 免費開發與測試
  • 包括部署到開發/暫存/生產階段

GemBox.Pdf 授權

GemBox 提供按開發人員的授權:

-單一開發商: 890 美元

  • 1 名開發人員
  • 無限制的專案
  • 1 年的支援與更新
  • 包括免版稅部署

重要注意事項:

  • HTML 轉 PDF 需要 GemBox.Document:額外 $890
  • HTML 至 PDF 的總費用:最低 1,780 美元
  • 續約時可享有 40% 的折扣(若在到期前續約,則可享有 60% 的折扣)
  • GemBox 套裝:2,200 美元(7 個產品

主要優勢:

  • 30 天退款保證
  • 永久授權
  • 包含無限制部署
  • 無需伺服器或 OEM 授權

常見情況的成本比較

工作場景 IronPDF 成本 GemBox 成本
單一開發人員,HTML 至 PDF $999 $1,780
3 位開發人員,僅限 PDF 操作 $1,499 $2,670
3 名開發人員,HTML 至 PDF $1,499 $5,340
企業 (10 位開發人員),完整功能 $2,999 $8,900+

您應該選擇哪一個程式庫?

IronPDF 和 GemBox.Pdf 之間的選擇取決於您的特定需求:

選擇 IronPDF 時:。

-將 HTML 轉換為 PDF 是首要需求: IronPDF 基於 Chrome 的渲染功能無可匹敵。 -您需要現代 Web 支援:完整的 CSS3、HTML5 和 JavaScript 功能 快速開發至關重要:簡潔的 API 可縮短產品上市時間 -您需要處理動態內容: JavaScript 執行會擷取即時數據 -需要跨平台部署:對雲端和容器化環境提供卓越的支持 預算也是一個考量: HTML 轉 PDF 方案的入門成本更低,性價比更高。

選擇 GemBox.Pdf 時:

-底層 PDF 控制至關重要:直接存取 PDF 物件和結構 -需要行動平台支援:原生相容 Android 和 iOS

  • OCR 是一項核心要求:內建 OCR,無需額外依賴項 -您主要處理現有 PDF 文件:強大的操作和提取功能 -無需使用 HTML 轉 PDF:避免為未使用的 GemBox.Document 付費 -無限制部署至關重要:包含免版稅再分發。

在下列情況下,請考慮使用這兩個函式庫

有些組織會發現在應用程式的不同部分使用這兩個函式庫的價值:

  • IronPDF 用於報告生成和 HTML 到 PDF 的轉換
  • 用於表單處理和 PDF 操作的 GemBox.Pdf

開始使用您選擇的函式庫。

這兩個函式庫都提供免費試用以評估其功能:

試用 IronPDF

1.安裝 NuGet 套件 2.開發不需要授權金鑰 3.在試用模式下,PDF 上會出現水印 4.評估期間的完整功能存取

下載 IronPDF 免費試用版

試用 GemBox.Pdf

1.安裝 NuGet 套件

  1. 使用 ComponentInfo.SetLicense("FREE-LIMITED-KEY") 3.免費模式下僅限 2 頁 4.升級以消除限制

視覺安裝指南

對於偏好 Visual Studio 圖形介面的開發人員,以下是安裝這兩個函式庫的逐步指南:

建立新的 ASP.NET 專案。

Visual Studio New Project 對話框,顯示 ASP.NET Web Application 選項與 .NET Framework 選項Visual Studio 用於創建 ASP.NET Web 應用程式的新專案對話框 - PDF 生成專案的基礎

ASP.NET 專案範本選擇畫面,高亮顯示 PDF 資料庫整合的 Web 表單選項選擇 Web 表單作為專案範本 - 適用於 IronPDF 和 GemBox.Pdf 實作

透過 NuGet 安裝 PDF 函式庫

解決方案總管上下文功能表,顯示用於新增 PDF 函式庫的管理 NuGet 套件選項在"解決方案總管"中右鍵按一下專案,以存取 NuGet 套件管理員進行函式庫安裝

Visual Studio 專案選單顯示 PDF 函式庫安裝的 Manage NuGet Packages 選項透過 Visual Studio 中的專案功能表存取 NuGet 套件管理員的替代方法

NuGet Package Manager 介面顯示 IronPDF 的安裝情形,並附有版本詳細資訊與說明透過 NuGet 套件管理員安裝 IronPDF - 請注意全面的功能說明和下載次數

其他安裝方法

IronPDF 官方網站下載頁面,顯示手動安裝的直接 DLL 下載選項IronPDF的網站針對不適合安裝NuGet的情況提供直接DLL下載

結論

IronPDF 和 GemBox.Pdf 都是適用於 .NET 開發人員的優質 PDF 函式庫,各自都有明顯的優勢。 IronPDF 藉由 Chrome 演算引擎,在 HTML 至 PDF 的轉換上表現卓越,是現代網路應用程式和動態內容製作的理想選擇。 GemBox.Pdf 在低階 PDF 操作和行動支援方面大放異彩,非常適合需要精確 PDF 控制的應用程式。

對於大多數網路開發人員和建置現代應用程式的團隊而言,IronPDF 提供了功能、易用性和價值的最佳組合。 它能夠使用熟悉的網路技術從 HTML 呈現像素完美的 PDF,大幅降低開發時間與複雜度。

然而,GemBox.Pdf 對於專業的情境,尤其是行動開發及專注於 PDF 表單處理或 OCR 需求的應用程式,仍是一個可靠的選擇。

準備好將您的 HTML 內容轉換成專業的 PDF 嗎? 開始使用 IronPDF 的免費試用版,並在您的 .NET 應用程式中體驗 Chrome 優質渲染的威力。 有了全面的說明文件、廣泛的程式碼範例和快速回應的支援,您將能在幾分鐘內而非幾小時內產生 PDF。

請注意GemBox.Pdf 和 GemBox.Document 是其各自所有者的註冊商標。 本網站與 GemBox.Pdf 或 GemBox.Document 無任何關聯、背書或贊助。 所有產品名稱、標誌和品牌均為其各自擁有者的財產。 比較僅供參考,反映了撰寫時的公開信息。

常見問題解答

怎樣在 C# 中將 HTML 轉換為 PDF?

您可以使用 IronPDF 的 RenderHtmlAsPdf 方法將 HTML 字符串轉換為 PDF。您還可以使用 RenderHtmlFileAsPdf 將 HTML 文件轉換為 PDF。

我可以使用這些庫來操作現有的PDF文件嗎?

是的,IronPDF和GemBox.Pdf都可以用來操作現有的PDF文件。IronPDF簡化了合併、拆分和添加水印等常見任務。GemBox.Pdf提供對PDF對象的更細粒度控制,非常適合複雜的操作任務。

使用IronPDF轉換HTML為PDF有哪些優勢?

IronPDF通過其Chrome V8渲染引擎提供優越的HTML到PDF轉換質量,實現98%以上的瀏覽器忠實度。它支持現代CSS3、HTML5、JavaScript執行、網頁字體和響應式設計。

哪個庫對於小型開發團隊來說更具成本效益?

對於需要HTML到PDF轉換的3人開發團隊來說,IronPDF的加值版許可證費用為1,499美元,而3個GemBox.Pdf和3個GemBox.Document許可證費用為5,340美元。IronPDF為團隊提供了顯著更好的價值。

IronPDF適合批量生成PDF嗎?

是的,IronPDF提供優秀的性能,HTML到PDF渲染時間約125毫秒,優化的異步/等待支持,和低於10MB的高效內存使用。它非常適合基於Web的大量PDF生成。

IronPDF包括什麼樣的支持?

IronPDF提供24/5工程支持,直接訪問開發團隊,通常24-48小時內回應,並提供綜合文檔和代碼示例。

我可以使用這些庫創建符合PDF/A的文件嗎?

是的,IronPDF可以通過簡單的方法調用如SaveAsPdfA()來生成符合PDF/A的文件,支持多個PDF/A版本。GemBox.Pdf可以讀取PDF/A文件並在修改時保持合規性。

這些庫是否與現代.NET框架兼容?

是的,這兩個庫都支持現代.NET版本。IronPDF支持.NET框架4.6.2+、.NET Core 3.1+和.NET 5至10版本。GemBox.Pdf支持.NET框架3.5+、.NET標準2.0和.NET 6+。

哪個庫為雲部署優化?

IronPDF為雲部署優化,專門支持Azure、AWS、Docker容器和無伺服器環境。其基於HTML的方法自然適合Web應用,使其成為SaaS應用的更好選擇。

是否有免費版本可以測試IronPDF?

IronPDF提供免費的評估選項,允許在沒有許可證密鑰的情況下進行無限的開發和測試,但輸出上會有水印。這提供了足夠的功能來在購買前評估產品。

Jacob Mellor, Team Iron 首席技術官
首席技術官

Jacob Mellor是Iron Software的首席技術官,也是開創C# PDF技術的前瞻性工程師。作為Iron Software核心代碼庫的原始開發者,他自公司成立以來就塑造了公司的產品架構,並與CEO Cameron Rimington將公司轉型為服務NASA、Tesla以及全球政府機構的50多人公司。

Jacob擁有曼徹斯特大學土木工程一級榮譽學士學位(1998年–2001年)。他於1999年在倫敦開立首家軟體公司,並於2005年建立了他的第一個.NET組件,專注於解決Microsoft生態系統中的複雜問題。

他的旗艦作品IronPDF和Iron Suite .NET程式庫全球已獲得超過3000萬次NuGet安裝,他的基礎代碼不斷在全球各地驅動開發者工具。擁有25年以上的商業經驗和41年的編碼專業知識,Jacob仍然專注於推動企業級C#、Java和Python PDF技術的創新,同時指導下一代技術領導者。

鋼鐵支援團隊

我們每週 5 天,每天 24 小時在線上。
聊天
電子郵件
打電話給我