从 Foxit PDF SDK 迁移到 IronPdf:(.NET指南)
从福昕 PDF SDK 迁移到 IronPDF:完整的 C# 迁移指南
从福昕 PDF SDK迁移到 IronPDF,用现代的、开发者友好的模式取代复杂的、以企业为中心的 API,从而简化您的 .NET PDF 生成工作流程。 本指南提供了一个全面、逐步的迁移路径,可消除模板代码并简化整个代码库中的 PDF 操作。
为什么要从福昕 PDF SDK 迁移到 IronPDF.
福昕 PDF 的挑战
福昕 PDF SDK 是一个功能强大的企业级库,但其复杂性可能会拖慢开发速度:
1.复杂的许可系统:多种产品、SKU 和许可类型(按开发人员、按服务器、OEM 等)使您很难为项目选择正确的选项。
2.企业定价:定价是为大型企业量身定制的,对于较小的团队或个人开发人员来说可能会过于昂贵。
3.手动安装:Foxit PDF SDK 需要手动引用 DLL 或私有 NuGet feeds - 没有简单的公共 NuGet 包可用。
4.Verbose API:使用 Library.Initialize() 进行库初始化、错误代码检查和显式 Library.Release() 调用为每个操作添加了大量的模板。
5.单独的 HTML 转换附加组件:HTML 到 PDF 的转换需要额外购买附加组件,它不包含在基本 SDK 中。
6.复杂配置:设置需要包含多个属性的详细对象配置(例如,HTML2PDFSettingData)。
7.C++ 传统:API 模式反映了 C++ 的起源,在现代 C# 应用程序中感觉不太自然。
福昕 PDF 与IronPDF对比
| 方面 | 福昕 PDF SDK | IronPDF |
|---|---|---|
| 安装 | 手动动态链接库/私有源代码 | 简单的 NuGet 软件包 |
| 许可 | 复杂、以企业为重点 | 透明,适合各种尺寸 |
| 初始化 | <代码>Library.Initialize(sn,key)</代码 | 设置一次许可证密钥 |
| 错误处理 | ErrorCode 枚举 | .NET 标准例外情况 |
| HTML 至 PDF | 单独购买附加组件 | 内置 Chromium 引擎 |
| API 风格 | C++ 遗产,冗长 | 现代 .NET 模式 |
| 资源清理 | 手册 Close()/Release() | IDisposable/automatic |
| 文档 | 企业文档门户 | 公共教程 |
成本效益分析
从 Foxit PDF 迁移到IronPDF可带来切实的开发优势:通过更简单的 API 降低复杂性、通过直观的方法加快开发速度、现代 .NET 兼容性(包括 async/await 和 LINQ 支持)、可利用现有网络技能的 HTML 优先方法以及无需单独购买附加组件的全包功能。 当您计划在 2025 年和 2026 年采用 .NET 10 和 C# 14 时,IronPDF 为 PDF 生成提供了一个面向未来的基础。
开始之前
前提条件
1..NET环境:IronPDF支持.NET Framework 4.6.2+、.NET Core 3.1+、.NET 5/6/7/8/9+。 2.NuGet访问:确保您可以从 NuGet 安装软件包 3.许可证密钥:从ironpdf.com获取用于生产的IronPDF许可证密钥。
备份您的项目
# Create a backup branch
git checkout -b pre-ironpdf-migration
git add .
git commit -m "Backup before福昕 PDF SDKtoIronPDFmigration"# Create a backup branch
git checkout -b pre-ironpdf-migration
git add .
git commit -m "Backup before福昕 PDF SDKtoIronPDFmigration"识别所有福昕 PDF 使用情况
# Find all福昕 PDF SDKreferences
grep -r "foxit\|PDFDoc\|PDFPage\|Library.Initialize\|Library.Release" --include="*.cs" --include="*.csproj" .
# Find Foxit DLL references
find . -name "*.csproj" | xargs grep -l "Foxit\|fsdk"# Find all福昕 PDF SDKreferences
grep -r "foxit\|PDFDoc\|PDFPage\|Library.Initialize\|Library.Release" --include="*.cs" --include="*.csproj" .
# Find Foxit DLL references
find . -name "*.csproj" | xargs grep -l "Foxit\|fsdk"文档当前功能
在迁移之前,编目:
- 您使用的福昕 PDF 功能(HTML 转换、注释、表单、安全性)
- 许可证密钥位置和初始化代码
- 自定义配置和设置
- 使用 ErrorCode 枚举的错误处理模式
快速启动迁移
步骤 1:更新 NuGet 软件包
#福昕 PDF SDKtypically requires manual removal of DLL references
# Check your .csproj for Foxit references and remove them
# Install IronPDF
dotnet add package IronPdf#福昕 PDF SDKtypically requires manual removal of DLL references
# Check your .csproj for Foxit references and remove them
# Install IronPDF
dotnet add package IronPdf如果您在 .csproj 中有福昕 PDF 引用,请手动将其删除:
<!-- Remove these manually -->
<Reference Include="fsdk_dotnet">
<HintPath>..\libs\Foxit\fsdk_dotnet.dll</HintPath>
</Reference><!-- Remove these manually -->
<Reference Include="fsdk_dotnet">
<HintPath>..\libs\Foxit\fsdk_dotnet.dll</HintPath>
</Reference>步骤 2:更新命名空间
// Before (Foxit PDF)
using foxit;
using foxit.common;
using foxit.common.fxcrt;
using foxit.pdf;
using foxit.pdf.annots;
using foxit.addon.conversion;
// After (IronPDF)
using IronPdf;
using IronPdf.Rendering;
using IronPdf.Editing;// Before (Foxit PDF)
using foxit;
using foxit.common;
using foxit.common.fxcrt;
using foxit.pdf;
using foxit.pdf.annots;
using foxit.addon.conversion;
// After (IronPDF)
using IronPdf;
using IronPdf.Rendering;
using IronPdf.Editing;IRON VB CONVERTER ERROR developers@ironsoftware.com第 3 步:初始化 IronPDF.
此次福昕 PDF 迁移中最重要的改进之一是消除了复杂的初始化和清理模式:
// Before (Foxit PDF)
string sn = "YOUR_SERIAL_NUMBER";
string key = "YOUR_LICENSE_KEY";
ErrorCode error_code = Library.Initialize(sn, key);
if (error_code != ErrorCode.e_ErrSuccess)
{
throw new Exception("Failed to initialize Foxit PDF SDK");
}
// ... your code ...
Library.Release(); // Don't forget this!
// After (IronPDF)
IronPdf.License.LicenseKey = "YOUR-IRONPDF-LICENSE-KEY";
// That's it! No Release() needed// Before (Foxit PDF)
string sn = "YOUR_SERIAL_NUMBER";
string key = "YOUR_LICENSE_KEY";
ErrorCode error_code = Library.Initialize(sn, key);
if (error_code != ErrorCode.e_ErrSuccess)
{
throw new Exception("Failed to initialize Foxit PDF SDK");
}
// ... your code ...
Library.Release(); // Don't forget this!
// After (IronPDF)
IronPdf.License.LicenseKey = "YOUR-IRONPDF-LICENSE-KEY";
// That's it! No Release() neededIRON VB CONVERTER ERROR developers@ironsoftware.com步骤 4:基本转换模式
// Before (Foxit PDF)
Library.Initialize(sn, key);
HTML2PDFSettingData settings = new HTML2PDFSettingData();
settings.page_width = 612.0f;
settings.page_height = 792.0f;
using (HTML2PDF html2pdf = new HTML2PDF(settings))
{
html2pdf.Convert(htmlContent, "output.pdf");
}
Library.Release();
// After (IronPDF)
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("output.pdf");// Before (Foxit PDF)
Library.Initialize(sn, key);
HTML2PDFSettingData settings = new HTML2PDFSettingData();
settings.page_width = 612.0f;
settings.page_height = 792.0f;
using (HTML2PDF html2pdf = new HTML2PDF(settings))
{
html2pdf.Convert(htmlContent, "output.pdf");
}
Library.Release();
// After (IronPDF)
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("output.pdf");IRON VB CONVERTER ERROR developers@ironsoftware.com完整的 API 参考
命名空间映射
| 福昕 PDF 命名空间 | IronPdf 同等产品 | 备注 |
|---|---|---|
| <代码>foxit</代码 | <代码>IronPdf</代码 | 主命名空间 |
| <代码>foxit.common</代码 | <代码>IronPdf</代码 | 常见类型 |
| <代码>foxit.common.fxcrt</代码 | 不适用 | 低级(不需要) |
| <代码>foxit.pdf</代码 | <代码>IronPdf</代码 | PDF 文档操作 |
| <代码>foxit.pdf.annots</代码 | <代码>IronPdf.编辑</代码 | 注释 |
| <代码>foxit.addon.conversion</代码 | <代码>IronPdf.Rendering</代码 | HTML/ 图片转换 |
核心类映射
| 福昕 PDF SDK 类 | IronPdf 同等产品 | 备注 |
|---|---|---|
| <代码>库</代码 | 不适用 | IronPdf 自动管理 |
| <代码>PDFDoc</代码 | <代码>PDF 文档</代码 | 主要文件类型 |
| <代码>PDF 页</代码 | <代码>PdfDocument.Pages[i]</代码 | 页面访问 |
| <代码>HTML2PDF</代码 | <代码>ChromePdfRenderer</代码 | HTML 转换 |
| <代码>文本页面</代码 | <代码>pdf.ExtractTextFromPage(i)</代码 | 文本提取 |
| <代码>水印</代码 | <代码>TextStamper</代码> / <代码>ImageStamper</代码 | Watermarks |
| <代码>安全性</代码 | <代码>安全设置</代码 | PDF 安全 |
| <代码>表格</代码 | <代码>pdf.Form</代码 | 表格字段 |
| <代码>元数据</代码 | <代码>pdf.MetaData</代码 | 文档元数据 |
PDFDoc 方法
| 福昕 PDFDoc | IronPDF PDFDocument | 备注 |
|---|---|---|
| <代码>new PDFDoc(path)</ 代码 | <代码>PdfDocument.FromFile(路径)</代码 | 从文件加载 |
| <代码>doc.LoadW(password)</代码 | <代码>PdfDocument.FromFile(路径, 密码)</代码 | 密码保护 |
| <代码>doc.GetPageCount()</代码 | <代码>pdf.PageCount</代码 | 页数属性 |
| <代码>doc.GetPage(index)</代码 | <代码>pdf.Pages[index]</代码 | 按索引获取页面 |
| <代码>doc.SaveAs(路径, 标志)</代码 | <代码>pdf.SaveAs(路径)</代码 | 保存文档 |
| <代码>doc.Close()</代码 | pdf.Dispose() 或 using 语句 | 清理 |
| <代码>doc.InsertDocument()</代码 | <代码>PdfDocument.Merge()</代码 | 合并文档 |
HTML2PDF/转换
| 福昕 HTML2PDF | IronPdf 同等产品 | 备注 |
|---|---|---|
| <代码>new HTML2PDFSettingData()</ 代码 | <代码>new ChromePdfRenderer()</ 代码 | 创建呈现器 |
| <代码>settings.page_width</代码 | <代码>RenderingOptions.PaperSize</代码 | 标准尺寸 |
| <代码>settings.page_height</代码 | <代码>RenderingOptions.SetCustomPaperSize()</代码 | 定制尺寸 |
| <代码>html2pdf.Convert(html, 路径)</代码 | <代码>renderer.RenderHtmlAsPdf(html)</代码 | HTML 字符串 |
| <代码>html2pdf.ConvertFromURL(url, path)</ 代码 | <代码>renderer.RenderUrlAsPdf(url)</代码 | URL 转换。 |
水印设置
| 福昕水印 | IronPdf 同等产品 | 备注 |
|---|---|---|
new Watermark(doc、文本、字体、大小、颜色) | <代码>new TextStamper()</ 代码 | 文本水印 |
| <代码>WatermarkSettings.position</代码 | <代码>VerticalAlignment</代码> + <代码>HorizontalAlignment</代码 | 职位 |
| <代码>WatermarkSettings.rotation</代码 | <代码>旋转</代码 | 旋转角度 |
| <代码>WatermarkSettings.opacity</代码 | <代码>容量</代码 | 0-100 百分比 |
| <代码>watermark.InsertToAllPages()</代码 | <代码>pdf.ApplyStamp(stamper)</代码 | 适用于所有 |
代码示例
示例 1:HTML 到 PDF 的转换
之前(福昕 PDF SDK):
// NuGet: Install-Package Foxit.SDK
using Foxit.SDK;
using Foxit.SDK.Common;
using Foxit.SDK.PDFConversion;
using System;
class Program
{
static void Main()
{
Library.Initialize("sn", "key");
HTML2PDFSettingData settingData = new HTML2PDFSettingData();
settingData.page_width = 612.0f;
settingData.page_height = 792.0f;
settingData.page_mode = HTML2PDFPageMode.e_HTML2PDFPageModeSinglePage;
using (HTML2PDF html2pdf = new HTML2PDF(settingData))
{
html2pdf.Convert("<html><body><h1>Hello World</h1></body></html>", "output.pdf");
}
Library.Release();
}
}// NuGet: Install-Package Foxit.SDK
using Foxit.SDK;
using Foxit.SDK.Common;
using Foxit.SDK.PDFConversion;
using System;
class Program
{
static void Main()
{
Library.Initialize("sn", "key");
HTML2PDFSettingData settingData = new HTML2PDFSettingData();
settingData.page_width = 612.0f;
settingData.page_height = 792.0f;
settingData.page_mode = HTML2PDFPageMode.e_HTML2PDFPageModeSinglePage;
using (HTML2PDF html2pdf = new HTML2PDF(settingData))
{
html2pdf.Convert("<html><body><h1>Hello World</h1></body></html>", "output.pdf");
}
Library.Release();
}
}IRON VB CONVERTER ERROR developers@ironsoftware.comAfter (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");
}
}IRON VB CONVERTER ERROR developers@ironsoftware.comIronPDF 方法将 15 行以上的配置代码减少到仅 4 行。 没有库初始化,没有显式清理,没有复杂的设置对象。 有关更多 HTML 渲染选项,请参阅 HTML to PDF 文档。
示例 2:URL 到 PDF 的转换
之前(福昕 PDF SDK):
// NuGet: Install-Package Foxit.SDK
using Foxit.SDK;
using Foxit.SDK.Common;
using Foxit.SDK.PDFConversion;
using System;
class Program
{
static void Main()
{
Library.Initialize("sn", "key");
HTML2PDFSettingData settingData = new HTML2PDFSettingData();
settingData.page_width = 612.0f;
settingData.page_height = 792.0f;
settingData.page_mode = HTML2PDFPageMode.e_HTML2PDFPageModeSinglePage;
using (HTML2PDF html2pdf = new HTML2PDF(settingData))
{
html2pdf.ConvertFromURL("https://www.example.com", "output.pdf");
}
Library.Release();
}
}// NuGet: Install-Package Foxit.SDK
using Foxit.SDK;
using Foxit.SDK.Common;
using Foxit.SDK.PDFConversion;
using System;
class Program
{
static void Main()
{
Library.Initialize("sn", "key");
HTML2PDFSettingData settingData = new HTML2PDFSettingData();
settingData.page_width = 612.0f;
settingData.page_height = 792.0f;
settingData.page_mode = HTML2PDFPageMode.e_HTML2PDFPageModeSinglePage;
using (HTML2PDF html2pdf = new HTML2PDF(settingData))
{
html2pdf.ConvertFromURL("https://www.example.com", "output.pdf");
}
Library.Release();
}
}IRON VB CONVERTER ERROR developers@ironsoftware.comAfter (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("output.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("output.pdf");
}
}IRON VB CONVERTER ERROR developers@ironsoftware.comIronPDF 内置的 Chromium 引擎可自动处理 JavaScript 执行、CSS 渲染和动态内容。 了解有关 URL 至 PDF 转换的更多信息。
示例 3:添加水印
之前(福昕 PDF SDK):
// NuGet: Install-Package Foxit.SDK
using Foxit.SDK;
using Foxit.SDK.Common;
using Foxit.SDK.PDFDoc;
using System;
class Program
{
static void Main()
{
Library.Initialize("sn", "key");
using (PDFDoc doc = new PDFDoc("input.pdf"))
{
doc.Load("");
Watermark watermark = new Watermark(doc, "Confidential",
new Font(Font.StandardID.e_StdIDHelvetica), 48.0f, 0xFF0000FF);
WatermarkSettings settings = new WatermarkSettings();
settings.flags = Watermark.e_WatermarkFlagASPageContents;
settings.position = Watermark.Position.e_PosCenter;
settings.rotation = -45.0f;
settings.opacity = 0.5f;
watermark.SetSettings(settings);
watermark.InsertToAllPages();
doc.SaveAs("output.pdf", PDFDoc.SaveFlags.e_SaveFlagNoOriginal);
}
Library.Release();
}
}// NuGet: Install-Package Foxit.SDK
using Foxit.SDK;
using Foxit.SDK.Common;
using Foxit.SDK.PDFDoc;
using System;
class Program
{
static void Main()
{
Library.Initialize("sn", "key");
using (PDFDoc doc = new PDFDoc("input.pdf"))
{
doc.Load("");
Watermark watermark = new Watermark(doc, "Confidential",
new Font(Font.StandardID.e_StdIDHelvetica), 48.0f, 0xFF0000FF);
WatermarkSettings settings = new WatermarkSettings();
settings.flags = Watermark.e_WatermarkFlagASPageContents;
settings.position = Watermark.Position.e_PosCenter;
settings.rotation = -45.0f;
settings.opacity = 0.5f;
watermark.SetSettings(settings);
watermark.InsertToAllPages();
doc.SaveAs("output.pdf", PDFDoc.SaveFlags.e_SaveFlagNoOriginal);
}
Library.Release();
}
}IRON VB CONVERTER ERROR developers@ironsoftware.comAfter (IronPDF):
// NuGet: Install-Package IronPdf
using IronPdf;
using IronPdf.Editing;
using System;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("input.pdf");
pdf.ApplyWatermark(new TextStamper()
{
Text = "Confidential",
FontSize = 48,
Opacity = 50,
Rotation = -45,
VerticalAlignment = VerticalAlignment.Middle,
HorizontalAlignment = HorizontalAlignment.Center
});
pdf.SaveAs("output.pdf");
}
}// NuGet: Install-Package IronPdf
using IronPdf;
using IronPdf.Editing;
using System;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("input.pdf");
pdf.ApplyWatermark(new TextStamper()
{
Text = "Confidential",
FontSize = 48,
Opacity = 50,
Rotation = -45,
VerticalAlignment = VerticalAlignment.Middle,
HorizontalAlignment = HorizontalAlignment.Center
});
pdf.SaveAs("output.pdf");
}
}IRON VB CONVERTER ERROR developers@ironsoftware.comIronPDF 的 TextStamper 提供基于属性的直观配置,而不是单独的设置对象和手动页面迭代。 有关其他选项,请参阅完整的 watermarking 文档。
示例 4:URL 转 PDF,带页眉和页脚
之前(福昕 PDF SDK):
using foxit;
using foxit.addon.conversion;
class Program
{
static void Main()
{
Library.Initialize("sn", "key");
try
{
HTML2PDFSettingData settings = new HTML2PDFSettingData();
settings.page_width = 595.0f; // A4
settings.page_height = 842.0f;
settings.page_margin_top = 100.0f;
settings.page_margin_bottom = 100.0f;
//福昕 PDF SDKhas limited header/footer support
// Often requires post-processing or additional code
using (HTML2PDF html2pdf = new HTML2PDF(settings))
{
html2pdf.ConvertFromURL("https://www.example.com", "webpage.pdf");
}
}
finally
{
Library.Release();
}
}
}using foxit;
using foxit.addon.conversion;
class Program
{
static void Main()
{
Library.Initialize("sn", "key");
try
{
HTML2PDFSettingData settings = new HTML2PDFSettingData();
settings.page_width = 595.0f; // A4
settings.page_height = 842.0f;
settings.page_margin_top = 100.0f;
settings.page_margin_bottom = 100.0f;
//福昕 PDF SDKhas limited header/footer support
// Often requires post-processing or additional code
using (HTML2PDF html2pdf = new HTML2PDF(settings))
{
html2pdf.ConvertFromURL("https://www.example.com", "webpage.pdf");
}
}
finally
{
Library.Release();
}
}
}IRON VB CONVERTER ERROR developers@ironsoftware.comAfter (IronPDF):
using IronPdf;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;
renderer.RenderingOptions.PrintHtmlBackgrounds = true;
renderer.RenderingOptions.WaitFor.RenderDelay(3000); // Wait for JS
// Built-in header/footer support
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
HtmlFragment = "<div style='text-align:center; font-size:12pt;'>Company Report</div>",
DrawDividerLine = true
};
renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter()
{
HtmlFragment = "<div style='text-align:right; font-size:10pt;'>Page {page} of {total-pages}</div>",
DrawDividerLine = true
};
var pdf = renderer.RenderUrlAsPdf("https://www.example.com");
pdf.SaveAs("webpage.pdf");
}
}using IronPdf;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;
renderer.RenderingOptions.PrintHtmlBackgrounds = true;
renderer.RenderingOptions.WaitFor.RenderDelay(3000); // Wait for JS
// Built-in header/footer support
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
HtmlFragment = "<div style='text-align:center; font-size:12pt;'>Company Report</div>",
DrawDividerLine = true
};
renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter()
{
HtmlFragment = "<div style='text-align:right; font-size:10pt;'>Page {page} of {total-pages}</div>",
DrawDividerLine = true
};
var pdf = renderer.RenderUrlAsPdf("https://www.example.com");
pdf.SaveAs("webpage.pdf");
}
}IRON VB CONVERTER ERROR developers@ironsoftware.comIronPdf 提供本地页眉和页脚支持,具有 HTML 风格和动态页码占位符。
示例 5:PDF 安全性和加密
之前(福昕 PDF SDK):
using foxit;
using foxit.pdf;
class Program
{
static void Main()
{
Library.Initialize("sn", "key");
try
{
using (PDFDoc doc = new PDFDoc("input.pdf"))
{
doc.LoadW("");
StdSecurityHandler securityHandler = new StdSecurityHandler();
securityHandler.Initialize(
StdSecurityHandler.EncryptAlgorithm.e_CipherAES,
"user_password",
"owner_password",
PDFDoc.Permission.e_PermPrint | PDFDoc.Permission.e_PermModify,
128);
doc.SetSecurityHandler(securityHandler);
doc.SaveAs("encrypted.pdf", (int)PDFDoc.SaveFlags.e_SaveFlagNoOriginal);
}
}
finally
{
Library.Release();
}
}
}using foxit;
using foxit.pdf;
class Program
{
static void Main()
{
Library.Initialize("sn", "key");
try
{
using (PDFDoc doc = new PDFDoc("input.pdf"))
{
doc.LoadW("");
StdSecurityHandler securityHandler = new StdSecurityHandler();
securityHandler.Initialize(
StdSecurityHandler.EncryptAlgorithm.e_CipherAES,
"user_password",
"owner_password",
PDFDoc.Permission.e_PermPrint | PDFDoc.Permission.e_PermModify,
128);
doc.SetSecurityHandler(securityHandler);
doc.SaveAs("encrypted.pdf", (int)PDFDoc.SaveFlags.e_SaveFlagNoOriginal);
}
}
finally
{
Library.Release();
}
}
}IRON VB CONVERTER ERROR developers@ironsoftware.comAfter (IronPDF):
using IronPdf;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("input.pdf");
// Set passwords
pdf.SecuritySettings.OwnerPassword = "owner_password";
pdf.SecuritySettings.UserPassword = "user_password";
// Set permissions
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;
pdf.SecuritySettings.AllowUserEdits = IronPdf.Security.PdfEditSecurity.EditAll;
pdf.SecuritySettings.AllowUserCopyPasteContent = true;
pdf.SecuritySettings.AllowUserAnnotations = true;
pdf.SaveAs("encrypted.pdf");
}
}using IronPdf;
class Program
{
static void Main()
{
var pdf = PdfDocument.FromFile("input.pdf");
// Set passwords
pdf.SecuritySettings.OwnerPassword = "owner_password";
pdf.SecuritySettings.UserPassword = "user_password";
// Set permissions
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;
pdf.SecuritySettings.AllowUserEdits = IronPdf.Security.PdfEditSecurity.EditAll;
pdf.SecuritySettings.AllowUserCopyPasteContent = true;
pdf.SecuritySettings.AllowUserAnnotations = true;
pdf.SaveAs("encrypted.pdf");
}
}IRON VB CONVERTER ERROR developers@ironsoftware.com性能考虑
重用 ChromePdfRenderer。
为了在福昕 PDF 迁移过程中获得最佳性能,请重复使用<代码>ChromePdfRenderer</代码实例--它是线程安全的:
// GOOD - Reuse renderer (thread-safe)
public class PdfService
{
private static readonly ChromePdfRenderer _renderer = new ChromePdfRenderer();
public byte[] Generate(string html) => _renderer.RenderHtmlAsPdf(html).BinaryData;
}
// BAD - Creates new instance each time
public byte[] GenerateBad(string html)
{
var renderer = new ChromePdfRenderer(); // Wasteful
return renderer.RenderHtmlAsPdf(html).BinaryData;
}// GOOD - Reuse renderer (thread-safe)
public class PdfService
{
private static readonly ChromePdfRenderer _renderer = new ChromePdfRenderer();
public byte[] Generate(string html) => _renderer.RenderHtmlAsPdf(html).BinaryData;
}
// BAD - Creates new instance each time
public byte[] GenerateBad(string html)
{
var renderer = new ChromePdfRenderer(); // Wasteful
return renderer.RenderHtmlAsPdf(html).BinaryData;
}IRON VB CONVERTER ERROR developers@ironsoftware.com单元转换助手
Foxit PDF SDK 使用点; IronPdf 使用毫米。 在迁移过程中使用此辅助工具:
public static class UnitConverter
{
public static double PointsToMm(double points) => points * 0.352778;
public static double MmToPoints(double mm) => mm / 0.352778;
public static double InchesToMm(double inches) => inches * 25.4;
}
// Usage: Convert Foxit's 72 points (1 inch) toIronPDFmillimeters
renderer.RenderingOptions.MarginTop = UnitConverter.PointsToMm(72); // ~25.4mmpublic static class UnitConverter
{
public static double PointsToMm(double points) => points * 0.352778;
public static double MmToPoints(double mm) => mm / 0.352778;
public static double InchesToMm(double inches) => inches * 25.4;
}
// Usage: Convert Foxit's 72 points (1 inch) toIronPDFmillimeters
renderer.RenderingOptions.MarginTop = UnitConverter.PointsToMm(72); // ~25.4mmIRON VB CONVERTER ERROR developers@ironsoftware.com正确的资源处置
// GOOD - Using statement for automatic cleanup
using (var pdf = PdfDocument.FromFile("large.pdf"))
{
string text = pdf.ExtractAllText();
} // pdf is disposed automatically// GOOD - Using statement for automatic cleanup
using (var pdf = PdfDocument.FromFile("large.pdf"))
{
string text = pdf.ExtractAllText();
} // pdf is disposed automaticallyIRON VB CONVERTER ERROR developers@ironsoftware.com故障排除
问题 1:Library.Initialize() 未找到
问题:Library.Initialize() 在IronPDF中不存在。
解决方案:IronPDF 使用更简单的初始化模式:
// Foxit PDF
Library.Initialize(sn, key);
//IronPDF- just set license key once at startup
IronPdf.License.LicenseKey = "YOUR-KEY";// Foxit PDF
Library.Initialize(sn, key);
//IronPDF- just set license key once at startup
IronPdf.License.LicenseKey = "YOUR-KEY";IRON VB CONVERTER ERROR developers@ironsoftware.com问题 2:错误代码处理
问题:代码检查 ErrorCode.e_ErrSuccess 但IronPDF没有这个功能。
解决方案:使用标准的 .NET 异常处理:
// Foxit PDF
ErrorCode err = doc.LoadW("");
if (err != ErrorCode.e_ErrSuccess) { /* handle error */ }
// IronPDF
try
{
var pdf = PdfDocument.FromFile("input.pdf");
}
catch (IOException ex)
{
Console.WriteLine($"Failed to load PDF: {ex.Message}");
}// Foxit PDF
ErrorCode err = doc.LoadW("");
if (err != ErrorCode.e_ErrSuccess) { /* handle error */ }
// IronPDF
try
{
var pdf = PdfDocument.FromFile("input.pdf");
}
catch (IOException ex)
{
Console.WriteLine($"Failed to load PDF: {ex.Message}");
}IRON VB CONVERTER ERROR developers@ironsoftware.com问题 3:PDFDoc.Close() 未找到
问题:doc.Close() 方法在IronPDF中不存在。
解决方案:使用 Dispose() 或 using 语句:
// Foxit PDF
doc.Close();
// IronPDF
pdf.Dispose();
// or better: wrap in using statement// Foxit PDF
doc.Close();
// IronPDF
pdf.Dispose();
// or better: wrap in using statementIRON VB CONVERTER ERROR developers@ironsoftware.com迁移清单
迁移前
- [ ] 列出使用的所有福昕 PDF SDK 功能
- [文档许可证密钥位置
- [ ] 注意所有
Library.Initialize()和Library.Release()调用 - [ ] 列出自定义设置(页面尺寸、页边距等)
- [ ] 使用 ErrorCode 识别错误处理模式
- [将项目备份到版本控制中
- [ ] 获取 IronPdf 许可证密钥
软件包迁移
- [ ] 从 .csproj 中移除福昕 PDF SDKDLL 引用
- [ ] 删除任何私有 NuGet feed 配置
- [ ] 安装 IronPdf NuGet 软件包:<代码>dotnet 添加软件包 IronPdf</ 代码
- [更新命名空间导入
- [ ] 在启动时设置 IronPdf 许可证密钥
代码迁移
- [ ] 删除
Library.Initialize()和Library.Release()调用 - [ ] 将
ErrorCode检查替换为 try/catch - [ ] 将<代码>PDFDoc</代码替换为
PdfDocument - [ ] 将<代码>HTML2PDF</代码替换为
ChromePdfRenderer - [ ] 将页面访问从
GetPage(i)更新为Pages[i] - [ ] 将
SaveAs(path, flags)替换为SaveAs(path) - [ ] 将
Close()替换为Dispose()或 using 语句 - [更新水印代码以使用
TextStamper - [ ] 将单位从点转换为毫米
测试
- [ ] 验证 HTML 到 PDF 的输出是否符合预期
- [ ] 测试 PDF 加载和文本提取
- [ ] 验证合并功能
- [ ] 检查水印外观
- [ ] 测试安全/加密功能
- [ ] 验证表单字段操作
- [ ] 性能测试
后迁移
- [ ] 删除福昕 PDF SDK动态链接库
- [ ] 删除与福昕软件相关的配置文件
- [ ] 更新文档
- [ ] 清理未使用的辅助代码
结论
从福昕 PDF SDK迁移到IronPDF可以消除复杂的初始化模式、冗长的配置对象和手动资源清理。其结果是代码更简洁、可维护性更高,并充分利用了现代.NET模式和内置的HTML/CSS渲染功能。
IronPDF 简化的 API 可缩短开发时间,同时提供全面的 PDF 功能--所有功能均可通过一个 NuGet 包访问,无需单独购买附加组件。 对于计划迁移到 .NET 10 及更高版本的团队,IronPDF 为 PDF 生成提供了一个面向未来的基础。






