從 Foxit PDF SDK 轉移到 IronPDF:(.NET指南)
從福昕 PDF SDK轉移到 IronPDF:完整的 C# 遷移指南。
從福昕 PDF SDK轉換到 IronPDF,以現代化、開發者友好的模式取代複雜的企業級 API,從而簡化您的 .NET PDF 生成工作流程。 本指南提供了一個全面、循序漸進的轉換路徑,可消除模板程式碼,並簡化整個程式碼庫的 PDF 作業。
為什麼要從福昕 PDF SDK轉移到 IronPDF?
福昕 PDF 的挑戰
Foxit 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 |
|---|---|---|
| 安裝 | 手動 DLL/私人饋送 | 簡單的 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-first 方法(可充分利用現有的網頁技能),以及無需另外購買附加元件的全包式功能。 當您計劃在 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 中有 Foxit 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
此次 Foxit 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 同等級產品 | 筆記 |
|---|---|---|
Library | 不適用 | 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(path) | 從檔案載入 |
doc.LoadW(password) | <編碼>PdfDocument.FromFile(路徑, 密碼)</編碼 | 密碼保護 |
| <編碼>doc.GetPageCount()</編碼 | <編碼>pdf.PageCount</編碼 | 頁數屬性 |
doc.GetPage(index) | <編碼>pdf.Pages[index]</編碼 | 依索引取得頁面 |
doc.SaveAs(path, flags) | <代碼>pdf.SaveAs(路徑)</代碼 | 儲存文件 |
| <編碼>doc.Close()</編碼 | pdf.Dispose() 或 using 語句 | 清理 |
doc.InsertDocument() | <代碼>PdfDocument.Merge()</代碼 | 合併文件。 |
HTML2PDF/轉換
| 福昕 HTML2PDF | IronPdf 同等級產品 | 筆記 |
|---|---|---|
new HTML2PDFSettingData()。 | 新的 ChromePdfRenderer() | 建立呈現器 |
| <編碼>settings.page_width</編碼 | RenderingOptions.PaperSize | 標準尺寸 |
| <編碼>settings.page_height</編碼 | <編碼>RenderingOptions.SetCustomPaperSize()</編碼 | 自訂尺寸 |
html2pdf.Convert(html, path) | renderer.RenderHtmlAsPdf(html)。 | HTML 字串 |
html2pdf.ConvertFromURL(url,path)。 | renderer.RenderUrlAsPdf(url)。 | URL 轉換。 |
水印設定
| 福昕水印 | IronPdf 同等級產品 | 筆記 |
|---|---|---|
new Watermark(doc、文字、字型、大小、顏色)。 | 新的 TextStamper() | 文字水印 |
WatermarkSettings.position | 垂直對齊 + 水平對齊 | 職位 |
| <編碼>WatermarkSettings.rotation</編碼 | 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
為了在您的 Foxit 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 add package IronPdf。 - [ ] 更新命名空間匯入
- [ ] 在啟動時設定 IronPdf 授權金鑰
程式碼遷移
- [ ] 移除
Library.Initialize()和Library.Release()呼叫 - [ ] 使用 try/catch 取代
ErrorCode檢查 - [ ] 將<編碼>PDFDoc</編碼替換為
PdfDocument - [ ] 將<編碼>HTML2PDF</編碼替換為
ChromePdfRenderer - [更新頁面存取從
GetPage(i)到Pages[i] - [ ] 將
SaveAs(path, flags)改為SaveAs(path) - [ ] 將
Close()替換為Dispose()或 using 語句 - [更新水印程式碼以使用
TextStamper - [ ] 將單位從點轉換為毫米
測試
- [驗證 HTML 至 PDF 的輸出是否符合預期
- [ ] 測試 PDF 載入與文字萃取
- [ ] 核實合併功能
- [ ] 檢查水印外觀
- [ ] 測試安全性/加密功能
- [ ] 驗證表單欄位的操作
- [ ] 效能測試
後遷移
- [ ] 刪除福昕 PDF SDKDLLs
- [ ] 移除與 Foxit 相關的設定檔
- [ ] 更新文件
- [ ] 清理未使用的輔助程式碼
結論
從福昕 PDF SDK轉移到 IronPDF,可以消除複雜的初始化模式、冗長的配置物件以及手動的資源清理。其結果是利用現代 .NET 模式和內建的 HTML/CSS 渲染功能,編寫出更乾淨、更易維護的程式碼。
IronPDF 簡化的 API 可縮短開發時間,同時提供全面的 PDF 功能 - 所有功能均可透過單一 NuGet 套件存取,無需另外購買附加元件。 對於計劃遷移至 .NET 10 及更高版本的團隊而言,IronPDF 為 PDF 生成提供了一個面向未來的基礎。






