フッターコンテンツにスキップ
移行ガイド

C#でComPDFKitからIronPDFに移行する方法

ComPDFKitは確かなPDF操作機能を提供していますが、開発チームはいくつかの要因によって、より確立された代替手段を検討することになります。

市場の成熟度とエコシステムの比較

ComPDFKitは、ドキュメントのギャップ、コミュニティの少なさ、Stack Overflowのカバー範囲の狭さなど、新しい市場参入者に共通する課題に直面しています。 IronPdfの10年にわたる改良は、エンタープライズプロジェクトが必要とする安定性とリソースを提供します。

アスペクトComPDFKitIronPDF
HTMLからPDFへ手作業によるHTML解析が必要ネイティブChromiumレンダリング
市場の成熟度新規参加者10年以上の実績
コミュニティサイズ小規模で限定的なStack Overflow大規模で活発なコミュニティ
ドキュメントいくつかのギャップ豊富なチュートリアルとガイド
ダウンロード成長中1,000万以上のNuGetダウンロード数
APIスタイルC# 影響を受ける、冗長最新の.NET流暢なAPI
メモリ管理手動のRelease()呼び出しGCの自動処理

フィーチャー パリティ

どちらのライブラリも包括的なPDF機能をサポートしています:

フィーチャーComPDFKitIronPDF
HTMLからPDFへ基本/マニュアル✅ ネイティブChromium
URLからPDFへマニュアルの実装✅ 組み込みの
ゼロからPDFを作成
PDF編集
テキスト抽出
マージ/スプリット
デジタル署名
フォーム入力
透かし
クロスプラットフォームWindows、Linux、macOSWindows、Linux、macOS

主な移行のメリット

1.優れたHTMLレンダリング: IronPDFのChromiumエンジンは、最新のCSS3、JavaScript、レスポンシブレイアウトをネイティブに処理します。 2.成熟したエコシステム: 10年以上の改良、広範なドキュメント、実証済みの安定性 3.よりシンプルなAPI:定型コードが少なくなり、 Release()呼び出しによる手動のメモリ管理が不要になります。

  1. .NETとの統合の改善:ネイティブのasync/await、LINQサポート、流暢なインターフェース 5.豊富なリソース: Stack Overflowの数千の回答とコミュニティの例

移行前の準備

前提条件

あなたの環境がこれらの要件を満たしていることを確認してください:

  • .NET Framework 4.6.2+または.NET Core 3.1 / .NET 5-9
  • Visual Studio 2019+またはC#拡張機能付きVS Code
  • NuGetパッケージマネージャへのアクセス
  • IronPDFライセンスキー (ironpdf.com にて無料トライアル可能)

ComPDFKitの使用状況を確認する

ソリューションディレクトリでこれらのコマンドを実行し、すべてのComPDFKit参照を特定します:

# Find allComPDFKitusages in your codebase
grep -r "using ComPDFKit" --include="*.cs" .
grep -r "CPDFDocument\|CPDFPage\|CPDFAnnotation" --include="*.cs" .

# Find NuGet package references
grep -r "ComPDFKit" --include="*.csproj" .
# Find allComPDFKitusages in your codebase
grep -r "using ComPDFKit" --include="*.cs" .
grep -r "CPDFDocument\|CPDFPage\|CPDFAnnotation" --include="*.cs" .

# Find NuGet package references
grep -r "ComPDFKit" --include="*.csproj" .
SHELL

予想される画期的な変更

変更ComPDFKitIronPDFインパクト
ドキュメントの読み込みCPDFDocument.InitWithFilePath()PdfDocument.FromFile()を使用してください。メソッド名の変更
セービングdocument.WriteToFilePath()<コード>pdf.SaveAs()</コードメソッド名の変更
メモリクリーンアップdocument.Release() 必須自動翻訳(GC)手動クリーンアップの削除
ページへのアクセスdocument.PageAtIndex(i).<コード>pdf.Pages[i]</コード配列スタイルのアクセス
ページ索引0ベース0ベース変更不要
HTMLレンダリングマニュアルの実装<コード>RenderHtmlAsPdf()</コード主な簡略化
テキスト抽出<コード>textPage.GetText()</コードpdf.ExtractAllText()を使用してください。簡易API

ステップごとの移行プロセス

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

ComPDFKitパッケージを削除し、IronPdfをインストールしてください:

# RemoveComPDFKitpackages
dotnet remove package ComPDFKit.NetCore
dotnet remove package ComPDFKit.NetFramework

# Install IronPDF
dotnet add package IronPdf
# RemoveComPDFKitpackages
dotnet remove package ComPDFKit.NetCore
dotnet remove package ComPDFKit.NetFramework

# Install IronPDF
dotnet add package IronPdf
SHELL

ステップ 2: 名前空間参照の更新

ComPDFKitの名前空間をIronPdfに置き換えてください:

// Remove these
using ComPDFKit.PDFDocument;
using ComPDFKit.PDFPage;
using ComPDFKit.PDFAnnotation;
using ComPDFKit.Import;

// Add this
using IronPdf;
// Remove these
using ComPDFKit.PDFDocument;
using ComPDFKit.PDFPage;
using ComPDFKit.PDFAnnotation;
using ComPDFKit.Import;

// Add this
using IronPdf;
$vbLabelText   $csharpLabel

ステップ 3: ライセンスの設定

// Add at application startup (Program.cs or Global.asax)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
// Add at application startup (Program.cs or Global.asax)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
$vbLabelText   $csharpLabel

完全な API 移行のリファレンス

ドキュメント操作

タスクComPDFKitIronPDF
空のドキュメントを作成CPDFDocument.CreateDocument()new PdfDocument().
ファイルから読み込むCPDFDocument.InitWithFilePath(パス)PdfDocument.FromFile(パス)
ストリームから読み込むCPDFDocument.InitWithStream(ストリーム)<コード>PdfDocument.FromStream(stream)</コード><コード>PdfDocument.FromStream(stream)
ファイルに保存document.WriteToFilePath(パス)pdf.SaveAs(path)のようにします。
ページ数を取得<コード>document.PageCount</コード<コード>pdf.PageCount</コード
リリース/廃棄<コード>document.Release()</コード不要

HTMLからPDFへの変換

タスクComPDFKitIronPDF
HTML文字列からPDFへ手動による実装が必要renderer.RenderHtmlAsPdf(html).
HTMLファイルからPDFへ手動による実装が必要renderer.RenderHtmlFileAsPdf(path)のようにします。
URLからPDFへ手動による実装が必要renderer.RenderUrlAsPdf(url)のようにします。
ページサイズの設定ページ作成パラメータrenderer.RenderingOptions.PaperSize
余白の設定エディタ設定renderer.RenderingOptions.MarginTopなど。

マージと分割の操作

タスクComPDFKitIronPDF
ドキュメントのマージdoc1.ImportPagesAtIndex(doc2, range, index).PdfDocument.Merge(pdf1, pdf2).
文書の分割新しいドキュメントにページを抽出pdf.CopyPages(start, end).

コード移行の例

HTMLからPDFへの変換

ComPDFKitとIronPDFの最も大きな違いはHTMLレンダリングです。 ComPDFKitは手動でテキストを配置する必要がありますが、IronPdfはChromiumエンジンでネイティブにHTMLをレンダリングします。

ComPDFKitの実装:

// NuGet: Install-Package ComPDFKit.NetCore
using ComPDFKit.PDFDocument;
using System;

class Program
{
    static void Main()
    {
        var document = CPDFDocument.CreateDocument();
        var page = document.InsertPage(0, 595, 842, "");

        //ComPDFKitrequires manual HTML rendering
        // NativeHTMLからPDFへnot directly supported
        var editor = page.GetEditor();
        editor.BeginEdit(CPDFEditType.EditText);
        editor.CreateTextWidget(new System.Drawing.RectangleF(50, 50, 500, 700), "HTML content here");
        editor.EndEdit();

        document.WriteToFilePath("output.pdf");
        document.Release();
    }
}
// NuGet: Install-Package ComPDFKit.NetCore
using ComPDFKit.PDFDocument;
using System;

class Program
{
    static void Main()
    {
        var document = CPDFDocument.CreateDocument();
        var page = document.InsertPage(0, 595, 842, "");

        //ComPDFKitrequires manual HTML rendering
        // NativeHTMLからPDFへnot directly supported
        var editor = page.GetEditor();
        editor.BeginEdit(CPDFEditType.EditText);
        editor.CreateTextWidget(new System.Drawing.RectangleF(50, 50, 500, 700), "HTML content here");
        editor.EndEdit();

        document.WriteToFilePath("output.pdf");
        document.Release();
    }
}
$vbLabelText   $csharpLabel

IronPDFの実装:

// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1><p>This is HTML content.</p>");
        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("<h1>Hello World</h1><p>This is HTML content.</p>");
        pdf.SaveAs("output.pdf");
    }
}
$vbLabelText   $csharpLabel

IronPDFのChromePdfRendererは手作業によるテキストの位置決めやエディターの管理を不要にします。 その他のHTML変換オプションについては、HTML to PDF documentationを参照してください。

複数のPDFをマージする

ComPDFKitの実装:

// NuGet: Install-Package ComPDFKit.NetCore
using ComPDFKit.PDFDocument;
using ComPDFKit.Import;
using System;

class Program
{
    static void Main()
    {
        var document1 = CPDFDocument.InitWithFilePath("file1.pdf");
        var document2 = CPDFDocument.InitWithFilePath("file2.pdf");

        // Import pages from document2 into document1
        document1.ImportPagesAtIndex(document2, "0-" + (document2.PageCount - 1), document1.PageCount);

        document1.WriteToFilePath("merged.pdf");
        document1.Release();
        document2.Release();
    }
}
// NuGet: Install-Package ComPDFKit.NetCore
using ComPDFKit.PDFDocument;
using ComPDFKit.Import;
using System;

class Program
{
    static void Main()
    {
        var document1 = CPDFDocument.InitWithFilePath("file1.pdf");
        var document2 = CPDFDocument.InitWithFilePath("file2.pdf");

        // Import pages from document2 into document1
        document1.ImportPagesAtIndex(document2, "0-" + (document2.PageCount - 1), document1.PageCount);

        document1.WriteToFilePath("merged.pdf");
        document1.Release();
        document2.Release();
    }
}
$vbLabelText   $csharpLabel

IronPDFの実装:

// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        var pdf1 = PdfDocument.FromFile("file1.pdf");
        var pdf2 = PdfDocument.FromFile("file2.pdf");

        var merged = PdfDocument.Merge(new List<PdfDocument> { pdf1, pdf2 });
        merged.SaveAs("merged.pdf");
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        var pdf1 = PdfDocument.FromFile("file1.pdf");
        var pdf2 = PdfDocument.FromFile("file2.pdf");

        var merged = PdfDocument.Merge(new List<PdfDocument> { pdf1, pdf2 });
        merged.SaveAs("merged.pdf");
    }
}
$vbLabelText   $csharpLabel

IronPdfの静的なMergeメソッドは、ページ範囲文字列による冗長なImportPagesAtIndexパターンを排除します。 その他のオプションについては、 PDF 結合のドキュメントを参照してください。

透かしの追加

透かしは、ComPDFKitのエディターベースのアプローチからIronPdfのHTMLベースのスタイリングへのパラダイムシフトを示しています。

ComPDFKitの実装:

// NuGet: Install-Package ComPDFKit.NetCore
using ComPDFKit.PDFDocument;
using ComPDFKit.PDFPage;
using System;
using System.Drawing;

class Program
{
    static void Main()
    {
        var document = CPDFDocument.InitWithFilePath("input.pdf");

        for (int i = 0; i < document.PageCount; i++)
        {
            var page = document.PageAtIndex(i);
            var editor = page.GetEditor();
            editor.BeginEdit(CPDFEditType.EditText);

            var textArea = editor.CreateTextArea();
            textArea.SetText("CONFIDENTIAL");
            textArea.SetFontSize(48);
            textArea.SetTransparency(128);

            editor.EndEdit();
            page.Release();
        }

        document.WriteToFilePath("watermarked.pdf");
        document.Release();
    }
}
// NuGet: Install-Package ComPDFKit.NetCore
using ComPDFKit.PDFDocument;
using ComPDFKit.PDFPage;
using System;
using System.Drawing;

class Program
{
    static void Main()
    {
        var document = CPDFDocument.InitWithFilePath("input.pdf");

        for (int i = 0; i < document.PageCount; i++)
        {
            var page = document.PageAtIndex(i);
            var editor = page.GetEditor();
            editor.BeginEdit(CPDFEditType.EditText);

            var textArea = editor.CreateTextArea();
            textArea.SetText("CONFIDENTIAL");
            textArea.SetFontSize(48);
            textArea.SetTransparency(128);

            editor.EndEdit();
            page.Release();
        }

        document.WriteToFilePath("watermarked.pdf");
        document.Release();
    }
}
$vbLabelText   $csharpLabel

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("<h1 style='color:rgba(255,0,0,0.3);'>CONFIDENTIAL</h1>",
            rotation: 45,
            verticalAlignment: VerticalAlignment.Middle,
            horizontalAlignment: HorizontalAlignment.Center);

        pdf.SaveAs("watermarked.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("<h1 style='color:rgba(255,0,0,0.3);'>CONFIDENTIAL</h1>",
            rotation: 45,
            verticalAlignment: VerticalAlignment.Middle,
            horizontalAlignment: HorizontalAlignment.Center);

        pdf.SaveAs("watermarked.pdf");
    }
}
$vbLabelText   $csharpLabel

IronPDFは20行以上の透かしの実装をHTML/CSSのスタイリングで単一のメソッド呼び出しに削減します。 その他のオプションについては、透かしのドキュメントを参照してください。

テキスト抽出

ComPDFKitの実装:

using ComPDFKit.PDFDocument;
using System.Text;

var document = CPDFDocument.InitWithFilePath("document.pdf");

// Extract text (verbose)
var allText = new StringBuilder();
for (int i = 0; i < document.PageCount; i++)
{
    var page = document.PageAtIndex(i);
    var textPage = page.GetTextPage();
    allText.AppendLine(textPage.GetText(0, textPage.CountChars()));
    textPage.Release();
    page.Release();
}

document.WriteToFilePath("output.pdf");
document.Release(); // Must remember to release!
using ComPDFKit.PDFDocument;
using System.Text;

var document = CPDFDocument.InitWithFilePath("document.pdf");

// Extract text (verbose)
var allText = new StringBuilder();
for (int i = 0; i < document.PageCount; i++)
{
    var page = document.PageAtIndex(i);
    var textPage = page.GetTextPage();
    allText.AppendLine(textPage.GetText(0, textPage.CountChars()));
    textPage.Release();
    page.Release();
}

document.WriteToFilePath("output.pdf");
document.Release(); // Must remember to release!
$vbLabelText   $csharpLabel

IronPDFの実装:

using IronPdf;

var pdf = PdfDocument.FromFile("document.pdf");

// Extract text (one-liner)
string allText = pdf.ExtractAllText();

pdf.SaveAs("output.pdf");
// No Release() needed - GC handles cleanup
using IronPdf;

var pdf = PdfDocument.FromFile("document.pdf");

// Extract text (one-liner)
string allText = pdf.ExtractAllText();

pdf.SaveAs("output.pdf");
// No Release() needed - GC handles cleanup
$vbLabelText   $csharpLabel

IronPdfは手作業によるRelease()呼び出しによる複数行のテキスト抽出を単一のメソッドに削減します。 その他の抽出オプションについては、テキスト抽出のドキュメントを参照してください。

パスワード保護

IronPDFの実装:

using IronPdf;

var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Confidential Document</h1>");

// Set security
pdf.SecuritySettings.UserPassword = "userPassword";
pdf.SecuritySettings.OwnerPassword = "ownerPassword";
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.FullPrintRights;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;

pdf.SaveAs("protected.pdf");
using IronPdf;

var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf("<h1>Confidential Document</h1>");

// Set security
pdf.SecuritySettings.UserPassword = "userPassword";
pdf.SecuritySettings.OwnerPassword = "ownerPassword";
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.FullPrintRights;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;

pdf.SaveAs("protected.pdf");
$vbLabelText   $csharpLabel

包括的なセキュリティ オプションについては、暗号化のドキュメントを参照してください。

重要な移行に関する注意事項

すべての Release() 呼び出しを削除します。

最もインパクトのある変更は、手動によるメモリ管理の削除です。 ComPDFKitは、文書、ページ、テキストページ上で明示的なRelease()呼び出しを必要とします。 IronPdfは.NETのガベージコレクションによってこれを自動的に処理します:

//ComPDFKit- manual cleanup required
document.Release();
page.Release();
textPage.Release();

//IronPDF- no equivalent needed
// GC handles cleanup automatically
//ComPDFKit- manual cleanup required
document.Release();
page.Release();
textPage.Release();

//IronPDF- no equivalent needed
// GC handles cleanup automatically
$vbLabelText   $csharpLabel

ネイティブ HTML レンダリング

ComPDFKitはエディタAPIを使って手動でテキストを配置する必要があります。IronPdfはChromiumエンジンでHTML/CSSをネイティブにレンダリングし、最新のCSS3、JavaScript、レスポンシブレイアウトをサポートします。

同じページのインデックス

どちらのライブラリも0ベースのインデックスを使用します(Pages[0]は最初のページです)。

簡易テキスト抽出

複数行の GetTextPage() + GetText() + Release() パターンを、単一の ExtractAllText() 呼び出しに置き換えてください。

フルエント マージ API

ImportPagesAtIndex(doc2, "0-9", pageCount)を単純なMerge(pdf1, pdf2)に置き換えてください。

移行後のチェックリスト

コードの移行が完了したら、以下を確認してください:

  • すべてのユニットテストを実行して、PDF生成が正しく機能することを確認します。
  • PDF出力品質を比較します(IronPDFのChromiumエンジンではレンダリング結果が異なる場合がありますが、通常はより優れています)
  • 複雑な CSS と JavaScript を使用した HTML レンダリングをテストする
  • テキスト抽出の精度を検証する
  • フォームの機能をテストする
  • パフォーマンステストのバッチ操作
  • すべてのターゲット環境でテストする
  • CI/CDパイプラインを更新する
  • ComPDFKitライセンスファイルを削除する

PDFインフラストラクチャの将来性を確保する

.NET 10が目前に迫り、C# 14では新しい言語機能が導入されるため、成熟し、活発に保守されているPDFライブラリを選択することで、長期的な互換性を確保できます。 IronPDFの10年以上の実績、広範なコミュニティサポート、モダンなAPIデザインは、プロジェクトが2025年、2026年に拡張される際にも、移行への投資が報われることを意味します。

その他のリソース


ComPDFKitからIronPDFに移行することで、Release()呼び出しによる手動でのメモリ管理が不要になり、同時にComPDFKitにはないネイティブなHTMLからPDFへのレンダリングが可能になります。 IronPdfの成熟したエコシステムへの移行は、エンタープライズプロジェクトが必要とするドキュメントの深さ、コミュニティサポート、実証済みの安定性を提供します。

カーティス・チャウ
テクニカルライター

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

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。