C# PDFパーサー
C#でIronPDFのExtractAllTextメソッドを使用してPDFファイルを解析し、ドキュメント全体または特定のページからテキストを抽出します。 このアプローチは、わずか数行のコードで、.NETアプリケーションのためのシンプルで効率的なPDFテキスト抽出を提供します。
IronPDFはC#アプリケーションでPDFの解析を簡単にします。 このチュートリアルでは、IronPDFという、PDF生成および操作のための包括的なC#ライブラリを使って、PDFをわずか数ステップで解析する方法を示します。
クイックスタート: IronPDFによる効率的な PDF 解析最小限のコードでIronPDFを使ってC#でPDFを解析する。 この例では、元の書式を維持したままPDFファイルからすべてのテキストを抽出する方法を示します。 IronPDFのExtractAllTextメソッドは、.NETアプリケーションへのスムーズなPDF解析の統合を可能にします。 以下の手順に従って、簡単にセットアップと実行を行ってください。
-
1IronPDF を NuGet Package Manager でインストールします
-
2このコード スニペットをコピーして実行します。
using IronPdf; var text = PdfDocument.FromFile("sample.pdf").ExtractAllText();Imports IronPdf Dim text = PdfDocument.FromFile("sample.pdf").ExtractAllText()Imports IronPdf Dim text = PdfDocument.FromFile("sample.pdf").ExtractAllText() -
3実際の環境でテストするためにデプロイする
今日からご自身のプロジェクトでIronPDFを使い始めるには、無料トライアルをお試しください。
最小限のワークフロー(5ステップ)
- C# PDFパーサーライブラリをダウンロード
- Visual Studio にインストールする
ExtractAllTextメソッドを使用して、テキストのすべての行を抽出します。ExtractTextFromPageメソッドを使用して、1 つのページからすべてのテキストを抽出します。- 解析された PDF コンテンツを表示する
C#でPDFファイルを解析するにはどうすればよいですか?
IronPDFを使えばPDFファイルの解析は簡単です。 以下のコードは、ExtractAllTextメソッドを使用して、PDFドキュメント全体からすべてのテキスト行を抽出します。 比較は、抽出されたPDFコンテンツとその出力を示しています。 このライブラリは特定のセクションからテキストと画像の抽出もサポートしています。
入力
サンプルの請求書PDF。
using IronPdf;
// Select the desired PDF File
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");
// Extract all text from an pdf
string allText = pdf.ExtractAllText();
// Extract all text from page 1
string page1Text = pdf.ExtractTextFromPage(0);using IronPdf;
// Select the desired PDF File
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");
// Extract all text from an pdf
string allText = pdf.ExtractAllText();
// Extract all text from page 1
string page1Text = pdf.ExtractTextFromPage(0);Imports IronPdf
' Select the desired PDF File
Private pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")
' Extract all text from an pdf
Private allText As String = pdf.ExtractAllText()
' Extract all text from page 1
Private page1Text As String = pdf.ExtractTextFromPage(0)Imports IronPdf
' Select the desired PDF File
Private pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")
' Extract all text from an pdf
Private allText As String = pdf.ExtractAllText()
' Extract all text from page 1
Private page1Text As String = pdf.ExtractTextFromPage(0)出力
ExtractAllTextを実行すると、読み順でページテキストが返されます。
Invoice INV-2026-0042
Billed to: Northwind Traders
Date: 2026-02-14
Consulting $3,200.00
Support $800.00
Total: $4,000.00
高度なテキスト抽出例
IronPDFを使用してPDFコンテンツを解析するその他の方法はこちらです:
入力
10ページのレポートドキュメント。
using IronPdf;
using System;
// Parse PDF from URL
var pdfFromUrl = PdfDocument.FromUrl(new Uri("https://example.com/document.pdf"));
string urlPdfText = pdfFromUrl.ExtractAllText();
// Parse password-protected PDFs
var protectedPdf = PdfDocument.FromFile("protected.pdf", "password123");
string protectedText = protectedPdf.ExtractAllText();
// Extract text from specific page range
var largePdf = PdfDocument.FromFile("large-document.pdf");
for (int i = 5; i < 10; i++)
{
string pageText = largePdf.ExtractTextFromPage(i);
Console.WriteLine($"Page {i + 1}: {pageText.Substring(0, 100)}...");
}using IronPdf;
using System;
// Parse PDF from URL
var pdfFromUrl = PdfDocument.FromUrl(new Uri("https://example.com/document.pdf"));
string urlPdfText = pdfFromUrl.ExtractAllText();
// Parse password-protected PDFs
var protectedPdf = PdfDocument.FromFile("protected.pdf", "password123");
string protectedText = protectedPdf.ExtractAllText();
// Extract text from specific page range
var largePdf = PdfDocument.FromFile("large-document.pdf");
for (int i = 5; i < 10; i++)
{
string pageText = largePdf.ExtractTextFromPage(i);
Console.WriteLine($"Page {i + 1}: {pageText.Substring(0, 100)}...");
}Imports IronPdf
Imports System
' Parse PDF from URL
Dim pdfFromUrl = PdfDocument.FromUrl(New Uri("https://example.com/document.pdf"))
Dim urlPdfText As String = pdfFromUrl.ExtractAllText()
' Parse password-protected PDFs
Dim protectedPdf = PdfDocument.FromFile("protected.pdf", "password123")
Dim protectedText As String = protectedPdf.ExtractAllText()
' Extract text from specific page range
Dim largePdf = PdfDocument.FromFile("large-document.pdf")
For i As Integer = 5 To 9
Dim pageText As String = largePdf.ExtractTextFromPage(i)
Console.WriteLine($"Page {i + 1}: {pageText.Substring(0, 100)}...")
NextImports IronPdf
Imports System
' Parse PDF from URL
Dim pdfFromUrl = PdfDocument.FromUrl(New Uri("https://example.com/document.pdf"))
Dim urlPdfText As String = pdfFromUrl.ExtractAllText()
' Parse password-protected PDFs
Dim protectedPdf = PdfDocument.FromFile("protected.pdf", "password123")
Dim protectedText As String = protectedPdf.ExtractAllText()
' Extract text from specific page range
Dim largePdf = PdfDocument.FromFile("large-document.pdf")
For i As Integer = 5 To 9
Dim pageText As String = largePdf.ExtractTextFromPage(i)
Console.WriteLine($"Page {i + 1}: {pageText.Substring(0, 100)}...")
Next出力
URLとパスワードが保護された行にはライブ入力が必要ですが、ページ範囲ループは各抽出されたページをコンソールに書き込みます。

複雑な解析ニーズには、PDF DOMオブジェクトアクセスを探索して構造化された内容を扱うことができます。
さまざまなPDFタイプの処理
IronPDFは様々なPDFタイプの解析に優れています:
using IronPdf;
using System.Text.RegularExpressions;
// Parse scanned PDFs with OCR (requires IronOcr)
var scannedPdf = PdfDocument.FromFile("scanned-document.pdf");
string ocrText = scannedPdf.ExtractAllText();
// Parse PDFs with forms
var formPdf = PdfDocument.FromFile("form.pdf");
string formText = formPdf.ExtractAllText();
// Extract and filter specific content
string invoiceText = pdf.ExtractAllText();
var invoiceNumber = Regex.Match(invoiceText, @"Invoice #: (\d+)").Groups[1].Value;
var totalAmount = Regex.Match(invoiceText, @"Total: \$([0-9,]+\.\d{2})").Groups[1].Value;using IronPdf;
using System.Text.RegularExpressions;
// Parse scanned PDFs with OCR (requires IronOcr)
var scannedPdf = PdfDocument.FromFile("scanned-document.pdf");
string ocrText = scannedPdf.ExtractAllText();
// Parse PDFs with forms
var formPdf = PdfDocument.FromFile("form.pdf");
string formText = formPdf.ExtractAllText();
// Extract and filter specific content
string invoiceText = pdf.ExtractAllText();
var invoiceNumber = Regex.Match(invoiceText, @"Invoice #: (\d+)").Groups[1].Value;
var totalAmount = Regex.Match(invoiceText, @"Total: \$([0-9,]+\.\d{2})").Groups[1].Value;Imports IronPdf
Imports System.Text.RegularExpressions
' Parse scanned PDFs with OCR (requires IronOcr)
Dim scannedPdf = PdfDocument.FromFile("scanned-document.pdf")
Dim ocrText As String = scannedPdf.ExtractAllText()
' Parse PDFs with forms
Dim formPdf = PdfDocument.FromFile("form.pdf")
Dim formText As String = formPdf.ExtractAllText()
' Extract and filter specific content
Dim invoiceText As String = pdf.ExtractAllText()
Dim invoiceNumber = Regex.Match(invoiceText, "Invoice #: (\d+)").Groups(1).Value
Dim totalAmount = Regex.Match(invoiceText, "Total: \$([0-9,]+\.\d{2})").Groups(1).ValueImports IronPdf
Imports System.Text.RegularExpressions
' Parse scanned PDFs with OCR (requires IronOcr)
Dim scannedPdf = PdfDocument.FromFile("scanned-document.pdf")
Dim ocrText As String = scannedPdf.ExtractAllText()
' Parse PDFs with forms
Dim formPdf = PdfDocument.FromFile("form.pdf")
Dim formText As String = formPdf.ExtractAllText()
' Extract and filter specific content
Dim invoiceText As String = pdf.ExtractAllText()
Dim invoiceNumber = Regex.Match(invoiceText, "Invoice #: (\d+)").Groups(1).Value
Dim totalAmount = Regex.Match(invoiceText, "Total: \$([0-9,]+\.\d{2})").Groups(1).ValueCAD図面や地図のエクスポートなどの階層化されたPDFは異なるタイプであり、その内容は名前付きオプショナルコンテントグループ(OCG)にグループ化されています。 ドキュメント全体を解析する代わりに、ExtractTextFromLayerで一層に限定して抽出するか、ExtractTextFromLayersでいくつかを組み合わせることができます。 詳細については、特定のレイヤーからテキストを抽出を参照してください。
解析されたPDFの内容を表示するにはどうすればよいですか?
C#フォームは、上記のコード実行から解析されたPDFコンテンツを表示します。 この出力は、文書処理のニーズに合わせてPDFから正確なテキストを提供します。
抽出されたテキストは、PDFの元の書式と構造を維持しているため、データ処理、コンテンツ分析、移行作業に最適です。 このテキストをさらに特定の内容を検索して置換したり、他の形式にエクスポートすることで処理します。
アプリケーションへのPDF解析の統合
IronPDFの解析機能は様々なアプリケーションに統合されます:
// ASP.NET Core example
public IActionResult ParseUploadedPdf(IFormFile pdfFile)
{
using var stream = pdfFile.OpenReadStream();
var pdf = PdfDocument.FromStream(stream);
var extractedText = pdf.ExtractAllText();
// Process or store the extracted text
return Json(new {
success = true,
textLength = extractedText.Length,
preview = extractedText.Substring(0, Math.Min(500, extractedText.Length))
});
}
// Console application example
static void BatchParsePdfs(string folderPath)
{
var pdfFiles = Directory.GetFiles(folderPath, "*.pdf");
foreach (var file in pdfFiles)
{
var pdf = PdfDocument.FromFile(file);
var text = pdf.ExtractAllText();
// Save extracted text
var textFile = Path.ChangeExtension(file, ".txt");
File.WriteAllText(textFile, text);
Console.WriteLine($"Parsed: {Path.GetFileName(file)} - {text.Length} characters");
}
}// ASP.NET Core example
public IActionResult ParseUploadedPdf(IFormFile pdfFile)
{
using var stream = pdfFile.OpenReadStream();
var pdf = PdfDocument.FromStream(stream);
var extractedText = pdf.ExtractAllText();
// Process or store the extracted text
return Json(new {
success = true,
textLength = extractedText.Length,
preview = extractedText.Substring(0, Math.Min(500, extractedText.Length))
});
}
// Console application example
static void BatchParsePdfs(string folderPath)
{
var pdfFiles = Directory.GetFiles(folderPath, "*.pdf");
foreach (var file in pdfFiles)
{
var pdf = PdfDocument.FromFile(file);
var text = pdf.ExtractAllText();
// Save extracted text
var textFile = Path.ChangeExtension(file, ".txt");
File.WriteAllText(textFile, text);
Console.WriteLine($"Parsed: {Path.GetFileName(file)} - {text.Length} characters");
}
}' ASP.NET Core example
Public Function ParseUploadedPdf(pdfFile As IFormFile) As IActionResult
Using stream = pdfFile.OpenReadStream()
Dim pdf = PdfDocument.FromStream(stream)
Dim extractedText = pdf.ExtractAllText()
' Process or store the extracted text
Return Json(New With {
.success = True,
.textLength = extractedText.Length,
.preview = extractedText.Substring(0, Math.Min(500, extractedText.Length))
})
End Using
End Function
' Console application example
Shared Sub BatchParsePdfs(folderPath As String)
Dim pdfFiles = Directory.GetFiles(folderPath, "*.pdf")
For Each file In pdfFiles
Dim pdf = PdfDocument.FromFile(file)
Dim text = pdf.ExtractAllText()
' Save extracted text
Dim textFile = Path.ChangeExtension(file, ".txt")
File.WriteAllText(textFile, text)
Console.WriteLine($"Parsed: {Path.GetFileName(file)} - {text.Length} characters")
Next
End Sub' ASP.NET Core example
Public Function ParseUploadedPdf(pdfFile As IFormFile) As IActionResult
Using stream = pdfFile.OpenReadStream()
Dim pdf = PdfDocument.FromStream(stream)
Dim extractedText = pdf.ExtractAllText()
' Process or store the extracted text
Return Json(New With {
.success = True,
.textLength = extractedText.Length,
.preview = extractedText.Substring(0, Math.Min(500, extractedText.Length))
})
End Using
End Function
' Console application example
Shared Sub BatchParsePdfs(folderPath As String)
Dim pdfFiles = Directory.GetFiles(folderPath, "*.pdf")
For Each file In pdfFiles
Dim pdf = PdfDocument.FromFile(file)
Dim text = pdf.ExtractAllText()
' Save extracted text
Dim textFile = Path.ChangeExtension(file, ".txt")
File.WriteAllText(textFile, text)
Console.WriteLine($"Parsed: {Path.GetFileName(file)} - {text.Length} characters")
Next
End Subこれらの例では、Webアプリケーションやバッチ処理シナリオへのPDF解析の組み込みを示しています。 高度な実装のためには、非同期およびマルチスレッド技術を探索して、複数のPDFを処理する際のパフォーマンスを向上させてください。
次に何ができるのかを見てみましょうか? こちらのチュートリアルページをご覧ください:PDFを編集
よくある質問
C#を使用してPDFからテキストを抽出するにはどうすればいいですか?
IronPDF の ExtractAllText メソッドを使用すると、C# コードの数行だけで PDF ドキュメント全体や個々のページから簡単にテキストを抽出できます。
IronPDF で PDF を解析するのにどのメソッドを使用しますか?
IronPDF の ExtractAllText メソッドを使用すると、.NET アプリケーションで PDF ドキュメントから効率的にテキストを抽出できます。
IronPDF は PDF の特定のページからテキストを抽出できますか?
はい、IronPDF は ExtractTextFromPage メソッドを使用して特定のページからテキストを抽出することをサポートしており、ターゲットPDFテキストの抽出に対して柔軟です。
IronPDF はパスワード保護された PDF からテキストを抽出することをサポートしていますか?
はい、IronPDF はドキュメントを開く際に正しいパスワードを提供することで、パスワード保護されたPDF からテキストを抽出することができます。
IronPDF は URL から取得した PDF を解析できますか?
はい。IronPDF の PdfDocument.FromUrl メソッドを使用して URL から直接 PDF を解析し、その後 ExtractAllText を使用してテキストを抽出できます。
IronPDF は、スキャンされたドキュメントからのテキスト抽出をどのように処理しますか?
PDF がスキャンされたドキュメントの場合、IronPDF は (IronOcrと共に) OCR 機能を利用して、そのような画像ベースのPDFからテキストを抽出することができます。
IronPDF を使用してPDFから特定のコンテンツを抽出およびフィルター処理することは可能ですか?
はい、IronPDFを使用するとすべてのテキストを抽出し、正規表現やカスタムロジックを使用して、請求書番号や合計のような特定のコンテンツをフィルターして探し出すことができます。
IronPDFを使用してPDF解析機能をウェブアプリケーションに統合するにはどうすればよいですか?
ASP.NET Core などのウェブアプリケーションに IronPDF の解析機能を統合するには、PDF入力ストリームを読み込み、ExtractAllText を使用して抽出されたコンテンツを処理または表示してください。
IronPDF が提供する高度なテキスト抽出機能はどのようなものですか?
IronPDF は、特定のページ範囲からのテキスト解析、レイヤード PDF の処理、非同期やマルチスレッドを活用したパフォーマンス向上などの高度な機能を提供します。
IronPDF はテキストを抽出する際に元のPDF形式を維持できますか?
はい、IronPDF はテキストを抽出する際にPDFの元の形式と構造を保持するよう設計されており、ドキュメント処理および分析タスクに適しています。
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

