跳至页脚内容
迁移指南

如何用 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) 处绘制文本" 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 文档类别
<代码>PDF 页</代码<代码>PdfDocument.Pages[i]</代码页面表示
<代码>PDF 内容</代码不适用(使用 HTML)页面内容
<代码>PDFFormattedText</代码不适用(使用 HTML)格式化文本
<代码>PdfPoint</代码不适用(使用 CSS 定位)坐标定位
<代码>ComponentInfo.SetLicense()</代码<代码>IronPdf.License.LicenseKey</代码许可证管理

文档操作

GemBox PDFIronPDF备注
<代码>new PdfDocument()</ 代码<代码>new PdfDocument()</ 代码创建新文档
<代码>PdfDocument.Load(path)</代码<代码>PdfDocument.FromFile(路径)</代码从文件加载
<代码>PdfDocument.Load(stream)</代码<代码>PdfDocument.FromStream(流)</代码从流加载
<代码>document.Save(路径)</代码<代码>pdf.SaveAs(路径)</代码保存到文件
<代码>document.Save(流)</代码<代码>pdf.Stream</代码>或<代码>pdf.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()</ 代码HTML 字符串文本内容
<代码>formattedText.FontSize = 12</ 代码CSS 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 移除 GemBox.Pdf 包</代码
  • [ ] 安装 IronPdf NuGet 软件包:<代码>dotnet 添加软件包 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 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。