IRONSOFTWAREHOME
ビデオ

How to Convert Images to a PDF in C#

Curtis Chau
Curtis Chau
Updated: 2026年7月19日

Foxit PDF SDK からIronPDFに移行すると、複雑なエンタープライズ向けの API が最新の開発者向けパターンに置き換えられ、 .NET PDF 生成ワークフローが簡素化されます。 このガイドでは、不要なコードを削除し、コードベース全体で PDF 操作を容易にする、完全なステップバイステップの移行パスを提供します。

なぜFoxit PDF SDKからIronPDFに移行するのですか?

フォクシットPDFの課題

Foxit PDF SDK は強力なエンタープライズ レベルのライブラリですが、非常に複雑なため、開発が遅くなる可能性があります。

1.**複雑なライセンス システム:**複数の製品、SKU、ライセンス タイプ (開発者ごと、サーバーごと、OEM など) があるため、プロジェクトに適切なオプションを選択するのが困難です。

2.**エンタープライズ価格設定:**価格は大規模な組織向けに調整されており、小規模なチームや個人の開発者にとっては高額になる可能性があります。

  1. 重いネイティブパッケージ: 公開NuGetパッケージ (Foxit.SDK.Dotnet)は大きく(約240 MB)、古いプロジェクトでは直接DLL参照やプライベートフィード設定を保持しているかもしれません。

  2. 冗長なAPI: Library.Release()呼び出しにより、全ての操作に定型文が追加されます。

  3. 別々のHTML2PDFエンジン: HTMLからPDFへの変換にはHTML2PDFエンジンのバイナリが必要で、NuGetパッケージにバンドルされるのではなくFoxitサポート/販売から別に配布されます。

  4. 複雑な設定: 設定には詳細なオブジェクト設定(例: HTML2PDFSettingData)と複数のプロパティが必要です。

  5. C++ の伝統: API パターンは C++ の起源を反映しており、最新の C# アプリケーションでは自然な感じがしません。

Foxit PDFとIronPDFの比較

アスペクトFoxit PDF SDKIronPDF
インストールFoxit.SDK.Dotnet (~240 MB) + HTML2PDFエンジン分離シンプルなNuGetパッケージ
ライセンス販売主導、開発者毎プラットフォーム毎透明で、あらゆるサイズに対応
初期設定Library.Initialize(sn, key)ライセンスキーを一度設定
エラー処理エラーコード列挙型.NET Standardの例外
HTMLからPDFへ別々のエンジンのダウンロード内蔵Chromiumエンジン
APIスタイルC#の遺産、冗長性最新 for .NETパターン
リソースのクリーンアップ手動Release()IDisposable/automatic
ドキュメンテーションエンタープライズドキュメントポータル公開チュートリアル

費用便益分析

Foxit PDFからIronPDFへの移行は具体的な開発上の利点を提供します。シンプルなAPIを通じた複雑さの削減、直感的なメソッドを活用した高速な開発、非同期/待機およびLINQサポートを含むモダンな.NETの互換性、既存のWebスキルを利用するHTMLファーストアプローチ、および別々のエンジンダウンロード不要のHTML変換が含まれます。 IronPDFは最新 for .NETバージョンで動作し、モダンなC#パターンとスムーズに組み合わせることができます。


始める前に

前提条件

  1. .NET環境: IronPDFは.NET Framework 4.6.2以降、 .NET Core 3.1以降、 .NET 5/6/7/8/9以降をサポートしています。
  2. NuGetアクセス: NuGetからパッケージをインストールできることを確認する 3.ライセンスキー: IronPDFから本番環境で使用するIronPDFライセンスキーを取得します。

プロジェクトのバックアップ

# Create a backup branch
git checkout -b pre-ironpdf-migration
git add .
git commit -m "Backup before Foxit PDF SDK to IronPDF migration"
SHELL

すべての Foxit PDF の使用法を特定する

# Find all Foxit PDF SDK references
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"
SHELL

ドキュメント現在の機能

移行前のカタログ

  • 使用している Foxit PDF の機能(HTML 変換、注釈、フォーム、セキュリティ)
  • ライセンスキーの場所と初期化コード
  • カスタム構成と設定
  • ErrorCode 列挙型を使用したエラー処理パターン

クイック スタート マイグレーション

ステップ 1: NuGet パッケージを更新する

# Remove the Foxit NuGet package
dotnet remove package Foxit.SDK.Dotnet

# Install IronPDF
dotnet add package IronPdf
SHELL

古い直接的なFoxit DLL参照が.csproj(古いビルド)にある場合、手動で削除します:

<!-- Remove these manually -->
<Reference Include="fsdk_dotnet">
    <HintPath>..\libs\Foxit\fsdk_dotnet.dll</HintPath>
</Reference>
XML

また、個別に解凍されたHTML2PDFエンジンフォルダーを削除します。

ステップ 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;

ステップ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-LICENSE-KEY";
// That's it! No Release() needed

ステップ 4: 基本的な変換パターン

// Before (Foxit PDF)
Library.Initialize(sn, key);
HTML2PDFSettingData settings = new HTML2PDFSettingData();
settings.page_width = 612.0f;
settings.page_height = 792.0f;
Convert.FromHTML(htmlContent, @"C:\Foxit\html2pdf_engine", "",
                 settings, "output.pdf", 30);
Library.Release();

// After (IronPDF)
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("output.pdf");

完全な API リファレンス

名前空間マッピング

Foxit PDF 名前空間IronPDF 同等物
foxitIronPdf
foxit.commonIronPdf
foxit.common.fxcrt該当なし
foxit.pdfIronPdf
foxit.pdf.annotsIronPdf.Editing
foxit.addon.conversionIronPdf.Rendering

コア クラス マッピング

Foxit PDF SDK クラスIronPDF 同等物
Library該当なし
PDFDocPdfDocument
PDFPagePdfDocument.Pages[i]
HTML2PDFChromePdfRenderer
TextPagepdf.ExtractTextFromPage(i)
WatermarkTextStamper / ImageStamper
SecuritySecuritySettings
Formpdf.Form
Metadatapdf.MetaData

PDFDocのメソッド

Foxit PDFDocIronPDF PdfDocument
new PDFDoc(path)PdfDocument.FromFile(path)
doc.LoadW(password)PdfDocument.FromFile(path, password)
doc.GetPageCount()pdf.PageCount
doc.GetPage(index)pdf.Pages[index]
doc.SaveAs(path, flags)pdf.SaveAs(path)
doc.Close()pdf.Dispose() またはusingステートメント
doc.InsertDocument()PdfDocument.Merge()

HTML2PDF / 変換

Foxit HTML2PDFIronPDF 同等物
new HTML2PDFSettingData()new ChromePdfRenderer()
settings.page_widthRenderingOptions.PaperSize
settings.page_heightRenderingOptions.SetCustomPaperSize()
Convert.FromHTML(html, engine, ...)renderer.RenderHtmlAsPdf(html)
Convert.FromHTML(url, engine, ...)renderer.RenderUrlAsPdf(url)

ウォーターマーク設定

Foxit ウォーターマークIronPDF 同等物
new Watermark(doc, text, font, size, color)new TextStamper()
WatermarkSettings.positionVerticalAlignment + HorizontalAlignment
WatermarkSettings.rotationRotation
WatermarkSettings.opacityOpacity
watermark.InsertToAllPages()pdf.ApplyStamp(stamper)

コード例

例1: HTMLからPDFへの変換

以前(Foxit PDF SDK):

// NuGet: Install-Package Foxit.SDK.Dotnet
// HTML-to-PDF requires the separate Foxit HTML2PDF engine (engine_path),
// obtained from Foxit support/sales — not in the NuGet package.
using foxit;
using foxit.common;
using foxit.addon.conversion;
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;

        Convert.FromHTML(
            "<html><body><h1>Hello World</h1></body></html>",
            @"C:\Foxit\html2pdf_engine",   // engine_path (separate download)
            "",                              // cookies path
            settingData,
            "output.pdf",
            30);                             // timeout (seconds)

        Library.Release();
    }
}

翻訳後(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");
    }
}

IronPDFのアプローチは15行以上の設定コードをわずか4行に減らします。 ライブラリの初期化、明示的なクリーンアップ、複雑な設定オブジェクトはありません。 HTMLレンダリングのオプションについては、HTML to PDF documentationを参照してください。

例2: URLからPDFへの変換

以前(Foxit PDF SDK):

// NuGet: Install-Package Foxit.SDK.Dotnet
// Convert.FromHTML accepts either a URL or a literal HTML string in the
// first argument; the URL form is what does URL-to-PDF.
using foxit;
using foxit.common;
using foxit.addon.conversion;
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;

        Convert.FromHTML(
            "https://www.example.com",
            @"C:\Foxit\html2pdf_engine",   // engine_path (separate download)
            "",                              // cookies path
            settingData,
            "output.pdf",
            30);                             // timeout (seconds)

        Library.Release();
    }
}

翻訳後(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");
    }
}

IronPDFの内蔵ChromiumエンジンはJavaScriptの実行、CSSレンダリング、ダイナミックコンテンツを自動的に処理します。 URLからPDFへの変換の詳細については、こちらをご覧ください。

例3: 透かしを追加する

以前(Foxit PDF SDK):

// NuGet: Install-Package Foxit.SDK.Dotnet
using foxit;
using foxit.common;
using foxit.pdf;
using System;

class Program
{
    static void Main()
    {
        Library.Initialize("sn", "key");

        using (PDFDoc doc = new PDFDoc("input.pdf"))
        {
            doc.Load("");

            WatermarkSettings settings = new WatermarkSettings();
            settings.flags = (int)Watermark.Flags.e_FlagASPageContents;
            settings.position = Position.e_PosCenter;
            settings.rotation = -45.0f;
            settings.opacity = 50;     // 0-100 in newer SDKs

            WatermarkTextProperties props = new WatermarkTextProperties();
            props.font = new Font(Font.StandardID.e_StdIDHelvetica);
            props.font_size = 48.0f;
            props.color = 0xFF0000;
            props.alignment = Alignment.e_AlignmentCenter;

            Watermark watermark = new Watermark(doc, "Confidential", props, settings);

            // No InsertToAllPages helper — iterate pages explicitly.
            for (int i = 0; i < doc.GetPageCount(); i++)
            {
                using (PDFPage page = doc.GetPage(i))
                {
                    watermark.InsertToPage(page);
                }
            }

            doc.SaveAs("output.pdf", (int)PDFDoc.SaveFlags.e_SaveFlagNoOriginal);
        }

        Library.Release();
    }
}

翻訳後(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");
    }
}

IronPDFの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 SDK has limited header/footer support
            // Often requires post-processing or additional code

            Convert.FromHTML(
                "https://www.example.com",
                @"C:\Foxit\html2pdf_engine",  // engine_path (separate download)
                "",                            // cookies path
                settings,
                "webpage.pdf",
                30);                           // timeout (seconds)
        }
        finally
        {
            Library.Release();
        }
    }
}

翻訳後(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");
    }
}

IronPDFはネイティブのヘッダーとフッターを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("");

                // Build the encryption data (cipher, key length, permissions)
                using (StdEncryptData encryptData = new StdEncryptData(
                    true,                                    // is_encrypt_metadata
                    (int)(PDFDoc.UserPermissions.e_PermPrint |
                          PDFDoc.UserPermissions.e_PermModify),
                    SecurityHandler.CipherType.e_CipherAES,
                    16))                                     // key length (bytes) -> AES-128
                using (StdSecurityHandler securityHandler = new StdSecurityHandler())
                {
                    securityHandler.Initialize(encryptData, "user_password", "owner_password");
                    doc.SetSecurityHandler(securityHandler);
                }

                doc.SaveAs("encrypted.pdf", (int)PDFDoc.SaveFlags.e_SaveFlagNoOriginal);
            }
        }
        finally
        {
            Library.Release();
        }
    }
}

翻訳後(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");
    }
}

パフォーマンスの考慮事項

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;
}

ユニット変換ヘルパー

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) to IronPDF millimeters
renderer.RenderingOptions.MarginTop = UnitConverter.PointsToMm(72); // ~25.4mm

適切なリソースの処分

// GOOD - Using statement for automatic cleanup
using (var pdf = PdfDocument.FromFile("large.pdf"))
{
    string text = pdf.ExtractAllText();
}  // pdf is disposed automatically

トラブルシューティング

問題 1: Library.Initialize() が見つかりません

問題: IronPDFにはLibrary.Initialize()がありません。

**解決策:**IronPDFはより単純な初期化パターンを使用します。

// Foxit PDF
Library.Initialize(sn, key);

// IronPDF - just set license key once at startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";

課題2: エラーコード処理

問題: コードはErrorCode.e_ErrSuccessをチェックしますが、IronPDFにはこれがありません。

**解決策:**標準 for .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}");
}

問題 3: PDFDoc.Close() が見つかりません

問題: IronPDFにはdoc.Close()メソッドがありません。

解決策: usingステートメントを使用します:

// Foxit PDF
doc.Close();

// IronPDF
pdf.Dispose();
// or better: wrap in using statement

移行チェックリスト

移行前

  • 使用されているすべてのFoxit PDF SDK機能をインベントリします
  • ドキュメントのライセンスキーの場所
  • すべてのLibrary.Release()呼び出しを記録する
  • カスタム設定(ページ サイズ、余白など)を一覧表示します
  • ErrorCode を使用してエラー処理パターンを識別する
  • バージョン管理にプロジェクトをバックアップする
  • IronPDFライセンスキーを取得する

パッケージの移行

  • .csproj からFoxit PDF SDKDLL 参照を削除します
  • プライベートNuGetフィード構成を削除します -IronPDFNuGetパッケージをインストールする: dotnet add package IronPdf
  • 名前空間のインポートを更新する
  • 起動時にIronPDFライセンスキーを設定する

コードの移行

  • Library.Release()呼び出しを削除する
  • ErrorCodeチェックをtry/catchに置き換える
  • PdfDocumentに置き換える
  • ChromePdfRendererに置き換える
  • ページアクセスをPages[i]に更新する
  • SaveAs(path)に置き換える
  • Dispose()またはusingステートメントに置き換える
  • ウォーターマークコードをTextStamperを使用するように更新する
  • 単位をポイントからミリメートルに変換する

テスティング

  • HTMLからPDFへの出力が期待通りであることを確認する
  • PDFの読み込みとテキスト抽出をテストする
  • マージ機能の検証
  • 透かしの外観を確認する
  • セキュリティ/暗号化機能をテストする
  • フォームフィールドの操作を検証する
  • パフォーマンステスト

移行後

-Foxit PDF SDKDLLを削除する

  • Foxit関連の設定ファイルを削除する
  • ドキュメントの更新
  • 未使用のヘルパーコードをクリーンアップする

ご注意: Foxit PDF SDKおよびFoxitはFoxit Software Incorporatedの登録商標です。 このサイトは Foxit Software と提携しておらず、承認またはスポンサーを受けていません。 すべての製品名、ロゴ、およびブランドは各所有者の所有物です。 比較は情報提供のみを目的としており、執筆時点で公開されている情報を反映しています。
Curtis Chau
テクニカルライター

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

...
詳しく読む

関連する記事

Key in blue circle

無料の30日間トライアルキーをすぐに入手してください。

Your trial license will be sent to your email address

制限なし。100% ロック解除済み。クレジットカード不要。

bullet_checkedクレジットカードやアカウントの作成は不要です。制限なし。100% ロック解除済み。クレジットカード不要。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
無料のライブデモを予約する
Booking Badge

世界中の数百万人のエンジニアから信頼されています。

ライセンスはより安く
義務のない相談を受ける
下記のフォームを記入するか、sales@ironsoftware.comにメールしてください。
あなたの詳細は常に守秘されます。
世界中の数百万人のエンジニアから信頼されています。
ライセンスはより安く
あなたの無料30日間の試用キーをすぐに入手。
クレジットカードやアカウントの作成は不要です。