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

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

PdfPigからIronPdfに移行することで、PDFの機能が閲覧のみのライブラリから、作成、操作、テキスト抽出、セキュリティ機能を扱う包括的なPDFソリューションに拡張されます。 このガイドでは、既存の抽出ワークフローを維持しながら、PdfPig では提供できない PDF 生成、HTML 変換、文書操作、セキュリティ機能を追加する完全な移行パスをステップごとに説明します。

なぜPdfPigからIronPDFに移行するのか

PdfPigについて

PdfPigは、C#用に特別に設計されたオープンソースのPDF読み取り・抽出ライブラリです。 評判の高いApache PDFBoxプロジェクトの一部門として、このライブラリは、開発者が驚くべき精度でPDFのコンテンツにアクセスすることを可能にします。PdfPigは抽出機能では優れていますが、市販されているより包括的なライブラリと比較すると、その範囲は大きく制限されています。

PdfPig は、PDF ファイルからテキスト、画像、フォームデータ、メタデータを抽出するための信頼性の高いツールを開発者に提供します。 そのため、主に文書分析やデータマイニングに重点を置いたアプリケーションに適しています。 しかし、PdfPigの機能は基本的に既存のドキュメントの解析に限られています。

読解のみの制限

PdfPigはPDFの読み取りに特化しています。 PdfPigは、お客様のアプリケーションが抽出を超えて成長する必要がある場合、お手伝いすることができません:

  1. PDF を生成できません: HTML、URL、またはプログラムから PDF を作成することはできません。

  2. HTML から PDF への変換機能はありません。PdfPigは PDF 読み取り/解析ライブラリであり、PDF 生成ライブラリではありません。 HTMLからPDFへの変換には、別のライブラリを使用する必要があります。

3.ドキュメント操作不可: PDF を結合、分割、または変更することはできません。

4.セキュリティ機能なし:パスワード、暗号化、デジタル署名を追加できません。

5.透かし/スタンプなし:既存のドキュメントに視覚的なオーバーレイを追加できません。

6.フォームへの入力なし:プログラムで PDF フォームに入力できません。

PdfPigとIronPdfの比較

フィーチャー PdfPig IronPDF
ライセンス オープンソース(Apache 2.0) 商用
PDFの読み取り/抽出 優秀 優秀
PDFジェネレーション 制限的 包括的
HTMLからPDFへ サポート対象外 サポート対象
テキスト抽出 優秀 優秀
PDF操作 サポートされていません マージ、分割、回転
ウォーターマーク サポートされていません サポート対象
セキュリティ/暗号化 サポートされていません サポート対象
サポートとドキュメンテーション コミュニティサポート 専用サポート
ページ索引 1ベース 0ベース

IronPDFはPDFの作成、閲覧、編集、署名のための機能一式をサポートしています。 この汎用性により、開発者は最初から最後までPDFファイルを管理することができます。 2025年と2026年まで.NET 10とC# 14の採用を計画しているチームにとって、IronPDFはPdfPigの読み取り機能を超えた完全なPDFライフサイクル・ソリューションを提供します。


始める前に

前提条件

  1. .NET環境: .NET Framework 4.6.2+ または.NET Core 3.1+ / .NET 5/6/7/8/9+
  2. NuGetアクセス: NuGetパッケージをインストールする機能
  3. IronPDFライセンス: IronPDFからライセンスキーを取得します。

NuGetパッケージの変更

# Remove PdfPig
dotnet remove package PdfPig

# Install IronPDF
dotnet add package IronPdf
# Remove PdfPig
dotnet remove package PdfPig

# Install IronPDF
dotnet add package IronPdf
SHELL

ライセンス構成

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

PdfPigの使用法を特定する

# FindPdfPigusage
grep -r "UglyToad\.PdfPig\|PdfDocument\.Open\|GetPages\(\)" --include="*.cs" .

# Find page index references (may need 1→0 conversion)
grep -r "GetPage(\|NumberOfPages" --include="*.cs" .
# FindPdfPigusage
grep -r "UglyToad\.PdfPig\|PdfDocument\.Open\|GetPages\(\)" --include="*.cs" .

# Find page index references (may need 1→0 conversion)
grep -r "GetPage(\|NumberOfPages" --include="*.cs" .
SHELL

完全な API リファレンス

名前空間の変更

// Before: PdfPig
using UglyToad.PdfPig;
using UglyToad.PdfPig.Content;
using UglyToad.PdfPig.DocumentLayoutAnalysis.WordExtractor;

// After: IronPDF
using IronPdf;
using IronPdf.Rendering;
// Before: PdfPig
using UglyToad.PdfPig;
using UglyToad.PdfPig.Content;
using UglyToad.PdfPig.DocumentLayoutAnalysis.WordExtractor;

// After: IronPDF
using IronPdf;
using IronPdf.Rendering;
' Before: PdfPig
Imports UglyToad.PdfPig
Imports UglyToad.PdfPig.Content
Imports UglyToad.PdfPig.DocumentLayoutAnalysis.WordExtractor

' After: IronPDF
Imports IronPdf
Imports IronPdf.Rendering
$vbLabelText   $csharpLabel

ドキュメント読み込みマッピング

PdfPig IronPDF
PdfDocument.Open(path) PdfDocument.FromFile(path)
PdfDocument.Open(bytes) PdfDocument.FromBinaryData(bytes)
PdfDocument.Open(stream) PdfDocument.FromStream(stream)
using (var doc = ...) var pdf = ...

ページ アクセスとプロパティのマッピング

PdfPig IronPDF
document.NumberOfPages pdf.PageCount
document.GetPages() pdf.Pages
document.GetPage(1) pdf.Pages[0]

テキスト抽出マッピング

PdfPig IronPDF
page.Text pdf.Pages[i].Text
page.GetWords() pdf.ExtractTextFromPage(i)
(manual loop) pdf.ExtractAllText()

メタデータアクセスマッピング

PdfPig IronPDF
document.Information.Title pdf.MetaData.Title
document.Information.Author pdf.MetaData.Author
document.Information.Subject pdf.MetaData.Subject
document.Information.Creator pdf.MetaData.Creator
document.Information.Producer pdf.MetaData.Producer

PdfPigでは利用できない新機能

IronPDFの特徴 翻訳内容
renderer.RenderHtmlAsPdf(html) HTMLからPDFへの変換
renderer.RenderUrlAsPdf(url) URLからPDFへの変換
PdfDocument.Merge(pdfs) 複数のPDFをマージ
pdf.ApplyWatermark(html) 透かしの追加
pdf.SecuritySettings.UserPassword パスワード保護
pdf.Sign(certificate) デジタル署名

コード移行の例

例1: PDFからのテキスト抽出

翻訳前 (PdfPig):

// NuGet: Install-Package PdfPig
using UglyToad.PdfPig;
using System;
using System.Text;

class Program
{
    static void Main()
    {
        using (var document = PdfDocument.Open("input.pdf"))
        {
            var text = new StringBuilder();
            foreach (var page in document.GetPages())
            {
                text.AppendLine(page.Text);
            }
            Console.WriteLine(text.ToString());
        }
    }
}
// NuGet: Install-Package PdfPig
using UglyToad.PdfPig;
using System;
using System.Text;

class Program
{
    static void Main()
    {
        using (var document = PdfDocument.Open("input.pdf"))
        {
            var text = new StringBuilder();
            foreach (var page in document.GetPages())
            {
                text.AppendLine(page.Text);
            }
            Console.WriteLine(text.ToString());
        }
    }
}
Imports UglyToad.PdfPig
Imports System
Imports System.Text

Class Program
    Shared Sub Main()
        Using document = PdfDocument.Open("input.pdf")
            Dim text = New StringBuilder()
            For Each page In document.GetPages()
                text.AppendLine(page.Text)
            Next
            Console.WriteLine(text.ToString())
        End Using
    End Sub
End Class
$vbLabelText   $csharpLabel

翻訳後(IronPDF):

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

class Program
{
    static void Main()
    {
        var pdf = PdfDocument.FromFile("input.pdf");
        string text = pdf.ExtractAllText();
        Console.WriteLine(text);
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        var pdf = PdfDocument.FromFile("input.pdf");
        string text = pdf.ExtractAllText();
        Console.WriteLine(text);
    }
}
Imports IronPdf
Imports System

Class Program
    Shared Sub Main()
        Dim pdf = PdfDocument.FromFile("input.pdf")
        Dim text As String = pdf.ExtractAllText()
        Console.WriteLine(text)
    End Sub
End Class
$vbLabelText   $csharpLabel

PdfPigとIronPdfはどちらも優れたテキスト抽出機能を提供します。 主な違いはコードパターンです。PdfPigでは、using ステートメントと PdfDocument.Open()、ページを手動で反復処理して GetPages()、各 page.Text プロパティからテキストを蓄積するために StringBuilder が必要です。

IronPDF はこれを 1 回の呼び出しに簡素化します: PdfDocument.FromFile() はドキュメントを読み込み、ExtractAllText() はすべてのテキスト コンテンツを一度に返します。 using ステートメントは必要なく、手動による反復や StringBuilder も必要ありません。 その他のオプションについては、テキスト抽出ドキュメントを参照してください。

例2: HTMLからPDFへの変換

翻訳前 (PdfPig):

PdfPig は HTML から PDF への変換をサポートしていません。PdfPigは PDF 生成ライブラリではなく、PDF 読み取り/解析ライブラリです。 HTML から PDF への変換には別のライブラリを使用する必要があります。

翻訳後(IronPDF):

// NuGet: Install-Package IronPdf
using IronPdf;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1><p>This is a PDF from HTML</p>");
        pdf.SaveAs("output.pdf");
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;

class Program
{
    static void Main()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1><p>This is a PDF from HTML</p>");
        pdf.SaveAs("output.pdf");
    }
}
Imports IronPdf

Class Program
    Shared Sub Main()
        Dim renderer = New ChromePdfRenderer()
        Dim pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1><p>This is a PDF from HTML</p>")
        pdf.SaveAs("output.pdf")
    End Sub
End Class
$vbLabelText   $csharpLabel

この例は、最も重大な能力ギャップを浮き彫りにしています。PdfPigは、"HTMLからPDFへの変換をサポートしない"、"PDF読み取り/解析ライブラリであり、PDF生成ライブラリではない "と明言しています。PdfPigを使ってHTMLからPDFを作成する必要がある場合は、まったく別のライブラリを使う必要があります。

IronPDF は、ChromePdfRenderer を通じてネイティブの HTML から PDF への変換を提供します。 RenderHtmlAsPdf() メソッドは HTML 文字列を受け入れ、内部的に Chromium エンジンを使用してそれらを PDF ドキュメントに変換し、HTML、CSS、およびJavaScriptを正確にレンダリングします。 結果の PdfDocument は、SaveAs() を使用して保存することも、保存する前にさらに操作することもできます。 包括的な例については、HTML to PDF documentationを参照してください。

例 3:PDFメタデータを読む

翻訳前 (PdfPig):

// NuGet: Install-Package PdfPig
using UglyToad.PdfPig;
using System;

class Program
{
    static void Main()
    {
        using (var document = PdfDocument.Open("input.pdf"))
        {
            var info = document.Information;
            Console.WriteLine($"Title: {info.Title}");
            Console.WriteLine($"Author: {info.Author}");
            Console.WriteLine($"Subject: {info.Subject}");
            Console.WriteLine($"Creator: {info.Creator}");
            Console.WriteLine($"Producer: {info.Producer}");
            Console.WriteLine($"Number of Pages: {document.NumberOfPages}");
        }
    }
}
// NuGet: Install-Package PdfPig
using UglyToad.PdfPig;
using System;

class Program
{
    static void Main()
    {
        using (var document = PdfDocument.Open("input.pdf"))
        {
            var info = document.Information;
            Console.WriteLine($"Title: {info.Title}");
            Console.WriteLine($"Author: {info.Author}");
            Console.WriteLine($"Subject: {info.Subject}");
            Console.WriteLine($"Creator: {info.Creator}");
            Console.WriteLine($"Producer: {info.Producer}");
            Console.WriteLine($"Number of Pages: {document.NumberOfPages}");
        }
    }
}
Imports UglyToad.PdfPig
Imports System

Class Program
    Shared Sub Main()
        Using document = PdfDocument.Open("input.pdf")
            Dim info = document.Information
            Console.WriteLine($"Title: {info.Title}")
            Console.WriteLine($"Author: {info.Author}")
            Console.WriteLine($"Subject: {info.Subject}")
            Console.WriteLine($"Creator: {info.Creator}")
            Console.WriteLine($"Producer: {info.Producer}")
            Console.WriteLine($"Number of Pages: {document.NumberOfPages}")
        End Using
    End Sub
End Class
$vbLabelText   $csharpLabel

翻訳後(IronPDF):

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

class Program
{
    static void Main()
    {
        var pdf = PdfDocument.FromFile("input.pdf");
        var info = pdf.MetaData;
        Console.WriteLine($"Title: {info.Title}");
        Console.WriteLine($"Author: {info.Author}");
        Console.WriteLine($"Subject: {info.Subject}");
        Console.WriteLine($"Creator: {info.Creator}");
        Console.WriteLine($"Producer: {info.Producer}");
        Console.WriteLine($"Number of Pages: {pdf.PageCount}");
    }
}
// NuGet: Install-Package IronPdf
using IronPdf;
using System;

class Program
{
    static void Main()
    {
        var pdf = PdfDocument.FromFile("input.pdf");
        var info = pdf.MetaData;
        Console.WriteLine($"Title: {info.Title}");
        Console.WriteLine($"Author: {info.Author}");
        Console.WriteLine($"Subject: {info.Subject}");
        Console.WriteLine($"Creator: {info.Creator}");
        Console.WriteLine($"Producer: {info.Producer}");
        Console.WriteLine($"Number of Pages: {pdf.PageCount}");
    }
}
Imports IronPdf
Imports System

Class Program
    Shared Sub Main()
        Dim pdf = PdfDocument.FromFile("input.pdf")
        Dim info = pdf.MetaData
        Console.WriteLine($"Title: {info.Title}")
        Console.WriteLine($"Author: {info.Author}")
        Console.WriteLine($"Subject: {info.Subject}")
        Console.WriteLine($"Creator: {info.Creator}")
        Console.WriteLine($"Producer: {info.Producer}")
        Console.WriteLine($"Number of Pages: {pdf.PageCount}")
    End Sub
End Class
$vbLabelText   $csharpLabel

どちらのライブラリも、ほぼ同じパターンでメタデータ・アクセスを提供します。PdfPigは、document.Information を通じてメタデータにアクセスし、document.NumberOfPages を通じてページ数にアクセスします。IronPDFはメタデータに pdf.MetaData を使用し、ページ数に pdf.PageCount を使用します。

移行は簡単です。PdfDocument.Open()PdfDocument.FromFile() に、document.Informationpdf.MetaData に、document.NumberOfPagespdf.PageCount に置き換えます。 IronPDFでは必要ないので、using ステートメント ラッパーを削除します。


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

ページのインデックス変更

PdfPigは1ベースのインデックスを使用しています; IronPDFは0ベースです:

// PdfPig:1ベースindexing
var firstPage = document.GetPage(1);  // First page

// IronPDF:0ベースindexing
var firstPage = pdf.Pages[0];  // First page

// Migration helper
int pdfPigIndex = 1;
int ironPdfIndex = pdfPigIndex - 1;
// PdfPig:1ベースindexing
var firstPage = document.GetPage(1);  // First page

// IronPDF:0ベースindexing
var firstPage = pdf.Pages[0];  // First page

// Migration helper
int pdfPigIndex = 1;
int ironPdfIndex = pdfPigIndex - 1;
' PdfPig:1ベースindexing
Dim firstPage = document.GetPage(1)  ' First page

' IronPDF:0ベースindexing
Dim firstPage = pdf.Pages(0)  ' First page

' Migration helper
Dim pdfPigIndex As Integer = 1
Dim ironPdfIndex As Integer = pdfPigIndex - 1
$vbLabelText   $csharpLabel

使用説明文は必須ではありません

// PdfPig: Requires using for disposal
using (var document = PdfDocument.Open("input.pdf"))
{
    // ...
}

// IronPDF: No using required (but can use for cleanup)
var pdf = PdfDocument.FromFile("input.pdf");
// ...
// pdf.Dispose(); // Optional
// PdfPig: Requires using for disposal
using (var document = PdfDocument.Open("input.pdf"))
{
    // ...
}

// IronPDF: No using required (but can use for cleanup)
var pdf = PdfDocument.FromFile("input.pdf");
// ...
// pdf.Dispose(); // Optional
Imports PdfPig
Imports IronPDF

Using document = PdfDocument.Open("input.pdf")
    ' ...
End Using

Dim pdf = PdfDocument.FromFile("input.pdf")
' ...
' pdf.Dispose() ' Optional
$vbLabelText   $csharpLabel

ドキュメントの読み込みの変更

// PdfPig: PdfDocument.Open()
using (var document = PdfDocument.Open("input.pdf"))

// IronPDF: PdfDocument.FromFile()
var pdf = PdfDocument.FromFile("input.pdf");
// PdfPig: PdfDocument.Open()
using (var document = PdfDocument.Open("input.pdf"))

// IronPDF: PdfDocument.FromFile()
var pdf = PdfDocument.FromFile("input.pdf");
Imports PdfPig
Imports IronPDF

Using document = PdfDocument.Open("input.pdf")
End Using

Dim pdf = PdfDocument.FromFile("input.pdf")
$vbLabelText   $csharpLabel

メタデータ プロパティ名の変更

// PdfPig: document.Information
var info = document.Information;

// IronPDF: pdf.MetaData
var info = pdf.MetaData;
// PdfPig: document.Information
var info = document.Information;

// IronPDF: pdf.MetaData
var info = pdf.MetaData;
' PdfPig: document.Information
Dim info = document.Information

' IronPDF: pdf.MetaData
Dim info = pdf.MetaData
$vbLabelText   $csharpLabel

ページ数プロパティの変更

// PdfPig: document.NumberOfPages
Console.WriteLine($"Pages: {document.NumberOfPages}");

// IronPDF: pdf.PageCount
Console.WriteLine($"Pages: {pdf.PageCount}");
// PdfPig: document.NumberOfPages
Console.WriteLine($"Pages: {document.NumberOfPages}");

// IronPDF: pdf.PageCount
Console.WriteLine($"Pages: {pdf.PageCount}");
' PdfPig: document.NumberOfPages
Console.WriteLine($"Pages: {document.NumberOfPages}")

' IronPDF: pdf.PageCount
Console.WriteLine($"Pages: {pdf.PageCount}")
$vbLabelText   $csharpLabel

移行後の新機能

IronPDFに移行すると、PdfPigでは提供できない機能が得られます:

PDFマージ

var pdf1 = PdfDocument.FromFile("document1.pdf");
var pdf2 = PdfDocument.FromFile("document2.pdf");
var merged = PdfDocument.Merge(pdf1, pdf2);
merged.SaveAs("merged.pdf");
var pdf1 = PdfDocument.FromFile("document1.pdf");
var pdf2 = PdfDocument.FromFile("document2.pdf");
var merged = PdfDocument.Merge(pdf1, pdf2);
merged.SaveAs("merged.pdf");
Dim pdf1 = PdfDocument.FromFile("document1.pdf")
Dim pdf2 = PdfDocument.FromFile("document2.pdf")
Dim merged = PdfDocument.Merge(pdf1, pdf2)
merged.SaveAs("merged.pdf")
$vbLabelText   $csharpLabel

ウォーターマーク

pdf.ApplyWatermark("<h2 style='color:red;'>CONFIDENTIAL</h2>");
pdf.ApplyWatermark("<h2 style='color:red;'>CONFIDENTIAL</h2>");
pdf.ApplyWatermark("<h2 style='color:red;'>CONFIDENTIAL</h2>")
$vbLabelText   $csharpLabel

パスワード保護

pdf.SecuritySettings.UserPassword = "userpassword";
pdf.SecuritySettings.OwnerPassword = "ownerpassword";
pdf.SecuritySettings.UserPassword = "userpassword";
pdf.SecuritySettings.OwnerPassword = "ownerpassword";
pdf.SecuritySettings.UserPassword = "userpassword"
pdf.SecuritySettings.OwnerPassword = "ownerpassword"
$vbLabelText   $csharpLabel

デジタル署名

var signature = new PdfSignature("certificate.pfx", "password")
{
    SigningContact = "support@company.com",
    SigningReason = "Document Approval"
};
pdf.Sign(signature);
var signature = new PdfSignature("certificate.pfx", "password")
{
    SigningContact = "support@company.com",
    SigningReason = "Document Approval"
};
pdf.Sign(signature);
Dim signature As New PdfSignature("certificate.pfx", "password") With {
    .SigningContact = "support@company.com",
    .SigningReason = "Document Approval"
}
pdf.Sign(signature)
$vbLabelText   $csharpLabel

機能比較の概要

フィーチャー PdfPig IronPDF
テキスト抽出
メタデータアクセス
画像抽出
PDF作成 制限的
HTMLからPDFへ
URLからPDFへ
PDFのマージ
PDFの分割
透かし
フォーム入力
パスワード保護
デジタル署名
ワードポジションデータ

移行チェックリスト

移行前

  • コードベース内のすべてのPdfPigの使用状況を一覧表示する
  • 単語レベルの位置データが必要かどうかを特定する(ハイブリッドアプローチを検討)
  • すべてのページインデックス参照をメモします(1 ベースを 0 ベースに変換する必要があります)
  • IronPDFライセンス キーの保存を計画する (環境変数を推奨)
  • まずはIronPDFの試用ライセンスでテストしてください

パッケージの変更

  • PdfPig NuGetパッケージを削除します: dotnet remove package PdfPig
  • IronPdf NuGetパッケージをインストールします: dotnet add package IronPdf

コードの変更

  • 名前空間のインポートを更新します (using UglyToad.PdfPig;using IronPdf;)
  • PdfDocument.Open()PdfDocument.FromFile() に置き換えます
  • document.Informationpdf.MetaData に置き換えます
  • document.NumberOfPagespdf.PageCount に置き換えます
  • ページインデックスを1から0に変換する
  • using ステートメントを削除します (オプション、 IronPDF必要ありません)
  • アプリケーションの起動時にIronPDFライセンスキーを追加する

移行後

  • テストテキスト抽出出力が期待通りである
  • すべてのPDF生成シナリオをテストする
  • 必要に応じて新しい機能(結合、透かし、セキュリティ)を追加します
  • Linuxにデプロイする場合はLinuxの依存関係をインストールします

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

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

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

アイアンサポートチーム

私たちは週5日、24時間オンラインで対応しています。
チャット
メール
電話してね