如何用 C# 从 GrabzIt 迁移到 IronPDF
从GrabzIt迁移到IronPDF可将您的 .NET PDF 工作流程从基于云的截图捕获服务(具有回调复杂性)转变为进程内库,该库可生成具有可选择、可搜索文本的真正矢量 PDF。 本指南为专业的 .NET 开发人员提供了一个全面的、逐步的迁移路径,消除了外部服务器依赖性、回调处理程序和按捕获量定价。
为什么要从GrabzIt迁移到 IronPDF.
GrabzIt架构问题
GrabzIt 是一种基于云的屏幕截图和 PDF 捕捉服务。虽然方便快速集成,但它有基本的架构限制:
1.基于图像的 PDF:GrabzIt创建基于屏幕截图的 PDF,其中文本不可选——本质上是包装在 PDF 格式中的图像。 这对于任何需要文本操作或可访问性的使用案例来说都是一个基本限制。
2.外部处理:所有内容都会发送到GrabzIt的服务器进行处理——这会对敏感数据造成隐私和合规性方面的担忧。 您的 HTML 内容离开了您的基础架构。
3.回调复杂性:GrabzIt使用异步回调模型,需要 webhook 处理基础设施。 您必须设置端点来接收结果,这增加了架构的复杂性。
4.按捕获量定价:按使用量付费模式在规模化时可能会变得很昂贵。 每生成一份 PDF 都需要成本。
5.无法进行文本搜索:由于 PDF 是基于图像的,因此如果没有 OCR,文本搜索和提取就无法进行——这需要额外的步骤和成本。
6.文件大小更大:基于图像的 PDF 文件比基于矢量的 PDF 文件大得多,通常是后者的 5-10 倍。
7.网络依赖性:没有互联网连接就无法生成 PDF,因此无法离线使用。
8.延迟:每次生成 PDF 都需要与外部服务器进行网络往返,增加 500 毫秒至 5 秒的延迟。
GrabzIt与IronPDF对比
| 方面 | GrabzIt | IronPDF |
|---|---|---|
| PDF 类型 | 基于图像(截图) | 真正的矢量 PDF |
| 文本选择 | 不可能 | 全文选择 |
| 文本搜索 | 需要 OCR | 本地可搜索 |
| 处理地点 | 外部服务器 | 本地/流程中 |
| 隐私保护 | 外部发送的数据 | 数据保持本地化 |
| 延迟 | 网络往返(500ms-5s) | 本地处理(~100 毫秒) |
| 定价模式 | 每次捕获 | 每位开发人员许可证 |
| 离线能力 | 否 | 是 |
| 文件大小 | 大图(图像数据) | 小(矢量数据) |
| 需要回电 | 是(异步) | 否(同步/异步) |
| CSS/JS 支持 | 有限的 | 完整的 Chromium 引擎 |
对于计划在 2025 年和 2026 年之前采用 .NET 10 和 C# 14 的团队来说,IronPDF 提供了一个面向未来的基础,其本地处理与现代 .NET 模式原生集成。
迁移复杂性评估
按功能估算的工作量
| 特征 | 迁移复杂性 |
|---|---|
| HTML 至 PDF | 极低 |
| URL 至 PDF | 极低 |
| HTML 至图像 | low |
| 页面大小/页边距 | low |
| 回调处理程序 | low |
| 水印 | low |
| 页眉/页脚 | 语言 |
| 验证密钥 | 极低 |
范式转换
GrabzIt此次迁移的根本转变在于从异步回调式云处理转向同步进程内生成:
GrabzIt: 发送 HTML → 等待回调 → 从服务器检索结果
IronPDF: 渲染 HTML → 立即获取 PDF
开始之前
前提条件
- .NET 版本:IronPDF支持 .NET Framework 4.6.2+ 和 .NET Core 3.1+ / .NET 5/6/7/8/9+ 2.许可证密钥:从ironpdf.com获取您的IronPDF许可证密钥。 3.规划基础设施移除:记录用于退役的回调处理程序和 webhook 端点
识别所有GrabzIt使用情况
# FindGrabzItclient usage
grep -r "GrabzItClient\|GrabzIt\." --include="*.cs" .
# Find callback handlers
grep -r "GrabzIt\|grabzit" --include="*.ashx" --include="*.aspx" --include="*.cs" .
# Find configuration
grep -r "APPLICATION_KEY\|APPLICATION_SECRET\|grabzit" --include="*.config" --include="*.json" .
# FindGrabzItclient usage
grep -r "GrabzItClient\|GrabzIt\." --include="*.cs" .
# Find callback handlers
grep -r "GrabzIt\|grabzit" --include="*.ashx" --include="*.aspx" --include="*.cs" .
# Find configuration
grep -r "APPLICATION_KEY\|APPLICATION_SECRET\|grabzit" --include="*.config" --include="*.json" .
NuGet 软件包变更
# Remove GrabzIt
dotnet remove package GrabzIt
# Install IronPDF
dotnet add package IronPdf
# Remove GrabzIt
dotnet remove package GrabzIt
# Install IronPDF
dotnet add package IronPdf
快速启动迁移
步骤 1:更新许可配置
之前 (GrabzIt):
GrabzIt 的每个客户端实例化都需要应用密钥和秘密:
var grabzIt = new GrabzItClient("YOUR_APPLICATION_KEY", "YOUR_APPLICATION_SECRET");
var grabzIt = new GrabzItClient("YOUR_APPLICATION_KEY", "YOUR_APPLICATION_SECRET");
Dim grabzIt As New GrabzItClient("YOUR_APPLICATION_KEY", "YOUR_APPLICATION_SECRET")
After (IronPDF):
// Set once at application startup
IronPdf.License.LicenseKey = "YOUR-IRONPDF-LICENSE-KEY";
// Then create renderer without credentials
var renderer = new ChromePdfRenderer();
// Set once at application startup
IronPdf.License.LicenseKey = "YOUR-IRONPDF-LICENSE-KEY";
// Then create renderer without credentials
var renderer = new ChromePdfRenderer();
' Set once at application startup
IronPdf.License.LicenseKey = "YOUR-IRONPDF-LICENSE-KEY"
' Then create renderer without credentials
Dim renderer As New ChromePdfRenderer()
步骤 2:更新名称空间导入
// Before (GrabzIt)
using GrabzIt;
using GrabzIt.Parameters;
// After (IronPDF)
using IronPdf;
// Before (GrabzIt)
using GrabzIt;
using GrabzIt.Parameters;
// After (IronPDF)
using IronPdf;
Imports IronPdf
完整的 API 参考
GrabzItClient 到IronPDF的映射
| GrabzIt 方法 | IronPDF 同等产品 |
|---|---|
new GrabzItClient(key, secret) |
new ChromePdfRenderer() |
HTMLToPDF(html) |
renderer.RenderHtmlAsPdf(html) |
URLToPDF(url) |
renderer.RenderUrlAsPdf(url) |
HTMLToImage(html) |
pdf.ToBitmap() |
Save(callbackUrl) |
pdf.SaveAs(path) |
SaveTo(filePath) |
pdf.SaveAs(filePath) |
GetResult(id) |
不适用 |
GetStatus(id) |
不适用 |
PDFOptions 到 RenderingOptions 映射
| GrabzIt PDF 选项 | IronPDF 属性 |
|---|---|
PageSize (A4,Letter) |
RenderingOptions.PaperSize |
CustomId |
不适用 |
MarginTop |
RenderingOptions.MarginTop |
MarginBottom |
RenderingOptions.MarginBottom |
ImageOptions 到IronPDF的映射
| GrabzIt 图像选项 | IronPDF 同等产品 |
|---|---|
Format (png, jpg) |
bitmap.Save(path, ImageFormat.Png) |
Width |
RenderingOptions.ViewPortWidth |
Height |
RenderingOptions.ViewPortHeight |
代码迁移示例
示例 1:HTML 到 PDF 的转换
之前 (GrabzIt):
// NuGet: Install-Package GrabzIt
using GrabzIt;
using GrabzIt.Parameters;
using System;
class Program
{
static void Main()
{
var grabzIt = new GrabzItClient("YOUR_APPLICATION_KEY", "YOUR_APPLICATION_SECRET");
var options = new PDFOptions();
options.CustomId = "my-pdf";
grabzIt.HTMLToPDF("<html><body><h1>Hello World</h1></body></html>", options);
grabzIt.SaveTo("output.pdf");
}
}
// NuGet: Install-Package GrabzIt
using GrabzIt;
using GrabzIt.Parameters;
using System;
class Program
{
static void Main()
{
var grabzIt = new GrabzItClient("YOUR_APPLICATION_KEY", "YOUR_APPLICATION_SECRET");
var options = new PDFOptions();
options.CustomId = "my-pdf";
grabzIt.HTMLToPDF("<html><body><h1>Hello World</h1></body></html>", options);
grabzIt.SaveTo("output.pdf");
}
}
Imports GrabzIt
Imports GrabzIt.Parameters
Imports System
Module Program
Sub Main()
Dim grabzIt As New GrabzItClient("YOUR_APPLICATION_KEY", "YOUR_APPLICATION_SECRET")
Dim options As New PDFOptions()
options.CustomId = "my-pdf"
grabzIt.HTMLToPDF("<html><body><h1>Hello World</h1></body></html>", options)
grabzIt.SaveTo("output.pdf")
End Sub
End Module
After (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<html><body><h1>Hello World</h1></body></html>");
pdf.SaveAs("output.pdf");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<html><body><h1>Hello World</h1></body></html>");
pdf.SaveAs("output.pdf");
}
}
Imports IronPdf
Imports System
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<html><body><h1>Hello World</h1></body></html>")
pdf.SaveAs("output.pdf")
End Sub
End Class
区别很大:GrabzIt 需要 API 凭证(YOUR_APPLICATION_KEY,YOUR_APPLICATION_SECRET),创建一个带有自定义 ID 的 PDFOptions 对象,结果是通过外部服务器发送的基于图像的 PDF。IronPDF的 ChromePdfRenderer 可在本地生成真正的矢量 PDF,并可选择文本——无需凭据、无需网络调用、无需回调。 有关其他渲染选项,请参阅 HTML to PDF 文档。
示例 2:URL 到 PDF 的转换
之前 (GrabzIt):
// NuGet: Install-Package GrabzIt
using GrabzIt;
using GrabzIt.Parameters;
using System;
class Program
{
static void Main()
{
var grabzIt = new GrabzItClient("YOUR_APPLICATION_KEY", "YOUR_APPLICATION_SECRET");
var options = new PDFOptions();
options.PageSize = PageSize.A4;
grabzIt.URLToPDF("https://www.example.com", options);
grabzIt.SaveTo("webpage.pdf");
}
}
// NuGet: Install-Package GrabzIt
using GrabzIt;
using GrabzIt.Parameters;
using System;
class Program
{
static void Main()
{
var grabzIt = new GrabzItClient("YOUR_APPLICATION_KEY", "YOUR_APPLICATION_SECRET");
var options = new PDFOptions();
options.PageSize = PageSize.A4;
grabzIt.URLToPDF("https://www.example.com", options);
grabzIt.SaveTo("webpage.pdf");
}
}
Imports GrabzIt
Imports GrabzIt.Parameters
Imports System
Module Program
Sub Main()
Dim grabzIt As New GrabzItClient("YOUR_APPLICATION_KEY", "YOUR_APPLICATION_SECRET")
Dim options As New PDFOptions()
options.PageSize = PageSize.A4
grabzIt.URLToPDF("https://www.example.com", options)
grabzIt.SaveTo("webpage.pdf")
End Sub
End Module
After (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderUrlAsPdf("https://www.example.com");
pdf.SaveAs("webpage.pdf");
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderUrlAsPdf("https://www.example.com");
pdf.SaveAs("webpage.pdf");
}
}
Imports IronPdf
Imports System
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderUrlAsPdf("https://www.example.com")
pdf.SaveAs("webpage.pdf")
End Sub
End Class
GrabzIt 需要通过选项对象配置 PageSize.A4 并与外部服务器进行身份验证。IronPDF的 RenderUrlAsPdf() 方法直接接受 URL,并使用完整的 Chromium 引擎在本地进行渲染,并完全支持 CSS 和 JavaScript。 了解有关 URL 至 PDF 转换的更多信息。
示例 3:HTML 到图像的转换
之前 (GrabzIt):
// NuGet: Install-Package GrabzIt
using GrabzIt;
using GrabzIt.Parameters;
using System;
class Program
{
static void Main()
{
var grabzIt = new GrabzItClient("YOUR_APPLICATION_KEY", "YOUR_APPLICATION_SECRET");
var options = new ImageOptions();
options.Format = ImageFormat.png;
options.Width = 800;
options.Height = 600;
grabzIt.HTMLToImage("<html><body><h1>Hello World</h1></body></html>", options);
grabzIt.SaveTo("output.png");
}
}
// NuGet: Install-Package GrabzIt
using GrabzIt;
using GrabzIt.Parameters;
using System;
class Program
{
static void Main()
{
var grabzIt = new GrabzItClient("YOUR_APPLICATION_KEY", "YOUR_APPLICATION_SECRET");
var options = new ImageOptions();
options.Format = ImageFormat.png;
options.Width = 800;
options.Height = 600;
grabzIt.HTMLToImage("<html><body><h1>Hello World</h1></body></html>", options);
grabzIt.SaveTo("output.png");
}
}
Imports GrabzIt
Imports GrabzIt.Parameters
Imports System
Module Program
Sub Main()
Dim grabzIt As New GrabzItClient("YOUR_APPLICATION_KEY", "YOUR_APPLICATION_SECRET")
Dim options As New ImageOptions()
options.Format = ImageFormat.png
options.Width = 800
options.Height = 600
grabzIt.HTMLToImage("<html><body><h1>Hello World</h1></body></html>", options)
grabzIt.SaveTo("output.png")
End Sub
End Module
After (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Drawing;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<html><body><h1>Hello World</h1></body></html>");
var images = pdf.ToBitmap();
images[0].Save("output.png", System.Drawing.Imaging.ImageFormat.Png);
}
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Drawing;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<html><body><h1>Hello World</h1></body></html>");
var images = pdf.ToBitmap();
images[0].Save("output.png", System.Drawing.Imaging.ImageFormat.Png);
}
}
Imports IronPdf
Imports System
Imports System.Drawing
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf("<html><body><h1>Hello World</h1></body></html>")
Dim images = pdf.ToBitmap()
images(0).Save("output.png", System.Drawing.Imaging.ImageFormat.Png)
End Sub
End Class
GrabzIt 提供了一个专用的 HTMLToImage() 方法,用于配置格式、宽度和高度。IronPDF首先使用 RenderHtmlAsPdf() 将 HTML 渲染为 PDF,然后使用 ToBitmap() 转换为位图,从而达到相同的效果。 这种方法只需一次渲染操作,即可获得 PDF 和图像输出。
关键迁移说明
无需回调
最重要的架构变化是完全取消了回调处理程序:
// GrabzIt: Async callback pattern
grabzIt.HTMLToPDF(html, options);
grabzIt.Save("https://myserver.com/grabzit-callback"); // Wait for callback...
// Callback handler (separate endpoint)
public class GrabzItHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string id = context.Request.QueryString["id"];
GrabzItClient grabzIt = new GrabzItClient("APP_KEY", "APP_SECRET");
GrabzItFile file = grabzIt.GetResult(id);
file.Save("output.pdf");
}
}
// IronPDF: Synchronous - result immediately available
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf"); // Done! 否 callback needed.
// GrabzIt: Async callback pattern
grabzIt.HTMLToPDF(html, options);
grabzIt.Save("https://myserver.com/grabzit-callback"); // Wait for callback...
// Callback handler (separate endpoint)
public class GrabzItHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string id = context.Request.QueryString["id"];
GrabzItClient grabzIt = new GrabzItClient("APP_KEY", "APP_SECRET");
GrabzItFile file = grabzIt.GetResult(id);
file.Save("output.pdf");
}
}
// IronPDF: Synchronous - result immediately available
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf"); // Done! 否 callback needed.
Imports System.Web
' GrabzIt: Async callback pattern
grabzIt.HTMLToPDF(html, options)
grabzIt.Save("https://myserver.com/grabzit-callback") ' Wait for callback...
' Callback handler (separate endpoint)
Public Class GrabzItHandler
Implements IHttpHandler
Public Sub ProcessRequest(context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim id As String = context.Request.QueryString("id")
Dim grabzIt As New GrabzItClient("APP_KEY", "APP_SECRET")
Dim file As GrabzItFile = grabzIt.GetResult(id)
file.Save("output.pdf")
End Sub
Public ReadOnly Property IsReusable As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
' IronPDF: Synchronous - result immediately available
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf") ' Done! No callback needed.
迁移后删除所有GrabzIt回调处理程序(.ashx 文件、处理程序端点、webhook 配置)。
真正的矢量 PDF 文件
GrabzIt 可创建基于图像的 PDF,其中文本不可选。IronPDF可生成真正的矢量 PDF:
// With IronPDF, text extraction works natively
var pdf = PdfDocument.FromFile("document.pdf");
string text = pdf.ExtractAllText(); // Works without OCR!
// With IronPDF, text extraction works natively
var pdf = PdfDocument.FromFile("document.pdf");
string text = pdf.ExtractAllText(); // Works without OCR!
Imports IronPdf
' With IronPDF, text extraction works natively
Dim pdf = PdfDocument.FromFile("document.pdf")
Dim text As String = pdf.ExtractAllText() ' Works without OCR!
有关详细信息,请参阅 文本提取文档。
更小的文件大小
基于矢量的 PDF 通常比GrabzIt基于图像的 PDF 小 5-10 倍。 这样可以提高存储成本、下载时间和电子邮件附件的可行性。
删除 API 证书
GrabzIt 的每项操作都需要 API 凭据:
// Remove these from configuration
// YOUR_APPLICATION_KEY
// YOUR_APPLICATION_SECRET
// Remove these from configuration
// YOUR_APPLICATION_KEY
// YOUR_APPLICATION_SECRET
IronPDF 使用在应用程序启动时设置一次的单一许可证密钥--无需每次请求验证。
故障排除
问题 1:GrabzItClient 未找到
问题:移除GrabzIt后,GrabzItClient 引用导致编译错误。
解决方案:替换为 ChromePdfRenderer:
// Remove:
// var grabzIt = new GrabzItClient("KEY", "SECRET");
// Replace with:
var renderer = new ChromePdfRenderer();
// Remove:
// var grabzIt = new GrabzItClient("KEY", "SECRET");
// Replace with:
var renderer = new ChromePdfRenderer();
' Remove:
' Dim grabzIt = New GrabzItClient("KEY", "SECRET")
' Replace with:
Dim renderer = New ChromePdfRenderer()
问题 2:未找到 PDF 选项
问题:IronPDF中不存在 PDFOptions 类。
解决方案:使用 RenderingOptions 属性:
// GrabzIt
var options = new PDFOptions();
options.PageSize = PageSize.A4;
// IronPDF
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;
// GrabzIt
var options = new PDFOptions();
options.PageSize = PageSize.A4;
// IronPDF
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;
' GrabzIt
Dim options As New PDFOptions()
options.PageSize = PageSize.A4
' IronPDF
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4
问题 3:回调处理程序仍被引用
问题:应用程序需要回调端点。
解决方案:彻底删除回调机制。IronPDF同步返回结果--无需网络钩子。
问题 4:未找到 ImageOptions
问题:IronPDF中不存在 ImageOptions 类。
解决方案:先渲染成 PDF,然后再转换:
// GrabzIt
var options = new ImageOptions();
options.Format = ImageFormat.png;
grabzIt.HTMLToImage(html, options);
// IronPDF
var pdf = renderer.RenderHtmlAsPdf(html);
var images = pdf.ToBitmap();
images[0].Save("output.png", System.Drawing.Imaging.ImageFormat.Png);
// GrabzIt
var options = new ImageOptions();
options.Format = ImageFormat.png;
grabzIt.HTMLToImage(html, options);
// IronPDF
var pdf = renderer.RenderHtmlAsPdf(html);
var images = pdf.ToBitmap();
images[0].Save("output.png", System.Drawing.Imaging.ImageFormat.Png);
' GrabzIt
Dim options As New ImageOptions()
options.Format = ImageFormat.png
grabzIt.HTMLToImage(html, options)
' IronPDF
Dim pdf = renderer.RenderHtmlAsPdf(html)
Dim images = pdf.ToBitmap()
images(0).Save("output.png", System.Drawing.Imaging.ImageFormat.Png)
迁移清单
迁移前
- 清点代码库中所有GrabzItAPI 调用
- 确定回调处理程序和 webhook 端点
- 记录GrabzIt当前的选项和模板
- 获取IronPDF许可证密钥
- 计划回调处理程序停用
代码迁移
- 安装 IronPdf NuGet 包:
dotnet add package IronPdf - 移除GrabzItNuGet 包:
dotnet remove package GrabzIt - 将
GrabzItClient替换为ChromePdfRenderer - 将
HTMLToPDF()转换为RenderHtmlAsPdf() - 将
URLToPDF()转换为RenderUrlAsPdf() - 将
Save(callback)替换为SaveAs(path) - 将选项从
PDFOptions更新为RenderingOptions
基础架构迁移
- 删除回调处理程序文件(
.ashx等) - 从配置中移除GrabzItAPI 密钥
- 移除 webhook URL 配置
- 将IronPDF许可证密钥添加到配置中
- 移除轮询/状态检查代码
测试
- 测试 HTML 到 PDF 的转换
- 测试 URL 到 PDF 的转换
- 确认输出的PDF文件中文本可选择。
- 测试文本提取功能(不使用 OCR)
- 确认文件大小较小
- 无网络延迟的性能测试
后迁移
取消GrabzIt订阅
- 归档回调处理程序代码
- 更新文档
- 监控任何与GrabzIt相关的错误

