跳過到頁腳內容
產品比較

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

在開發需要PDF生成和操作的.NET應用程序時,選擇合適的C# PDF庫可以顯著影響專案的成功。 這份全面的比較檢視了IronPDF和GemBox.Pdf,兩個突出.NET PDF庫,幫助開發者根據功能、性能、定價和真實案例做出明智決策。

快速比較概述

class="product__comprehensive-comparison-table">
class="table-container">
class="table-number">產品比較概述
class="table-title">IronPDF和GemBox.Pdf的.NET開發功能比較
類別 功能/方面 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:現代Web標準
JavaScript執行 完整的JavaScript支持 不支持JavaScript IronPDF:動態內容
渲染速度 ~125毫秒典型 N/A(無HTML支持) IronPDF:快速渲染
開發體驗 代碼示例 100多個可運行範例 100多個範例可用 兩者:豐富資源
文檔 教程、操作指南、視頻 以API文檔為主 IronPDF:多學習途徑
內容操作 合併/拆分PDFs 內建方法 內建方法 兩者:標準功能
文本抽取 Unicode支持,OCR集成 Unicode支持,內建OCR GemBox:內建OCR
表單支持 HTML表單轉PDF表單 創建、填寫、平展表單 依賴上下文
性能指標 內存使用 典型低於10MB 低內存佔用 兩者:高效
線程支持 原生async/await優化 線程安全操作 IronPDF:更好的非同步支持
安全與加密 加密等級 AES-256,自定義處理器 AES-256標準 兩者:行業標準
數位簽名 集成可視簽名 數位簽名支持 兩者:簽名支持
授權與定價 入門級 Lite:$799(1開發者,1專案) 單一開發者:0(1開發者,無限制專案) IronPDF:更低的入門成本
重新發佈 +,999 免版稅 包含,無限制部署 GemBox:更好的部署條款
套件選項 Iron Suite:$1,498(9個產品) GemBox Bundle:,200(7個產品) IronPDF:更好的套件價值
支持 包含支持 是,24/5工程支持 是,1年專業支持 兩者:良好支持
響應時間 24-48小時典型 一個工作日內 兩者:快速響應
最佳適用 使用案例 HTML到PDF,Web應用,報告 PDF操作,表單,OCR 依賴上下文
class="table-note"> 注釋。GemBox.Pdf專注於PDF操作,需要GemBox.Document進行HTML轉換。IronPDF提供本地HTML到PDF轉換,具備完整的瀏覽器渲染。*在GemBox使用HTML支持需要額外的產品購買。

請注意GemBox.Pdf需要單獨的GemBox.Document庫(額外$890)進行HTML到PDF轉換。

什麼是IronPDF庫?

IronPDF是一個全面的.NET PDF庫,專為使HTML到PDF轉換對開發者無縫化而設計。 IronPDF在其核心構建了Chrome渲染引擎,改變了開發者在C#、F#和VB.NET應用程序中生成PDF的方式。

該庫的理念是利用現有的Web開發技能。 開發者可以使用熟悉的HTML、CSS和JavaScript來創建複雜的PDF文檔,而不需要學習複雜的PDF API。 這種方法大大縮短了開發時間,同時確保與現代WEB標準相匹配的像素級完美渲染。

IronPDF的核心功能

IronPDF提供了涵蓋幾乎每個開發者可能遇到的PDF相關任務的廣泛功能集:

HTML到PDF轉換之優

  • Chrome V8引擎:使用與Google Chrome相同的引擎渲染HTML,確保98%以上的瀏覽器一致性
  • 完整的CSS3/HTML5支持:全面支持現代Web標準,包括flexbox、grid和動畫
  • JavaScript執行:渲染前處理JavaScript,完美捕捉動態內容
  • 響應式設計:處理響應式佈局並提供可定制的視窗設置
  • Web字體支持:準確渲染Google字體、定製字體及圖標字體

高級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>$799.00</td>
                <td>$799.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>$799.00</td>
                <td>$799.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);
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

此示例展示了IronPDF處理具有梯度、表格、動態JavaScript內容等複雜HTML佈局的能力,以及像安全設置和元數據這樣的高級PDF功能。 該庫無縫處理所有事物,生成的專業PDF與HTML設計完全匹配。

什麼是GemBox.Pdf庫?

GemBox.Pdf代表了一種不同的.NET中的PDF操作方法。 它不是專注於HTML到PDF的轉換,而是專注於低層次的PDF運算和直接的PDF操作。 這使得它特別適合需要準確控制PDF結構和內容的場景。

該庫擅長於處理現有的PDF文檔,提供了強大的功能,以逐級的水平讀取、編輯和操作PDF文件。 GemBox.Pdf的操作不依賴於Adobe Acrobat,使跨多個環境的部署變得簡單。

GemBox.Pdf的核心功能

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

PDF文檔操作

  • 讀寫PDFs:直觀訪問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內容和動態元素
  • 響應設計:處理媒體查詢和響應式佈局
  • 外部資源:自動從URLs獲取圖片、樣式表和字體

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
  • 額外成本:需要購買兩個單獨的庫

Modern CSS框架支持:一個關鍵之別

當處理像Bootstrap、Tailwind CSS和Foundation這樣的現代CSS框架時,IronPDF的Chrome基礎渲染的優勢變得顯而易見。 這些框架已成為現代Web應用程序的骨幹,能否正確在PDF中呈現對於許多使用情境至關重要。

IronPDF:完整現代框架支持

IronPDF的Chrome渲染引擎提供了對所有現代CSS框架的全面、本地支持:

  • Bootstrap 5:對響應式佈局的全方位flexbox和CSS網格支持
  • Tailwind CSS:完整的優先使用實用程序的CSS框架支持
  • Real-world examples: Renders the Bootstrap homepage and Bootstrap templates pixel-perfect
  • 現代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");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

GemBox:無現代框架支持

由於GemBox.Pdf缺乏本地HTML渲染,必須依賴GemBox.Document進行HTML轉換,現代CSS框架面臨嚴重限制:

  • 不支持Bootstrap:Flexbox和CSS Grid功能無法正確渲染
  • 不支持Tailwind CSS:不支持實用程序類和現代佈局
  • 需要手動解決方案:必須創建打印優化版的HTML
  • 有限的CSS3:許多現代CSS功能都無法工作
  • 額外複雜性:兩步轉換過程(HTML → DOCX → PDF)引入不一致性

根據開發人員的討論,即使是像邊框和佈局這樣的基本CSS功能在GemBox的HTML轉換方法也可能出現問題。

真實世界的影響:如果你的應用程序使用Bootstrap作為其UI,且需要生成與Web介面匹配的PDF報告或導出,IronPDF提供了一個簡單的解決方案,而GemBox則需要重大修改或手動工作。

有關 CSS 框架相容性的更多詳細信息,請參閱Bootstrap & Flexbox CSS 指南

哪個庫在不同的PDF任務中表現最佳?

理解每個庫在哪方面表現最佳有助於開發者根據具體需求選擇合適的工具。

IronPDF擅長的地方

IronPDF在這些場景中表現出色:

1. Web應用程序的PDF生成

非常適合SaaS應用程序、網絡門戶和需要將網頁內容轉換為PDF的任何系統。 Chrome渲染引擎確保包括那些使用Bootstrap、Tailwind CSS或自訂框架的複雜Web佈局完美呈現。

2. 動態報告生成

當報告中包含圖表(如Chart.js,D3.js)、動態數據可視化或JavaScript渲染內容時,IronPDF能準確捕捉一切。 這使得它成為商業智能儀表板和數據驅動應用程序的理想選擇。

3. 發票和文檔模板

使用HTML/CSS模板進行發票、收據和商業文件允許設計師在不需要學習PDF專用API的情況下創建模板。使用熟悉的Web技術可以快速更改。

4. 快速開發項目

簡單的API和基於HTML的方法極大地減少了開發時間。開發人員可以在分鐘內創建一個複雜的PDF,而不是幾小時。

5. 跨平台部署

由於原生支持Windows、Linux、macOS、Docker和雲平台,IronPDF簡化了跨多樣化環境的部署。

GemBox.Pdf擅長的地方

GemBox.Pdf在這些方面表現出色:

1. 低層次PDF操作

當需要對PDF結構進行準確控制時,GemBox.Pdf的面向對象的方法提供了對PDF元素、流和字典的直接訪問。

2. 表單豐富的應用程序

對於與PDF表單密切合作的應用程序,GemBox.Pdf提供了全面的表單字段操作,包括程式化創建複雜的交互表單。

3. OCR需求

借助內建的OCR功能,GemBox.Pdf可以從掃描文檔中提取文本,而不需要額外庫,使其適合文檔數位化專案。

4. 移動開發

原生支持Android和iOS平台,使GemBox.Pdf成為需要PDF功能的移動應用程序的良好選擇。

5. 現有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

基礎PDF操作時,GemBox.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年的定價):

  • Lite License:$799

    • 1 名開發者
    • 1 個項目
    • 1年支持和更新
  • Plus License:$1,199

    • 3 名開發者
    • 3 個項目
    • 1年支持和更新
  • Professional License:$2,399
    • 10 名開發者
    • 10 個項目
    • 1年支持和更新

額外選項

  • 免版稅重新發佈:+$2,399
  • 可用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 Bundle:$2,200元/7個產品

主要優勢

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

常見情境下的成本比較

情境 IronPDF成本 GemBox成本
單一開發者,HTML到PDF $749 $1,780
3名開發者,僅PDF操作 $1,499 $2,670
3名開發者,HTML到PDF $1,199 $5,340
企業(10名開發者),全功能 $2,399 $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轉換
  • GemBox.Pdf用於表單處理和PDF操作

如何開始著手選擇的庫?

這兩個庫皆提供免費試用來評估其能力:

試用IronPDF

  1. 安裝NuGet包
  2. 開發中不需要License密鑰
  3. 在試用模式PDF上會出現浮水印
  4. 評估期間全面功能訪問

下載IronPDF免費試用

試用GemBox.Pdf

  1. 安裝NuGet包
  2. 使用ComponentInfo.SetLicense("FREE-LIMITED-KEY")
  3. 免費模式限制為2頁
  4. 升級以移除限制

可視化安裝指南

對於喜歡使用Visual Studio圖形界面的開發者,以下是安裝這兩個庫的逐步指南:

創建新的ASP.NET項目

Visual Studio新項目對話框顯示ASP.NET Web應用程序選擇的.NET框架選項 Visual Studio新的項目對話框用於創建一個ASP.NET Web應用程序-PDF生成項目的基礎

ASP.NET項目模板選擇屏幕突出顯示Web表單選項以便於PDF庫集成 選擇Web表單作為項目模板-適用於IronPDF和GemBox.Pdf的實施

通過NuGet安裝PDF庫

Solution Explorer上下文菜單顯示管理NuGet包選項以添加PDF庫 右鍵單擊Solution Explorer中的項目以進入NuGet包管理器進行庫安裝

Visual Studio項目菜單顯示管理NuGet包選項以進行PDF庫安裝 通過Visual Studio的項目菜單進入NuGet包管理器的另一種方法

NuGet包管理器界面顯示IronPDF的安裝及版本詳情與描述 通過NuGet包管理器安裝IronPDF--注意全面的功能描述和下載次數

替代安裝方法

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

結論

IronPDF和GemBox.Pdf都為.NET開發者提供優質的PDF庫,各有其明顯的優勢。 IronPDF憑藉其Chrome渲染引擎在HTML到PDF的轉換中表現出色,非常適合現代Web應用程序和動態內容生成。 GemBox.Pdf在低層次的PDF操作和移動支持方面表現突出,非常適合需要精確PDF控制的應用程序。

對於大多數開發現代應用程序的Web開發者和團隊來說,IronPDF提供了功能、易用性和價值的最佳組合。 其使用熟悉的Web技術從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 一起將其轉變為一家擁有超過 50 名員工的公司,為 NASA、特斯拉 和 全世界政府機構服務。

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

他的旗艦產品 IronPDF & IronSuite .NET 庫在全球 NuGet 被安裝超過 3000 萬次,其基礎代碼繼續為世界各地的開發工具提供動力。擁有 25 年的商業經驗和 41 年的編碼專業知識,Jacob 仍專注於推動企業級 C#、Java 及 Python PDF 技術的創新,同時指導新一代技術領袖。