Foxit PDF SDKからIronPdfへの移行:(.NET ガイド)
Foxit PDF SDKからIronPDFへの移行:完全なC#移行ガイド
Foxit PDF SDKからIronPDFへの移行は、複雑なエンタープライズ向けAPIを最新の開発者フレンドリーなパターンに置き換えることで、.NET PDF生成ワークフローを合理化します。 このガイドは、定型的なコードを排除し、コードベース全体のPDF操作を簡素化する、包括的で段階的な移行パスを提供します。
なぜFoxit PDF SDKからIronPDFに移行するのですか?
フォクシットPDFの課題
Foxit PDF SDKは強力なエンタープライズレベルのライブラリですが、開発の速度を低下させる複雑さがあります:
1.複雑なライセンスシステム:複数の製品、SKU、ライセンスタイプ(開発者ごと、サーバーごと、OEMなど)があるため、プロジェクトに適したオプションを選択するのが難しくなっています。
2.エンタープライズ価格:価格は大規模な組織向けに設定されており、小規模なチームや個人の開発者にとっては高額になる可能性があります。
3.手動インストール:Foxit PDF SDK には、手動による DLL 参照またはプライベート NuGet フィードが必要です。
4.冗長なAPI:Library.Initialize()によるライブラリの初期化、エラーコードチェック、明示的なLibrary.Release()呼び出しは、すべての操作に実質的な定型文を追加します。
5.個別のHTML変換アドオン: HTMLからPDFへの変換には、アドオンの追加購入が必要です。
6.複雑な構成: 設定には、複数のプロパティを持つ詳細なオブジェクト構成 (HTML2PDFSettingData など) が必要です。
7.C++の遺産:APIパターンはC#の起源を反映しており、最新のC#アプリケーションではあまり自然ではありません。
Foxit PDFとIronPDFの比較
</font| アスペクト | Foxit PDF SDK | IronPDF |
|---|---|---|
| インストール | マニュアルDLL/プライベートフィード | シンプルなNuGetパッケージ |
| ライセンス | 企業向けの複雑な翻訳 | 透明で、あらゆるサイズに対応 |
| 初期設定 | Library.Initialize(sn, key). | ライセンスキーを一度設定 |
| エラー処理 | エラーコード列挙型 | .NET 標準の例外 |
| HTMLからPDFへ | 別途アドオン購入 | 内蔵Chromiumエンジン |
| APIスタイル | C#の遺産、冗長性 | 最新の.NETパターン |
| リソースのクリーンアップ | マニュアル Close()/Release()。 | IDisposable/automatic |
| ドキュメンテーション | エンタープライズドキュメントポータル | 公開チュートリアル。 |
費用便益分析
Foxit PDFからIronPDFに移行することで、よりシンプルなAPIによる複雑さの軽減、直感的なメソッドによる開発の高速化、非同期/待機やLINQサポートを含む最新の.NET互換性、既存のWebスキルを活用する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 beforeFoxit PDF SDKtoIronPDFmigration"# Create a backup branch
git checkout -b pre-ironpdf-migration
git add .
git commit -m "Backup beforeFoxit PDF SDKtoIronPDFmigration"すべての Foxit PDF の使用法を特定する
# Find allFoxit 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 allFoxit 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"ドキュメント現在の機能
移行前のカタログ
- 使用している Foxit PDF の機能(HTML 変換、注釈、フォーム、セキュリティ)
- ライセンスキーの場所と初期化コード
- カスタム構成と設定
- ErrorCode 列挙型を使用したエラー処理パターン
クイック スタート マイグレーション
ステップ 1: NuGet パッケージを更新する。
#Foxit PDF SDKtypically requires manual removal of DLL references
# Check your .csproj for Foxit references and remove them
# Install IronPDF
dotnet add package IronPdf#Foxit 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の移行における最も重要な改善点の1つは、複雑な初期化とクリーンアップのパターンをなくしたことです:
// 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 リファレンス
名前空間マッピング
| Foxit PDF 名前空間 | IronPDF 同等物 | ノート |
|---|---|---|
| <コード>foxit</コード | IronPdf(アイアンPDF | 主な名前空間 |
| <コード>foxit.common</コード | IronPdf(アイアンPDF | 一般的なタイプ |
| <コード>foxit.common.fxcrt</コード | 該当なし | 低レベル(不要) |
| <コード>foxit.pdf</コード | IronPdf(アイアンPDF | PDFドキュメント操作 |
| <コード>foxit.pdf.annots</コード | <コード>IronPdf.Editing</コード | 注釈 |
| <コード>foxit.addon.conversion</コード | IronPdf.レンダリング | HTML/画像変換 |
コア クラス マッピング
| Foxit PDF SDK クラス | IronPDF 同等物 | ノート |
|---|---|---|
| <コード>ライブラリ</コード | 該当なし | IronPDFは以下を自動管理します。 |
| <コード>PDFDoc</コード | <コード>PdfDocument</コード | 主なドキュメントクラス |
| <コード>PDFページ</コード | <コード>PdfDocument.Pages[i]</コード | ページへのアクセス |
HTML2PDF | <コード>ChromePdfRenderer</コード | HTML変換 |
| <コード>テキストページ</コード | pdf.ExtractTextFromPage(i)のようにします。 | テキスト抽出 |
| <コード>ウォーターマーク</コード | <コード>TextStamper</コード> / <コード>ImageStamper</コード | ウォーターマーク。 |
| <コード>セキュリティ</コード | <コード>セキュリティ設定</コード | PDFセキュリティ |
| <コード>フォーム</コード | <コード>pdf.Form</コード | フォームフィールド |
| <コード>メタデータ</コード | <コード>pdf.MetaData</コード | 文書のメタデータ |
PDFDocのメソッド
| Foxit PDFDoc | IronPDF PdfDocument | ノート |
|---|---|---|
new PDFDoc(path) とします。 | PdfDocument.FromFile(パス)。 | ファイルから読み込む |
| <コード>doc.LoadW(パスワード)</コード | PdfDocument.FromFile(path, password). | パスワード保護 |
| <コード>doc.GetPageCount()</コード | <コード>pdf.PageCount</コード | ページ数プロパティ |
doc.GetPage(インデックス) | <コード>pdf.Pages[index]</コード | インデックスでページを取得 |
doc.SaveAs(path, flags). | pdf.SaveAs(path)のようにします。 | ドキュメントを保存 |
| <コード>doc.Close()</コード | pdf.Dispose()またはusing文 | クリーンアップ |
doc.InsertDocument()。 | PdfDocument.Merge()を使用してください。 | ドキュメントをマージする. |
HTML2PDF / 変換
| Foxit HTML2PDF | IronPDF 同等物 | ノート |
|---|---|---|
new HTML2PDFSettingData(). | new 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変換。 |
ウォーターマーク設定
| Foxit ウォーターマーク | IronPDF 同等物 | ノート |
|---|---|---|
new Watermark(doc, text, font, size, color). | new TextStamper(). | テキスト透かし |
| <コード>WatermarkSettings.position</コード | VerticalAlignment + HorizontalAlignment です。 | ポジション |
| <コード>WatermarkSettings.rotation</コード | <コード>ローテーション</コード | 回転角度 |
| <コード>WatermarkSettings.opacity</コード | <コード>Opacity</コード | 0~100パーセント |
watermark.InsertToAllPages(). | <コード>pdf.ApplyStamp(stamper)</コード><コード>pdf.ApplyStamp(stamper) | 応募対象 |
コード例
例1: HTMLからPDFへの変換
以前(Foxit 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.com翻訳後(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 documentationを参照してください。
例2: URLからPDFへの変換
以前(Foxit 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.com翻訳後(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: 透かしを追加する
以前(Foxit 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.com翻訳後(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 documentationの全文をご覧ください。
例4: ヘッダーとフッターのあるPDFへのURL
以前(Foxit 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;
//Foxit 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;
//Foxit 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.com翻訳後(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 のセキュリティと暗号化
以前(Foxit 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.com翻訳後(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移行チェックリスト
移行前
- [使用されているFoxit PDF SDKの全機能のインベントリ
- [ドキュメントのライセンスキーの場所
- [すべての
Library.Initialize()とLibrary.Release()呼び出しに注意してください。 - [カスタム設定(ページサイズ、マージンなど)をリストアップしてください。)
- [ ] ErrorCodeを使用したエラー処理パターンの特定
- [プロジェクトのバージョン管理へのバックアップ
- [IronPDF ライセンスキーの取得
パッケージの移行
- [ ] .csproj からFoxit PDF SDKDLL 参照を削除する
- [ ] プライベートなNuGetフィード設定を削除する。
- [ ] IronPdf NuGetパッケージをインストールします:
dotnet add package IronPdf<//code>. - [名前空間インポートの更新
- [ ] 起動時にIronPDFライセンスキーを設定する
コードの移行
- [ ]
Library.Initialize()とLibrary.Release()の呼び出しを削除する。 - [ ]
ErrorCode<//code> チェックを try/catch に置き換えてください。 - [
PDFDoc<//code> をPdfDocument<//code> に置き換えてください。 - [
HTML2PDFを<コード>ChromePdfRenderer</コードに置き換えてください。 - [ ]
GetPage(i)からPages[i]にページアクセスを更新してください。 - [ ]
SaveAs(path, flags)をSaveAs(path)に置き換えてください。 - [ ]
Close()をDispose()またはusing文に置き換えてください。 - [ ]
TextStamperを使用するように透かしコードを更新してください。 - [ポイントからミリメートルへの単位変換
テスティング
- [HTMLからPDFへの出力が期待通りになっているか確認すること。
- [PDF の読み込みとテキスト抽出のテスト
- [マージ機能の検証
- [透かしの表示チェック
- [セキュリティ/暗号化機能のテスト
- [フォームフィールドの操作を検証する
- [パフォーマンステスト
移行後
- [ ]Foxit PDF SDKDLLの削除
- [Foxit 関連の設定ファイルの削除
- [ドキュメントの更新
- [未使用のヘルパーコードのクリーンアップ
結論
Foxit PDF SDKからIronPDFに移行することで、複雑な初期化パターン、冗長な設定オブジェクト、手動によるリソースのクリーンアップが不要になります。その結果、最新の.NETパターンと組み込みのHTML/CSSレンダリング機能を活用した、よりクリーンで保守性の高いコードが実現します。
IronPDFの簡素化されたAPIは、包括的なPDF機能を提供しながら開発時間を短縮します。 .NET 10以降への移行を計画しているチームにとって、IronPDFはPDF生成のための将来的な基盤を提供します。
IronPDFドキュメント、チュートリアル、APIリファレンスをすべてご覧いただき、Foxit PDFへの移行を促進してください。






