跳過到頁腳內容
遷移指南

如何在 C# 中從 GemBox PDF 遷移到 IronPDF

從GemBox PDF遷移到 IronPDF:完整的 C# 遷移指南。

從GemBox PDF轉換到IronPDF可將您的 .NET PDF 工作流程從基於坐標的程式化文件建構轉換為基於 HTML/CSS 的現代化渲染。 本指南提供全面、逐步的轉換路徑,消除段落限制,簡化專業 .NET 開發人員的文件製作。

為何要從GemBox PDF轉移到 IronPDF?

GemBox PDF的挑戰

GemBox PDF 是一個功能強大的 .NET PDF 元件,但它有一些影響實際開發的重大限制:

1. 免費版中的 20 段限制: 免費版限制您只能撰寫 20 段,表格單元格會計入此限制內。 一個簡單的 10 行 5 欄表格使用了 50 個"段落",使得免費版本甚至無法用於基本的商業文件。

2.沒有 HTML 到 PDF 的轉換:GemBox PDF 需要程式化的文件建構。 您必須計算座標並手動定位每個元素 - 沒有簡單的"渲染此 HTML"功能。

3.基於座標的佈局:不同於 HTML/CSS 自然流暢的佈局,GemBox PDF 需要您為每個文字元素、圖片和形狀計算精確的 X/Y 位置。

4.有限的功能集:與全面性的 PDF 函式庫相比,GemBox PDF 著重於基本操作 - 讀取、寫入、合併、分割 - 沒有 HTML 渲染或現代 CSS 支援等進階功能。

5.僅程式化:每次設計變更都需要程式碼變更。 想要調整間距嗎? 重新計算座標。 想要不同的字型大小?調整下方所有 Y 位置。

6.表格單元格計數:段落限制會計算表格單元格,而不只是可見的段落。這使得免費版本對於包含表格的文件幾乎毫無價值。

7.設計的學習曲線:開發人員必須以座標而非文件流程來思考,這使得像"新增一個段落"這樣的簡單工作變得出奇的複雜。

GemBox PDF與IronPDF的比較

範疇GemBox PDFIronPDF
免費版本限制20 段(包括表格單元格)僅提供水印,無內容限制
HTML 至 PDF不支援完整的 Chromium 引擎
排版方式基於座標、手動HTML/CSS 流程佈局
表格計入段落限制無限制,使用 HTML 表格
現代 CSS不適用Flexbox、網格、CSS3 動畫
JavaScript 支援不適用完整的 JavaScript 執行
設計變更重新計算坐標編輯 HTML/CSS
學習曲線PDF 座標系統HTML/CSS (熟悉網頁)

對於計劃在 2025 年和 2026 年之前採用 .NET 10 和 C# 14 的團隊而言,IronPDF 提供了一個面向未來的基礎,利用熟悉的網路技術來產生 PDF。


遷移複雜性評估

按功能估計的工作量

特點遷移複雜性筆記
載入/儲存 PDF非常低直接方法對應
合併 PDF非常低直接方法對應
分割 PDF頁面索引處理
文字擷取非常低直接方法對應
新增文字語言協調 → HTML
表格手冊 → HTML 表格
圖片協調 → HTML
水印不同的 API
密碼保護語言不同的結構
表格欄位語言API 差異

範式轉移

這次GemBox PDF遷移的最大改變是從 基於座標的版面設計轉換為 HTML/CSS版面設計

GemBox PDF:  "在位置 (100, 700) 繪製文字
IronPdf:     "使用 CSS 設定渲染此 HTML

對於熟悉網路技術的開發人員而言,這種範式轉換一般較為容易,但需要以不同的方式思考 PDF。


開始之前

先決條件

1..NET 版本:IronPDF 支持 .NET Framework 4.6.2+ 和 .NET Core 2.0+ / .NET 5/6/7/8/9+ 。 2.許可金鑰:從ironpdf.com取得您的IronPDF授權金鑰。 3.備份:為移轉工作建立分支 4.HTML/CSS知識:基本熟悉有助於翻譯,但非必要。

辨識所有GemBox PDF使用方式

# Find allGemBox PDFreferences
grep -r "GemBox\.Pdf\|PdfDocument\|PdfPage\|PdfFormattedText\|ComponentInfo\.SetLicense" --include="*.cs" .

# Find package references
grep -r "GemBox\.Pdf" --include="*.csproj" .
# Find allGemBox PDFreferences
grep -r "GemBox\.Pdf\|PdfDocument\|PdfPage\|PdfFormattedText\|ComponentInfo\.SetLicense" --include="*.cs" .

# Find package references
grep -r "GemBox\.Pdf" --include="*.csproj" .
SHELL

NuGet 套件變更

# Remove GemBox PDF
dotnet remove package GemBox.Pdf

# Install IronPDF
dotnet add package IronPdf
# Remove GemBox PDF
dotnet remove package GemBox.Pdf

# Install IronPDF
dotnet add package IronPdf
SHELL

快速啟動遷移

步驟 1:更新授權組態

之前 (GemBox PDF):

// Must call before anyGemBox PDFoperations
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
// Or for professional:
ComponentInfo.SetLicense("YOUR-PROFESSIONAL-LICENSE");
// Must call before anyGemBox PDFoperations
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
// Or for professional:
ComponentInfo.SetLicense("YOUR-PROFESSIONAL-LICENSE");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

After (IronPDF):

// Set once at application startup
IronPdf.License.LicenseKey = "YOUR-IRONPDF-LICENSE-KEY";

// Or in appsettings.json:
// { "IronPdf.License.LicenseKey": "YOUR-LICENSE-KEY" }
// Set once at application startup
IronPdf.License.LicenseKey = "YOUR-IRONPDF-LICENSE-KEY";

// Or in appsettings.json:
// { "IronPdf.License.LicenseKey": "YOUR-LICENSE-KEY" }
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

步驟 2:更新命名空間匯入

// Before (GemBox PDF)
using GemBox.Pdf;
using GemBox.Pdf.Content;

// After (IronPDF)
using IronPdf;
using IronPdf.Editing;
// Before (GemBox PDF)
using GemBox.Pdf;
using GemBox.Pdf.Content;

// After (IronPDF)
using IronPdf;
using IronPdf.Editing;
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

步驟 3:基本轉換模式

之前 (GemBox PDF):

using GemBox.Pdf;
using GemBox.Pdf.Content;

ComponentInfo.SetLicense("FREE-LIMITED-KEY");

using (var document = new PdfDocument())
{
    var page = document.Pages.Add();
    var formattedText = new PdfFormattedText()
    {
        Text = "Hello World",
        FontSize = 24
    };

    page.Content.DrawText(formattedText, new PdfPoint(100, 700));
    document.Save("output.pdf");
}
using GemBox.Pdf;
using GemBox.Pdf.Content;

ComponentInfo.SetLicense("FREE-LIMITED-KEY");

using (var document = new PdfDocument())
{
    var page = document.Pages.Add();
    var formattedText = new PdfFormattedText()
    {
        Text = "Hello World",
        FontSize = 24
    };

    page.Content.DrawText(formattedText, new PdfPoint(100, 700));
    document.Save("output.pdf");
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

After (IronPDF):

using IronPdf;

IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";

var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1 style='font-size:24px;'>Hello World</h1>");
pdf.SaveAs("output.pdf");
using IronPdf;

IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";

var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1 style='font-size:24px;'>Hello World</h1>");
pdf.SaveAs("output.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

主要差異:

  • 不需要坐標計算
  • 以 HTML/CSS 取代程式化排版
  • 無段落限制
  • 更簡單、更易讀的程式碼

完整的 API 參考資料

命名空間對應

GemBox PDFIronPDF
<編碼>GemBox.Pdf</編碼<編碼>IronPdf</編碼
GemBox.Pdf.內容IronPdf (內容為 HTML)
GemBox.Pdf.安全性IronPdf (SecuritySettings)
GemBox.Pdf.Forms<代碼>IronPdf.Forms</代碼

核心類映射

GemBox PDFIronPDF說明
<編碼>PDF 文件</編碼<編碼>PDF 文件</編碼主要 PDF 文件類別
PdfPage<代碼>PdfDocument.Pages[i]</代碼頁面表示
PDFContent不適用 (使用 HTML)頁面內容
<編碼>PDFFormattedText</編碼不適用 (使用 HTML)格式化文字
PdfPoint不適用 (使用 CSS 定位)座標定位
<編碼>ComponentInfo.SetLicense()</編碼IronPDF.License.LicenseKey授權管理

文件操作

GemBox PDFIronPDF筆記
new PdfDocument()new PdfDocument()建立新文件
<代碼>PdfDocument.Load(path)</代碼PdfDocument.FromFile(path)從檔案載入
<代碼>PdfDocument.Load(stream)</代碼PdfDocument.FromStream(stream)從串流載入
<編碼>document.Save(路徑)</編碼<代碼>pdf.SaveAs(路徑)</代碼儲存至檔案
document.Save(stream)pdf.Streampdf.BinaryData以流/位元組的方式取得

頁面運作

GemBox PDFIronPDF筆記
<編碼>document.Pages.Add()</編碼透過 HTML 渲染建立新增頁面
<編碼>document.Pages.Count</編碼<編碼>pdf.PageCount</編碼頁數
<編碼>document.Pages[index]</編碼<編碼>pdf.Pages[index]</編碼存取頁面 (均為 0 索引)
document.Pages.AddClone(pages)<代碼>PdfDocument.Merge()</代碼克隆/合併頁面

文字與內容作業

GemBox PDFIronPDF筆記
new PdfFormattedText() 新的 PdfFormattedText()。HTML 字串文字內容
formattedText.FontSize=12CSS font-size: 12pt字體大小
formattedText.Font = ...</編碼CSS font-family: ...</編碼字型系列
page.Content.DrawText(text,point)renderer.RenderHtmlAsPdf(html)渲染文本
<編碼>page.Content.GetText()</編碼pdf.ExtractTextFromPage(i)擷取文字

程式碼遷移範例

範例 1:HTML 到 PDF 的轉換

之前 (GemBox PDF):

// NuGet: Install-Package GemBox.Pdf
using GemBox.Pdf;
using GemBox.Pdf.Content;

class Program
{
    static void Main()
    {
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var document = PdfDocument.Load("input.html");
        document.Save("output.pdf");
    }
}
// NuGet: Install-Package GemBox.Pdf
using GemBox.Pdf;
using GemBox.Pdf.Content;

class Program
{
    static void Main()
    {
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var document = PdfDocument.Load("input.html");
        document.Save("output.pdf");
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

After (IronPDF):

// NuGet: Install-Package IronPdf
using IronPdf;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
        pdf.SaveAs("output.pdf");
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
        pdf.SaveAs("output.pdf");
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

IronPdf 的 ChromePdfRenderer 使用現代的 Chromium 引擎進行精確的 HTML/CSS/JavaScript 渲染。 與GemBox PDF有限的 HTML 支援不同,IronPDF 可呈現任何 HTML 內容,並完整支援 CSS3 與 JavaScript。 請參閱 HTML to PDF 文件,以瞭解更多渲染選項。

範例 2:合併 PDF 檔案

之前 (GemBox PDF):

// NuGet: Install-Package GemBox.Pdf
using GemBox.Pdf;
using System.Linq;

class Program
{
    static void Main()
    {
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        using (var document = new PdfDocument())
        {
            var source1 = PdfDocument.Load("document1.pdf");
            var source2 = PdfDocument.Load("document2.pdf");

            document.Pages.AddClone(source1.Pages);
            document.Pages.AddClone(source2.Pages);

            document.Save("merged.pdf");
        }
    }
}
// NuGet: Install-Package GemBox.Pdf
using GemBox.Pdf;
using System.Linq;

class Program
{
    static void Main()
    {
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        using (var document = new PdfDocument())
        {
            var source1 = PdfDocument.Load("document1.pdf");
            var source2 = PdfDocument.Load("document2.pdf");

            document.Pages.AddClone(source1.Pages);
            document.Pages.AddClone(source2.Pages);

            document.Save("merged.pdf");
        }
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

After (IronPDF):

// NuGet: Install-Package IronPdf
using IronPdf;

class Program
{
    static void Main()
    {
        var pdf1 = PdfDocument.FromFile("document1.pdf");
        var pdf2 = PdfDocument.FromFile("document2.pdf");

        var merged = PdfDocument.Merge(pdf1, pdf2);
        merged.SaveAs("merged.pdf");
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;

class Program
{
    static void Main()
    {
        var pdf1 = PdfDocument.FromFile("document1.pdf");
        var pdf2 = PdfDocument.FromFile("document2.pdf");

        var merged = PdfDocument.Merge(pdf1, pdf2);
        merged.SaveAs("merged.pdf");
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

IronPdf 的靜態 Merge 方法簡化了操作 - 無需創建一個空文檔並單獨克隆頁面。 進一步瞭解 合併與分割 PDF 的相關資訊。

範例 3:將文字新增至 PDF

之前 (GemBox PDF):

// NuGet: Install-Package GemBox.Pdf
using GemBox.Pdf;
using GemBox.Pdf.Content;

class Program
{
    static void Main()
    {
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        using (var document = new PdfDocument())
        {
            var page = document.Pages.Add();
            var formattedText = new PdfFormattedText()
            {
                Text = "Hello World",
                FontSize = 24
            };

            page.Content.DrawText(formattedText, new PdfPoint(100, 700));
            document.Save("output.pdf");
        }
    }
}
// NuGet: Install-Package GemBox.Pdf
using GemBox.Pdf;
using GemBox.Pdf.Content;

class Program
{
    static void Main()
    {
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        using (var document = new PdfDocument())
        {
            var page = document.Pages.Add();
            var formattedText = new PdfFormattedText()
            {
                Text = "Hello World",
                FontSize = 24
            };

            page.Content.DrawText(formattedText, new PdfPoint(100, 700));
            document.Save("output.pdf");
        }
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

After (IronPDF):

// NuGet: Install-Package IronPdf
using IronPdf;
using IronPdf.Editing;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderHtmlAsPdf("<p>Original Content</p>");

        var stamper = new TextStamper()
        {
            Text = "Hello World",
            FontSize = 24,
            HorizontalOffset = 100,
            VerticalOffset = 700
        };

        pdf.ApplyStamp(stamper);
        pdf.SaveAs("output.pdf");
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using IronPdf.Editing;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderHtmlAsPdf("<p>Original Content</p>");

        var stamper = new TextStamper()
        {
            Text = "Hello World",
            FontSize = 24,
            HorizontalOffset = 100,
            VerticalOffset = 700
        };

        pdf.ApplyStamp(stamper);
        pdf.SaveAs("output.pdf");
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

為了在現有的 PDF 中加入文字,IronPDF 提供了 TextStamper 類,可提供精確的定位控制。 對於新文件,只需將文字包含在 HTML 模板中即可。 有關其他選項,請參閱 戳記文件

範例 4:建立表格(最大的改進!)

之前 (GemBox PDF) - 每個單元格計入 20 段限制:

using GemBox.Pdf;
using GemBox.Pdf.Content;

ComponentInfo.SetLicense("FREE-LIMITED-KEY");

using (var document = new PdfDocument())
{
    var page = document.Pages.Add();
    double y = 700;
    double[] xPositions = { 50, 200, 300, 400 };

    // Headers (4 paragraphs)
    var headers = new[] { "Product", "Price", "Qty", "Total" };
    for (int i = 0; i < headers.Length; i++)
    {
        var text = new PdfFormattedText { Text = headers[i], FontSize = 12 };
        page.Content.DrawText(text, new PdfPoint(xPositions[i], y));
    }
    y -= 20;

    // Data rows (4 paragraphs per row!)
    // Can only add a few rows before hitting 20-paragraph limit!

    document.Save("products.pdf");
}
using GemBox.Pdf;
using GemBox.Pdf.Content;

ComponentInfo.SetLicense("FREE-LIMITED-KEY");

using (var document = new PdfDocument())
{
    var page = document.Pages.Add();
    double y = 700;
    double[] xPositions = { 50, 200, 300, 400 };

    // Headers (4 paragraphs)
    var headers = new[] { "Product", "Price", "Qty", "Total" };
    for (int i = 0; i < headers.Length; i++)
    {
        var text = new PdfFormattedText { Text = headers[i], FontSize = 12 };
        page.Content.DrawText(text, new PdfPoint(xPositions[i], y));
    }
    y -= 20;

    // Data rows (4 paragraphs per row!)
    // Can only add a few rows before hitting 20-paragraph limit!

    document.Save("products.pdf");
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

後 (IronPDF) - 無限制、正確的 HTML 表格:

using IronPdf;

IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";

var html = @"
    <html>
    <head>
        <style>
            table { border-collapse: collapse; width: 100%; }
            th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
            th { background-color: #4CAF50; color: white; }
            tr:nth-child(even) { background-color: #f2f2f2; }
        </style>
    </head>
    <body>
        <table>
            <thead>
                <tr>
                    <th>Product</th>
                    <th>Price</th>
                    <th>Qty</th>
                    <th>Total</th>
                </tr>
            </thead>
            <tbody>
                <tr><td>Widget A</td><td>$19.99</td><td>5</td><td>$99.95</td></tr>
                <tr><td>Widget B</td><td>$29.99</td><td>3</td><td>$89.97</td></tr>
                <!-- Add hundreds or thousands of rows - no limit! -->
            </tbody>
        </table>
    </body>
    </html>";

var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("products.pdf");
using IronPdf;

IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";

var html = @"
    <html>
    <head>
        <style>
            table { border-collapse: collapse; width: 100%; }
            th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
            th { background-color: #4CAF50; color: white; }
            tr:nth-child(even) { background-color: #f2f2f2; }
        </style>
    </head>
    <body>
        <table>
            <thead>
                <tr>
                    <th>Product</th>
                    <th>Price</th>
                    <th>Qty</th>
                    <th>Total</th>
                </tr>
            </thead>
            <tbody>
                <tr><td>Widget A</td><td>$19.99</td><td>5</td><td>$99.95</td></tr>
                <tr><td>Widget B</td><td>$29.99</td><td>3</td><td>$89.97</td></tr>
                <!-- Add hundreds or thousands of rows - no limit! -->
            </tbody>
        </table>
    </body>
    </html>";

var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("products.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

這是GemBox PDF遷移中最顯著的改進。 在GemBox PDF免費版本中無法使用的表格,在IronPDF中卻能完美運作,並支援完整的 CSS 設定。


關鍵遷移注意事項

坐標轉換為 CSS 定位

如果您需要像素完美定位(類似於GemBox PDF的座標系統),請使用 CSS 絕對定位:

<div style="position:absolute; left:50px; top:750px; font-size:24px;">
    Text positioned at specific coordinates
</div>
<div style="position:absolute; left:50px; top:750px; font-size:24px;">
    Text positioned at specific coordinates
</div>
HTML

頁面索引

GemBox PDF 和IronPDF都使用 0 索引頁面,因此這方面的轉換工作簡單直接:

// GemBox PDF
var page = document.Pages[0];

// IronPDF
var page = pdf.Pages[0];
// GemBox PDF
var page = document.Pages[0];

// IronPDF
var page = pdf.Pages[0];
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

安全設定

// GemBox PDF
document.SaveOptions.SetPasswordEncryption(userPassword, ownerPassword);

// IronPDF
pdf.SecuritySettings.UserPassword = "userPassword";
pdf.SecuritySettings.OwnerPassword = "ownerPassword";
// GemBox PDF
document.SaveOptions.SetPasswordEncryption(userPassword, ownerPassword);

// IronPDF
pdf.SecuritySettings.UserPassword = "userPassword";
pdf.SecuritySettings.OwnerPassword = "ownerPassword";
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

疑難排解

問題 1:PdfFormattedText 未找到

問題PdfFormattedText 在IronPDF中不存在。

解決方案:使用具有 CSS 定義的 HTML:

// GemBox PDF
var text = new PdfFormattedText { Text = "Hello", FontSize = 24 };

// IronPDF
var html = "<p style='font-size:24px;'>Hello</p>";
var pdf = renderer.RenderHtmlAsPdf(html);
// GemBox PDF
var text = new PdfFormattedText { Text = "Hello", FontSize = 24 };

// IronPDF
var html = "<p style='font-size:24px;'>Hello</p>";
var pdf = renderer.RenderHtmlAsPdf(html);
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

問題 2:找不到 DrawText 方法

問題page.Content.DrawText() 無法使用。

解決方案:透過 HTML 呈現或使用印章器建立內容:

// For new documents - render HTML
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Content</h1>");

// For existing documents - use stampers
var stamper = new TextStamper() { Text = "Added Text" };
pdf.ApplyStamp(stamper);
// For new documents - render HTML
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Content</h1>");

// For existing documents - use stampers
var stamper = new TextStamper() { Text = "Added Text" };
pdf.ApplyStamp(stamper);
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

問題 3:文件載入的差異

問題PdfDocument.Load() 未找到。

解決方案:使用 PdfDocument.FromFile()FromStream()

// GemBox PDF
var doc = PdfDocument.Load("input.pdf");

// IronPDF
var pdf = PdfDocument.FromFile("input.pdf");
// GemBox PDF
var doc = PdfDocument.Load("input.pdf");

// IronPDF
var pdf = PdfDocument.FromFile("input.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

問題 4:儲存方法的差異

問題document.Save() 方法簽章不同。

解決方案:使用 SaveAs()

// GemBox PDF
document.Save("output.pdf");

// IronPDF
pdf.SaveAs("output.pdf");
// GemBox PDF
document.Save("output.pdf");

// IronPDF
pdf.SaveAs("output.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

遷移清單

預遷移

  • [清查程式碼庫中所有GemBox PDF的使用情況
  • [ ] 識別需要 HTML 轉換的基於坐標的佈局
  • [ ] 評估目前影響您程式碼的段落限制
  • [ ] 獲得 IronPdf 授權金鑰
  • [ ] 在版本控制中建立遷移分支

程式碼遷移

  • [ ] 移除GemBox PDFNuGet 套件:dotnet remove package GemBox.Pdf
  • [ ] 安裝 IronPdf NuGet 套件:dotnet add package IronPdf
  • [ ] 更新命名空間匯入
  • [ ] 將<編碼>ComponentInfo.SetLicense()</編碼替換為IronPDF.License.LicenseKey。。
  • [ ] 將 PdfDocument.Load() 轉換為 PdfDocument.FromFile()
  • [ ] 將 document.Save() 轉換為 pdf.SaveAs()
  • [ ] 以 HTML 內容取代基於座標的文字
  • [ ] 使用 CSS 定義將<編碼>PDFFormattedText</編碼轉換為 HTML
  • [ ] 更新合併操作以使用 PdfDocument.Merge()

測試

  • [ ] 確認所有文件都能正確生成
  • [驗證文件外觀是否符合預期
  • [ ] 測試表格生成(之前受限於 20 段規則)
  • [ ] 確認文字擷取工作正常
  • [ ] 測試合併與分割作業
  • [驗證安全性/加密功能

後遷移

  • [ ] 移除GemBox PDF授權金鑰
  • [ ] 更新文件
  • [為 PDF 團隊提供 HTML/CSS 方式的訓練
  • [ ] 享受無段落限制的無限制內容!

結論

從GemBox PDF遷移到IronPDF可消除計算表格單元格的令人沮喪的 20 段限制,以直覺的 HTML/CSS 排版取代基於坐標的定位,並提供基於 Chromium 的現代化渲染引擎以準確產生文件。

從程式化的文件建構到以 HTML 為基礎的渲染,這種範式的轉變充分利用了大多數開發人員已有的技能,縮短了開發時間,使設計變更就像編輯 HTML 和 CSS 一樣簡單。 對於建立文件繁重應用程式的團隊而言,此GemBox PDF遷移功能可消除人為的內容限制,並為複雜、專業的 PDF 生成提供可能性。

探索完整的IronPdf文件教程API參考,加速您的遷移。

Curtis Chau
技術作家

Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。

除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。