透かしなしで本番環境でテストしてください。
必要な場所で動作します。
30日間、完全に機能する製品をご利用いただけます。
数分で稼働させることができます。
製品トライアル期間中にサポートエンジニアリングチームへの完全アクセス
このチュートリアルでは、C#でPDF(Portable Document Format)ドキュメントからデータを読み取る方法を、2つの異なるツールを使用した例とともに学習します。
PDFからテキストや画像を抽出できるパーサーライブラリ/リーダーは、オンライン上に多数存在します。 PDFファイルから最新の関連サービスを備えた2つの最も有用で最高のライブラリを使用して情報を抽出します。 また、両方のライブラリを比較して、どちらが優れているかを見つけ出します。
[iText 7](https://itextpdf.com/products/itext-7/itext-7-core" target="_blank" rel="nofollow noopener noreferrer) と IronPDF を比較します。 進む前に、両方のライブラリを紹介します。
iText 7ライブラリは、iTextSharpの最新バージョンです。これは.NETおよびJavaアプリケーションの両方で使用されます。 それにはドキュメントエンジン(Adobe Acrobat Readerのようなもの)、高レベルおよび低レベルのプログラミング機能、イベントリスナー、PDF編集機能が備わっています。 iText 7は、エラーなくPDFドキュメントのページを作成、編集、強化できます。 その他の機能には、パスワードの追加、エンコーディング戦略の作成、PDF文書への権限オプションの保存などがあります。 これもコンテンツやキャンバス画像の追加や変更、PDF要素(辞書など)の追加、ウォーターマークやブックマークの作成、フォントサイズの変更、機密データへの署名に使用されます。
iText 7は、.NET環境でWeb、モバイル、デスクトップ、カーネル、クラウドアプリ向けのカスタムPDF処理アプリケーションを構築することを可能にします。
IronPDFはIron Softwareによって開発されたライブラリで、C#やJavaのソフトウェアエンジニアがPDFコンテンツを作成、編集、抽出できるようにします。 通常、この製品はHTML、ウェブページ、または画像からPDFを生成するために使用されます。 それはPDFを読み取り、そのテキストを抽出するために使用されます。 その他の機能には、ヘッダー/フッター、署名、添付ファイル、パスワード、セキュリティ質問の追加が含まれます。 それはマルチスレッドおよび非同期機能による完全なパフォーマンス最適化を提供します。
IronPDFは.NET 5、.NET 6、.NET 7、.NET Core、Standard、Frameworkのクロスプラットフォームに対応しています。 これはWindows、macOS、Linux、Docker、Azure、AWSに対応しています。
では、両方のデモンストレーションをご覧ください。
次のPDFファイルを使用して、PDFからテキストを抽出します。
IronPDF
以下は、iText 7を使用してテキストを抽出するためのソースコードです。
//assign PDF location to a string and create new StringBuilder...
string pdfPath = @"D:/TestDocument.pdf";
var pageText = new StringBuilder();
//read PDF using new PdfDocument and new PdfReader...
using (PdfDocument document = new PdfDocument(new PdfReader(pdfPath)))
{
var pageNumbers = document.GetNumberOfPages();
for (int page = 1; page <= pageNumbers; page++)
{
//new LocationTextExtractionStrategy creates a new text extraction renderer
LocationTextExtractionStrategy strategy = new LocationTextExtractionStrategy();
PdfCanvasProcessor parser = new PdfCanvasProcessor(strategy);
parser.ProcessPageContent(document.GetFirstPage());
pageText.Append(strategy.GetResultantText());
}
Console.WriteLine(pageText.ToString());
}
//assign PDF location to a string and create new StringBuilder...
string pdfPath = @"D:/TestDocument.pdf";
var pageText = new StringBuilder();
//read PDF using new PdfDocument and new PdfReader...
using (PdfDocument document = new PdfDocument(new PdfReader(pdfPath)))
{
var pageNumbers = document.GetNumberOfPages();
for (int page = 1; page <= pageNumbers; page++)
{
//new LocationTextExtractionStrategy creates a new text extraction renderer
LocationTextExtractionStrategy strategy = new LocationTextExtractionStrategy();
PdfCanvasProcessor parser = new PdfCanvasProcessor(strategy);
parser.ProcessPageContent(document.GetFirstPage());
pageText.Append(strategy.GetResultantText());
}
Console.WriteLine(pageText.ToString());
}
'assign PDF location to a string and create new StringBuilder...
Dim pdfPath As String = "D:/TestDocument.pdf"
Dim pageText = New StringBuilder()
'read PDF using new PdfDocument and new PdfReader...
Using document As New PdfDocument(New PdfReader(pdfPath))
Dim pageNumbers = document.GetNumberOfPages()
For page As Integer = 1 To pageNumbers
'new LocationTextExtractionStrategy creates a new text extraction renderer
Dim strategy As New LocationTextExtractionStrategy()
Dim parser As New PdfCanvasProcessor(strategy)
parser.ProcessPageContent(document.GetFirstPage())
pageText.Append(strategy.GetResultantText())
Next page
Console.WriteLine(pageText.ToString())
End Using
抽出されたテキスト出力
それでは、IronPDFを使ってPDFからテキストを抽出してみましょう。
次のソースコードは、IronPDFを使用してPDFからテキストを抽出する例を示しています。
var pdf = PdfDocument.FromFile(@"D:/TestDocument.pdf");
string text = pdf.ExtractAllText();
Console.WriteLine(text);
var pdf = PdfDocument.FromFile(@"D:/TestDocument.pdf");
string text = pdf.ExtractAllText();
Console.WriteLine(text);
Dim pdf = PdfDocument.FromFile("D:/TestDocument.pdf")
Dim text As String = pdf.ExtractAllText()
Console.WriteLine(text)
IronPDFを使用したテキスト抽出
IronPDFを使用すると、PDFからテキストを抽出するのに2行で済みます。 一方で、iText 7の場合、同じタスクに約10行のコードを書く必要があります。
IronPDFは、標準で便利なテキスト抽出メソッドを提供します。 しかし、iText 7では同じタスクを実行するために独自のロジックを記述する必要があります。
IronPDFはパフォーマンスとコードの可読性の両面において効率的です。
両方のライブラリは精度の面で等しく、どちらも100%の正確な出力を提供します。
iText 7は[商業利用](https://itextpdf.com/how-buy" target="_blank" rel="nofollow noopener noreferrer)のみ使用可能です。 IronPDFは開発には無料で、無料トライアルを商業利用のためにも提供しています。
IronPDFとiText 7のより詳細な比較については、このIronPDF対iText 7のブログ記事をご覧ください。