IRONOCRの使い方 C# PDF フォームフィールドを読む:プログラムでフォームデータを抽出する Kannapat Udonpant 更新日:2025年12月19日 IronOCR をダウンロード NuGet ダウンロード DLL ダウンロード Windows 版 無料トライアル LLM向けのコピー LLM向けのコピー LLM 用の Markdown としてページをコピーする ChatGPTで開く このページについてChatGPTに質問する ジェミニで開く このページについてGeminiに問い合わせる Grokで開く このページについてGrokに質問する 困惑の中で開く このページについてPerplexityに問い合わせる 共有する Facebook で共有 Xでシェア(Twitter) LinkedIn で共有 URLをコピー 記事をメールで送る IronPDF を使用すると、テキスト フィールド、チェック ボックス、ラジオ ボタン、ドロップダウンをプログラムで読み取り、簡単なコードを使用して C# の PDF フォームからデータを抽出できます。 これにより、手動によるデータ入力が不要になり、フォーム処理ワークフローが数秒で自動化されます。 PDFフォームを扱うことは、開発者にとって非常に困難なことがあります。 求人応募、アンケート回答、保険金請求などを処理する場合、フォームのデータを手動でコピーすると時間がかかり、間違いが発生しやすくなります。 IronPDFを使用すると、そのような面倒な作業を省略し、コードを数行書くだけでPDFドキュメント内のインタラクティブフォームフィールドから値を取得できます。 以前は時間がかかっていた作業を数秒でできます。 この記事では、C# のフォーム オブジェクトを使用して、単純なフォームからすべてのフィールドを取得する方法を説明します。 サンプルコードでは、各フィールドをループしてその値を抽出する方法を示しています。 使い方は簡単で、扱いにくい PDF ビューアを操作したり、隠れた書式設定の問題に対処したりする必要はありません。 DevOpsエンジニアにとって、IronPDF のコンテナ化に適した設計は、複雑なネイティブ依存関係に悩まされることなく、Docker でフォーム処理サービスを展開できることを意味します。 IronPDF を使い始めるにはどうすればいいですか? PDFフォームフィールド抽出のためのIronPDFのセットアップには最小限の構成が必要です。 NuGetパッケージマネージャーを使用してライブラリをインストールしてください: Install-Package IronPDF またはVisual StudioのパッケージマネージャーUIを通して。 IronPdfはWindows、Linux、macOS、Dockerコンテナをサポートし、様々なデプロイシナリオに対応します。 詳細な設定方法については、IronPDFドキュメントを参照してください。 コンテナ化されたデプロイメントの場合、IronPDF は合理化された Docker セットアップを提供します。 FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base WORKDIR /app # Install dependencies for IronPDF on Linux RUN apt-get update && apt-get install -y \ libgdiplus \ libc6-dev \ && rm -rf /var/lib/apt/lists/* FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src COPY ["YourProject.csproj", "."] RUN dotnet restore "YourProject.csproj" COPY . . RUN dotnet build "YourProject.csproj" -c Release -o /app/build FROM build AS publish RUN dotnet publish "YourProject.csproj" -c Release -o /app/publish FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "YourProject.dll"] IronPDF で PDF フォームデータを読み取るにはどうすればいいですか? 次のコードは、IronPDF を使用して既存の PDF ファイルからすべてのフィールドを読み取る方法を示しています。 using IronPdf; using System; class Program { static void Main(string[] args) { // Load the PDF document containing interactive form fields PdfDocument pdf = PdfDocument.FromFile("application_form.pdf"); // Access the form object and iterate through all fields var form = pdf.Form; foreach (var field in form) { Console.WriteLine($"Field Name: {field.Name}"); Console.WriteLine($"Field Value: {field.Value}"); Console.WriteLine($"Field Type: {field.GetType().Name}"); Console.WriteLine("---"); } } } using IronPdf; using System; class Program { static void Main(string[] args) { // Load the PDF document containing interactive form fields PdfDocument pdf = PdfDocument.FromFile("application_form.pdf"); // Access the form object and iterate through all fields var form = pdf.Form; foreach (var field in form) { Console.WriteLine($"Field Name: {field.Name}"); Console.WriteLine($"Field Value: {field.Value}"); Console.WriteLine($"Field Type: {field.GetType().Name}"); Console.WriteLine("---"); } } } Imports IronPdf Imports System Class Program Shared Sub Main(args As String()) ' Load the PDF document containing interactive form fields Dim pdf As PdfDocument = PdfDocument.FromFile("application_form.pdf") ' Access the form object and iterate through all fields Dim form = pdf.Form For Each field In form Console.WriteLine($"Field Name: {field.Name}") Console.WriteLine($"Field Value: {field.Value}") Console.WriteLine($"Field Type: {field.GetType().Name}") Console.WriteLine("---") Next End Sub End Class $vbLabelText $csharpLabel このコードは、簡単なフォームを含むPDFファイルをロードし、各フォームフィールドを反復処理し、フィールド名、フィールド値、およびフィールドタイプを出力します。 PdfDocument.FromFile()メソッドはPDFドキュメントを解析し、Formプロパティはすべてのインタラクティブなフォームフィールドへのアクセスを提供します。 各フィールドは、そのフィールド タイプに固有のプロパティを公開し、正確なデータ抽出を可能にします。 より複雑なシナリオについては、IronPDF APIリファレンスで高度なフォーム操作方法をご覧ください。 出力 ! 左側に入力されたフィールドを持つ PDF 求人応募フォーム、右側に抽出されたフォーム フィールド データを表示する Visual Studio デバッグ コンソールを表示する分割画面 どのような異なるフォーム フィールド タイプを読み取ることができますか? PDFフォームにはさまざまなフィールドタイプがあり、それぞれに特定の取り扱いが必要です。 IronPDFはフィールドタイプを自動的に識別し、特定のアクセスを提供します。 using IronPdf; using System.Collections.Generic; using System.Linq; PdfDocument pdf = PdfDocument.FromFile("complex_form.pdf"); // Text fields - standard input boxes var nameField = pdf.Form.FindFormField("fullName"); string userName = nameField.Value; // Checkboxes - binary selections var agreeCheckbox = pdf.Form.FindFormField("termsAccepted"); bool isChecked = agreeCheckbox.Value == "Yes"; // Radio buttons - single choice from group var genderRadio = pdf.Form.FindFormField("gender"); string selectedGender = genderRadio.Value; // Dropdown lists (ComboBox) - predefined options var countryDropdown = pdf.Form.FindFormField("country"); string selectedCountry = countryDropdown.Value; // Access all available options var availableCountries = countryDropdown.Choices; // Multi-line text areas var commentsField = pdf.Form.FindFormField("comments_part1_513"); string userComments = commentsField.Value; // Grab all fields that start with "interests_" var interestFields = pdf.Form .Where(f => f.Name.StartsWith("interests_")); // Collect checked interests List<string> selectedInterests = new List<string>(); foreach (var field in interestFields) { if (field.Value == "Yes") // checkboxes are "Yes" if checked { // Extract the interest name from the field name string interestName = field.Name.Replace("interests_", ""); selectedInterests.Add(interestName); } } using IronPdf; using System.Collections.Generic; using System.Linq; PdfDocument pdf = PdfDocument.FromFile("complex_form.pdf"); // Text fields - standard input boxes var nameField = pdf.Form.FindFormField("fullName"); string userName = nameField.Value; // Checkboxes - binary selections var agreeCheckbox = pdf.Form.FindFormField("termsAccepted"); bool isChecked = agreeCheckbox.Value == "Yes"; // Radio buttons - single choice from group var genderRadio = pdf.Form.FindFormField("gender"); string selectedGender = genderRadio.Value; // Dropdown lists (ComboBox) - predefined options var countryDropdown = pdf.Form.FindFormField("country"); string selectedCountry = countryDropdown.Value; // Access all available options var availableCountries = countryDropdown.Choices; // Multi-line text areas var commentsField = pdf.Form.FindFormField("comments_part1_513"); string userComments = commentsField.Value; // Grab all fields that start with "interests_" var interestFields = pdf.Form .Where(f => f.Name.StartsWith("interests_")); // Collect checked interests List<string> selectedInterests = new List<string>(); foreach (var field in interestFields) { if (field.Value == "Yes") // checkboxes are "Yes" if checked { // Extract the interest name from the field name string interestName = field.Name.Replace("interests_", ""); selectedInterests.Add(interestName); } } Imports IronPdf Imports System.Collections.Generic Imports System.Linq Dim pdf As PdfDocument = PdfDocument.FromFile("complex_form.pdf") ' Text fields - standard input boxes Dim nameField = pdf.Form.FindFormField("fullName") Dim userName As String = nameField.Value ' Checkboxes - binary selections Dim agreeCheckbox = pdf.Form.FindFormField("termsAccepted") Dim isChecked As Boolean = agreeCheckbox.Value = "Yes" ' Radio buttons - single choice from group Dim genderRadio = pdf.Form.FindFormField("gender") Dim selectedGender As String = genderRadio.Value ' Dropdown lists (ComboBox) - predefined options Dim countryDropdown = pdf.Form.FindFormField("country") Dim selectedCountry As String = countryDropdown.Value ' Access all available options Dim availableCountries = countryDropdown.Choices ' Multi-line text areas Dim commentsField = pdf.Form.FindFormField("comments_part1_513") Dim userComments As String = commentsField.Value ' Grab all fields that start with "interests_" Dim interestFields = pdf.Form.Where(Function(f) f.Name.StartsWith("interests_")) ' Collect checked interests Dim selectedInterests As New List(Of String)() For Each field In interestFields If field.Value = "Yes" Then ' checkboxes are "Yes" if checked ' Extract the interest name from the field name Dim interestName As String = field.Name.Replace("interests_", "") selectedInterests.Add(interestName) End If Next $vbLabelText $csharpLabel FindFormField()メソッドを使用すると、名前で特定のフィールドに直接アクセスできるため、すべてのフォーム フィールドを反復処理する必要がなくなります。 チェックボックスはチェックされた場合"Yes"を返し、ラジオボタンは選択された値を返します。 ドロップダウンやリストボックスなどの選択フィールドは、Choicesプロパティを通して、フィールドの値と利用可能なすべてのオプションの両方を提供します。 この包括的なメソッドのセットにより、開発者は複雑なインタラクティブフォームからデータへのアクセスと抽出が可能になります。 複雑なフォームを扱う場合は、抽出前にIronPDF のフォーム編集機能を使用して、プログラムでフィールド値を入力または変更することを検討してください。 ここで、IronPDFがより複雑なフォームを取り扱ってフォームフィールドの値からデータを抽出することができる様子をご覧ください: ! 左側にさまざまなフィールドタイプ(テキストフィールド、チェックボックス、ラジオボタン、ドロップダウン)を含むPDF登録フォーム、右側に抽出されたフォームフィールドデータをプログラムで表示するVisual Studioデバッグコンソールを示すスクリーンショット 複数のアンケートフォームを処理するにはどうすればよいですか? 顧客調査から数百のPDFフォームを処理する必要があるシナリオを考えてみましょう。 以下のコードは、IronPDFを使用したバッチ処理を示しています: using IronPdf; using System; using System.Text; using System.IO; using System.Collections.Generic; public class SurveyProcessor { static void Main(string[] args) { ProcessSurveyBatch(@"C:\Surveys"); } public static void ProcessSurveyBatch(string folderPath) { StringBuilder csvData = new StringBuilder(); csvData.AppendLine("Date,Name,Email,Rating,Feedback"); foreach (string pdfFile in Directory.GetFiles(folderPath, "*.pdf")) { try { PdfDocument survey = PdfDocument.FromFile(pdfFile); string date = survey.Form.FindFormField("surveyDate")?.Value ?? ""; string name = survey.Form.FindFormField("customerName")?.Value ?? ""; string email = survey.Form.FindFormField("email")?.Value ?? ""; string rating = survey.Form.FindFormField("satisfaction")?.Value ?? ""; string feedback = survey.Form.FindFormField("comments")?.Value ?? ""; feedback = feedback.Replace("\n", " ").Replace("\"", "\"\""); csvData.AppendLine($"{date},{name},{email},{rating},\"{feedback}\""); } catch (Exception ex) { Console.WriteLine($"Error processing {pdfFile}: {ex.Message}"); } } File.WriteAllText("survey_results.csv", csvData.ToString()); Console.WriteLine("Survey processing complete!"); } } using IronPdf; using System; using System.Text; using System.IO; using System.Collections.Generic; public class SurveyProcessor { static void Main(string[] args) { ProcessSurveyBatch(@"C:\Surveys"); } public static void ProcessSurveyBatch(string folderPath) { StringBuilder csvData = new StringBuilder(); csvData.AppendLine("Date,Name,Email,Rating,Feedback"); foreach (string pdfFile in Directory.GetFiles(folderPath, "*.pdf")) { try { PdfDocument survey = PdfDocument.FromFile(pdfFile); string date = survey.Form.FindFormField("surveyDate")?.Value ?? ""; string name = survey.Form.FindFormField("customerName")?.Value ?? ""; string email = survey.Form.FindFormField("email")?.Value ?? ""; string rating = survey.Form.FindFormField("satisfaction")?.Value ?? ""; string feedback = survey.Form.FindFormField("comments")?.Value ?? ""; feedback = feedback.Replace("\n", " ").Replace("\"", "\"\""); csvData.AppendLine($"{date},{name},{email},{rating},\"{feedback}\""); } catch (Exception ex) { Console.WriteLine($"Error processing {pdfFile}: {ex.Message}"); } } File.WriteAllText("survey_results.csv", csvData.ToString()); Console.WriteLine("Survey processing complete!"); } } Imports IronPdf Imports System Imports System.Text Imports System.IO Imports System.Collections.Generic Public Class SurveyProcessor Shared Sub Main(args As String()) ProcessSurveyBatch("C:\Surveys") End Sub Public Shared Sub ProcessSurveyBatch(folderPath As String) Dim csvData As New StringBuilder() csvData.AppendLine("Date,Name,Email,Rating,Feedback") For Each pdfFile As String In Directory.GetFiles(folderPath, "*.pdf") Try Dim survey As PdfDocument = PdfDocument.FromFile(pdfFile) Dim [date] As String = If(survey.Form.FindFormField("surveyDate")?.Value, "") Dim name As String = If(survey.Form.FindFormField("customerName")?.Value, "") Dim email As String = If(survey.Form.FindFormField("email")?.Value, "") Dim rating As String = If(survey.Form.FindFormField("satisfaction")?.Value, "") Dim feedback As String = If(survey.Form.FindFormField("comments")?.Value, "") feedback = feedback.Replace(vbLf, " ").Replace("""", """""") csvData.AppendLine($"{[date]},{name},{email},{rating},""{feedback}""") Catch ex As Exception Console.WriteLine($"Error processing {pdfFile}: {ex.Message}") End Try Next File.WriteAllText("survey_results.csv", csvData.ToString()) Console.WriteLine("Survey processing complete!") End Sub End Class $vbLabelText $csharpLabel このバッチプロセッサは、ディレクトリからすべてのPDFアンケートフォームを読み取り、関連するフィールドデータを抽出し、結果をCSVファイルにエクスポートします。null結合演算子( ?? )により、欠落しているフィールドにデフォルト値が提供されるため、フォームが不完全な場合でも堅牢なデータ抽出が可能になります。 エラー処理により、バッチ プロセスを中断することなく問題のある PDF をキャプチャします。 スケーラブルなフォーム処理サービスを構築するにはどうすればよいですか? 大規模なフォーム処理の導入を検討しているDevOpsエンジニア向けに、PDF フォームの抽出を処理する本番環境対応の API サービスをご紹介します。 using Microsoft.AspNetCore.Mvc; using IronPdf; using System.Collections.Concurrent; [ApiController] [Route("api/[controller]")] public class FormProcessorController : ControllerBase { private static readonly ConcurrentDictionary<string, ProcessingStatus> _processingJobs = new(); [HttpPost("extract")] public async Task<IActionResult> ExtractFormData(IFormFile pdfFile) { if (pdfFile == null || pdfFile.Length == 0) return BadRequest("No file uploaded"); var jobId = Guid.NewGuid().ToString(); _processingJobs[jobId] = new ProcessingStatus { Status = "Processing" }; // Process asynchronously to avoid blocking _ = Task.Run(async () => { try { using var stream = new MemoryStream(); await pdfFile.CopyToAsync(stream); var pdf = PdfDocument.FromStream(stream); var extractedData = new Dictionary<string, string>(); foreach (var field in pdf.Form) { extractedData[field.Name] = field.Value; } _processingJobs[jobId] = new ProcessingStatus { Status = "Complete", Data = extractedData }; } catch (Exception ex) { _processingJobs[jobId] = new ProcessingStatus { Status = "Error", Error = ex.Message }; } }); return Accepted(new { jobId }); } [HttpGet("status/{jobId}")] public IActionResult GetStatus(string jobId) { if (_processingJobs.TryGetValue(jobId, out var status)) return Ok(status); return NotFound(); } [HttpGet("health")] public IActionResult HealthCheck() { return Ok(new { status = "healthy", activeJobs = _processingJobs.Count(j => j.Value.Status == "Processing"), completedJobs = _processingJobs.Count(j => j.Value.Status == "Complete") }); } } public class ProcessingStatus { public string Status { get; set; } public Dictionary<string, string> Data { get; set; } public string Error { get; set; } } using Microsoft.AspNetCore.Mvc; using IronPdf; using System.Collections.Concurrent; [ApiController] [Route("api/[controller]")] public class FormProcessorController : ControllerBase { private static readonly ConcurrentDictionary<string, ProcessingStatus> _processingJobs = new(); [HttpPost("extract")] public async Task<IActionResult> ExtractFormData(IFormFile pdfFile) { if (pdfFile == null || pdfFile.Length == 0) return BadRequest("No file uploaded"); var jobId = Guid.NewGuid().ToString(); _processingJobs[jobId] = new ProcessingStatus { Status = "Processing" }; // Process asynchronously to avoid blocking _ = Task.Run(async () => { try { using var stream = new MemoryStream(); await pdfFile.CopyToAsync(stream); var pdf = PdfDocument.FromStream(stream); var extractedData = new Dictionary<string, string>(); foreach (var field in pdf.Form) { extractedData[field.Name] = field.Value; } _processingJobs[jobId] = new ProcessingStatus { Status = "Complete", Data = extractedData }; } catch (Exception ex) { _processingJobs[jobId] = new ProcessingStatus { Status = "Error", Error = ex.Message }; } }); return Accepted(new { jobId }); } [HttpGet("status/{jobId}")] public IActionResult GetStatus(string jobId) { if (_processingJobs.TryGetValue(jobId, out var status)) return Ok(status); return NotFound(); } [HttpGet("health")] public IActionResult HealthCheck() { return Ok(new { status = "healthy", activeJobs = _processingJobs.Count(j => j.Value.Status == "Processing"), completedJobs = _processingJobs.Count(j => j.Value.Status == "Complete") }); } } public class ProcessingStatus { public string Status { get; set; } public Dictionary<string, string> Data { get; set; } public string Error { get; set; } } Imports Microsoft.AspNetCore.Mvc Imports IronPdf Imports System.Collections.Concurrent Imports System.IO Imports System.Threading.Tasks <ApiController> <Route("api/[controller]")> Public Class FormProcessorController Inherits ControllerBase Private Shared ReadOnly _processingJobs As New ConcurrentDictionary(Of String, ProcessingStatus)() <HttpPost("extract")> Public Async Function ExtractFormData(pdfFile As IFormFile) As Task(Of IActionResult) If pdfFile Is Nothing OrElse pdfFile.Length = 0 Then Return BadRequest("No file uploaded") End If Dim jobId = Guid.NewGuid().ToString() _processingJobs(jobId) = New ProcessingStatus With {.Status = "Processing"} ' Process asynchronously to avoid blocking _ = Task.Run(Async Function() Try Using stream As New MemoryStream() Await pdfFile.CopyToAsync(stream) Dim pdf = PdfDocument.FromStream(stream) Dim extractedData As New Dictionary(Of String, String)() For Each field In pdf.Form extractedData(field.Name) = field.Value Next _processingJobs(jobId) = New ProcessingStatus With { .Status = "Complete", .Data = extractedData } End Using Catch ex As Exception _processingJobs(jobId) = New ProcessingStatus With { .Status = "Error", .Error = ex.Message } End Try End Function) Return Accepted(New With {Key .jobId = jobId}) End Function <HttpGet("status/{jobId}")> Public Function GetStatus(jobId As String) As IActionResult Dim status As ProcessingStatus = Nothing If _processingJobs.TryGetValue(jobId, status) Then Return Ok(status) End If Return NotFound() End Function <HttpGet("health")> Public Function HealthCheck() As IActionResult Return Ok(New With { Key .status = "healthy", Key .activeJobs = _processingJobs.Count(Function(j) j.Value.Status = "Processing"), Key .completedJobs = _processingJobs.Count(Function(j) j.Value.Status = "Complete") }) End Function End Class Public Class ProcessingStatus Public Property Status As String Public Property Data As Dictionary(Of String, String) Public Property Error As String End Class $vbLabelText $csharpLabel この API サービスは、ジョブ トラッキングを備えた非同期フォーム処理を提供し、マイクロサービス アーキテクチャに最適です。 /healthエンドポイントにより、Kubernetes などのコンテナ オーケストレーターがサービスの健全性を監視できるようになります。 Docker Compose を使用してこのサービスをデプロイします。 version: '3.8' services: form-processor: build: . ports: - "8080:80" environment: - ASPNETCORE_ENVIRONMENT=Production - IRONPDF_LICENSE_KEY=${IRONPDF_LICENSE_KEY} healthcheck: test: ["CMD", "curl", "-f", "___PROTECTED_URL_7___"] interval: 30s timeout: 10s retries: 3 deploy: resources: limits: cpus: '2' memory: 2G reservations: cpus: '1' memory: 1G version: '3.8' services: form-processor: build: . ports: - "8080:80" environment: - ASPNETCORE_ENVIRONMENT=Production - IRONPDF_LICENSE_KEY=${IRONPDF_LICENSE_KEY} healthcheck: test: ["CMD", "curl", "-f", "___PROTECTED_URL_7___"] interval: 30s timeout: 10s retries: 3 deploy: resources: limits: cpus: '2' memory: 2G reservations: cpus: '1' memory: 1G YAML パフォーマンスとリソースの最適化はどうですか? 大量の PDF フォームを処理する場合、リソースの最適化が重要になります。 IronPDF は、スループットを最大化するためのいくつかの戦略を提供します。 using IronPdf; using System.Threading.Tasks.Dataflow; public class HighPerformanceFormProcessor { public static async Task ProcessFormsInParallel(string[] pdfPaths) { // Configure parallelism based on available CPU cores var processorCount = Environment.ProcessorCount; var actionBlock = new ActionBlock<string>( async pdfPath => await ProcessSingleForm(pdfPath), new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = processorCount, BoundedCapacity = processorCount * 2 // Prevent memory overflow }); // Feed PDFs to the processing pipeline foreach (var path in pdfPaths) { await actionBlock.SendAsync(path); } actionBlock.Complete(); await actionBlock.Completion; } private static async Task ProcessSingleForm(string pdfPath) { try { // Use async file reading to avoid blocking I/O using var fileStream = new FileStream(pdfPath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true); var pdf = PdfDocument.FromStream(fileStream); // Process form fields var results = new Dictionary<string, string>(); foreach (var field in pdf.Form) { results[field.Name] = field.Value; } // Store results (implement your storage logic) await StoreResults(Path.GetFileName(pdfPath), results); } catch (Exception ex) { // Log error (implement your logging) Console.WriteLine($"Error processing {pdfPath}: {ex.Message}"); } } private static async Task StoreResults(string fileName, Dictionary<string, string> data) { // Implement your storage logic (database, file system, cloud storage) await Task.CompletedTask; // Placeholder } } using IronPdf; using System.Threading.Tasks.Dataflow; public class HighPerformanceFormProcessor { public static async Task ProcessFormsInParallel(string[] pdfPaths) { // Configure parallelism based on available CPU cores var processorCount = Environment.ProcessorCount; var actionBlock = new ActionBlock<string>( async pdfPath => await ProcessSingleForm(pdfPath), new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = processorCount, BoundedCapacity = processorCount * 2 // Prevent memory overflow }); // Feed PDFs to the processing pipeline foreach (var path in pdfPaths) { await actionBlock.SendAsync(path); } actionBlock.Complete(); await actionBlock.Completion; } private static async Task ProcessSingleForm(string pdfPath) { try { // Use async file reading to avoid blocking I/O using var fileStream = new FileStream(pdfPath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true); var pdf = PdfDocument.FromStream(fileStream); // Process form fields var results = new Dictionary<string, string>(); foreach (var field in pdf.Form) { results[field.Name] = field.Value; } // Store results (implement your storage logic) await StoreResults(Path.GetFileName(pdfPath), results); } catch (Exception ex) { // Log error (implement your logging) Console.WriteLine($"Error processing {pdfPath}: {ex.Message}"); } } private static async Task StoreResults(string fileName, Dictionary<string, string> data) { // Implement your storage logic (database, file system, cloud storage) await Task.CompletedTask; // Placeholder } } Imports IronPdf Imports System.Threading.Tasks.Dataflow Imports System.IO Public Class HighPerformanceFormProcessor Public Shared Async Function ProcessFormsInParallel(pdfPaths As String()) As Task ' Configure parallelism based on available CPU cores Dim processorCount = Environment.ProcessorCount Dim actionBlock = New ActionBlock(Of String)( Async Function(pdfPath) Await ProcessSingleForm(pdfPath), New ExecutionDataflowBlockOptions With { .MaxDegreeOfParallelism = processorCount, .BoundedCapacity = processorCount * 2 ' Prevent memory overflow }) ' Feed PDFs to the processing pipeline For Each path In pdfPaths Await actionBlock.SendAsync(path) Next actionBlock.Complete() Await actionBlock.Completion End Function Private Shared Async Function ProcessSingleForm(pdfPath As String) As Task Try ' Use async file reading to avoid blocking I/O Using fileStream As New FileStream(pdfPath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, True) Dim pdf = PdfDocument.FromStream(fileStream) ' Process form fields Dim results = New Dictionary(Of String, String)() For Each field In pdf.Form results(field.Name) = field.Value Next ' Store results (implement your storage logic) Await StoreResults(Path.GetFileName(pdfPath), results) End Using Catch ex As Exception ' Log error (implement your logging) Console.WriteLine($"Error processing {pdfPath}: {ex.Message}") End Try End Function Private Shared Async Function StoreResults(fileName As String, data As Dictionary(Of String, String)) As Task ' Implement your storage logic (database, file system, cloud storage) Await Task.CompletedTask ' Placeholder End Function End Class $vbLabelText $csharpLabel この実装では、TPL データフローを使用して、CPU 使用率を最大化しながらメモリ枯渇を防ぐ制限付き処理パイプラインを作成します。 BoundedCapacity設定により、パイプラインが同時にメモリに読み込む PDF が多すぎないことが保証されます。これは、メモリ制限のあるコンテナ化された環境では重要です。 運用中のフォーム処理をどのように監視すればよいですか? 実稼働環境での展開では、包括的な監視により、信頼性の高いフォーム処理が保証されます。 一般的な可観測性ツールを使用してアプリケーション メトリックを統合します。 using Prometheus; using System.Diagnostics; public class MonitoredFormProcessor { private static readonly Counter ProcessedFormsCounter = Metrics .CreateCounter("pdf_forms_processed_total", "Total number of processed PDF forms"); private static readonly Histogram ProcessingDuration = Metrics .CreateHistogram("pdf_form_processing_duration_seconds", "Processing duration in seconds"); private static readonly Gauge ActiveProcessingGauge = Metrics .CreateGauge("pdf_forms_active_processing", "Number of forms currently being processed"); public async Task<FormExtractionResult> ProcessFormWithMetrics(string pdfPath) { using (ProcessingDuration.NewTimer()) { ActiveProcessingGauge.Inc(); try { var pdf = PdfDocument.FromFile(pdfPath); var result = new FormExtractionResult { FieldCount = pdf.Form.Count(), Fields = new Dictionary<string, string>() }; foreach (var field in pdf.Form) { result.Fields[field.Name] = field.Value; } ProcessedFormsCounter.Inc(); return result; } finally { ActiveProcessingGauge.Dec(); } } } } public class FormExtractionResult { public int FieldCount { get; set; } public Dictionary<string, string> Fields { get; set; } } using Prometheus; using System.Diagnostics; public class MonitoredFormProcessor { private static readonly Counter ProcessedFormsCounter = Metrics .CreateCounter("pdf_forms_processed_total", "Total number of processed PDF forms"); private static readonly Histogram ProcessingDuration = Metrics .CreateHistogram("pdf_form_processing_duration_seconds", "Processing duration in seconds"); private static readonly Gauge ActiveProcessingGauge = Metrics .CreateGauge("pdf_forms_active_processing", "Number of forms currently being processed"); public async Task<FormExtractionResult> ProcessFormWithMetrics(string pdfPath) { using (ProcessingDuration.NewTimer()) { ActiveProcessingGauge.Inc(); try { var pdf = PdfDocument.FromFile(pdfPath); var result = new FormExtractionResult { FieldCount = pdf.Form.Count(), Fields = new Dictionary<string, string>() }; foreach (var field in pdf.Form) { result.Fields[field.Name] = field.Value; } ProcessedFormsCounter.Inc(); return result; } finally { ActiveProcessingGauge.Dec(); } } } } public class FormExtractionResult { public int FieldCount { get; set; } public Dictionary<string, string> Fields { get; set; } } Imports Prometheus Imports System.Diagnostics Public Class MonitoredFormProcessor Private Shared ReadOnly ProcessedFormsCounter As Counter = Metrics.CreateCounter("pdf_forms_processed_total", "Total number of processed PDF forms") Private Shared ReadOnly ProcessingDuration As Histogram = Metrics.CreateHistogram("pdf_form_processing_duration_seconds", "Processing duration in seconds") Private Shared ReadOnly ActiveProcessingGauge As Gauge = Metrics.CreateGauge("pdf_forms_active_processing", "Number of forms currently being processed") Public Async Function ProcessFormWithMetrics(pdfPath As String) As Task(Of FormExtractionResult) Using ProcessingDuration.NewTimer() ActiveProcessingGauge.Inc() Try Dim pdf = PdfDocument.FromFile(pdfPath) Dim result As New FormExtractionResult With { .FieldCount = pdf.Form.Count(), .Fields = New Dictionary(Of String, String)() } For Each field In pdf.Form result.Fields(field.Name) = field.Value Next ProcessedFormsCounter.Inc() Return result Finally ActiveProcessingGauge.Dec() End Try End Using End Function End Class Public Class FormExtractionResult Public Property FieldCount As Integer Public Property Fields As Dictionary(Of String, String) End Class $vbLabelText $csharpLabel これらの Prometheus メトリックは Grafana ダッシュボードとシームレスに統合され、フォーム処理のパフォーマンスをリアルタイムで可視化します。 処理時間がしきい値を超えたり、エラー率が急上昇したりしたときに通知するアラート ルールを構成します。 結論 IronPDF は C# での PDF フォーム データの抽出を簡素化し、複雑なドキュメント処理を簡単なコードに変換します。 基本的なフィールド読み取りからエンタープライズ規模のバッチ処理まで、ライブラリはさまざまなフォーム タイプを効率的に処理します。 DevOpsチームにとって、IronPDF のコンテナ対応アーキテクチャと最小限の依存関係により、クラウド プラットフォーム間でのスムーズな展開が可能になります。 提供される例は、単純なコンソール アプリケーションから監視機能を備えたスケーラブルなマイクロサービスまで、実際のシナリオの実用的な実装を示しています。 アンケート処理の自動化、紙のフォームのデジタル化、ドキュメント管理システムの構築など、どのような場合でも、IronPDF はフォーム データを確実に抽出するためのツールを提供します。 クロスプラットフォーム サポートにより、開発環境、ステージング環境、運用環境全体でフォーム処理サービスが一貫して実行されます。 よくある質問 IronPDFはC#でPDFフォームフィールドを読むのにどのように役立ちますか? IronPDFはC#で記入可能なPDFからフォームフィールドのデータを抽出する合理化されたプロセスを提供し、手作業によるデータ抽出に比べて必要な時間と労力を大幅に削減します。 IronPDFを使ってどのようなPDFフォームフィールドを抽出できますか? IronPdfを使用すると、テキスト入力、チェックボックス、ドロップダウン選択などを含む様々なフォームフィールドを記入可能なPDFから抽出することができます。 なぜPDFフォームのデータ抽出を自動化することが有益なのでしょうか? IronPDFでPDFフォームのデータ抽出を自動化することで、時間を節約し、エラーを減らし、手入力の必要性をなくすことで生産性を向上させます。 IronPDFは大量のPDFフォーム処理に対応していますか? IronPdfは大量のPDFフォームを効率的に処理するように設計されており、求人応募、アンケート、その他大量のドキュメントを処理するのに理想的です。 IronPdfを使う利点は何ですか? IronPdfはヒューマンエラーを減らし、データ抽出プロセスをスピードアップし、開発者が平凡なデータ入力ではなく、より複雑なタスクに集中できるようにします。 IronPDFは異なるPDFフォーマットを扱うことができますか? IronPdfは様々なPDFフォーマットを扱うことができ、幅広い文書やフォームデザインに対応します。 IronPdfはどのようにデータ抽出の精度を向上させるのですか? IronPdfは抽出プロセスを自動化することで、手作業によるデータ入力で起こりがちなヒューマンエラーのリスクを最小限に抑え、精度を向上させます。 IronPDFを使用するプログラミング言語は何ですか? IronPDFはC#で使用するように設計されており、.NETアプリケーションでPDFドキュメントを操作したりデータを抽出したりするための強力なツールを開発者に提供します。 Kannapat Udonpant 今すぐエンジニアリングチームとチャット ソフトウェアエンジニア ソフトウェアエンジニアになる前に、Kannapatは北海道大学で環境資源の博士号を修了しました。博士号を追求する間に、彼はバイオプロダクションエンジニアリング学科の一部である車両ロボティクスラボラトリーのメンバーになりました。2022年には、C#のスキルを活用してIron Softwareのエンジニアリングチームに参加し、IronPDFに注力しています。Kannapatは、IronPDFの多くのコードを執筆している開発者から直接学んでいるため、この仕事を大切にしています。同僚から学びながら、Iron Softwareでの働く社会的側面も楽しんでいます。コードやドキュメントを書いていない時は、KannapatはPS5でゲームをしたり、『The Last of Us』を再視聴したりしていることが多いです。 関連する記事 公開日 2026年1月21日 OCR C# GitHubインテグレーション:IronOCRでテキスト認識アプリを作る OCR C# GitHubチュートリアル:IronOCRを使用してGitHubプロジェクトにテキスト認識を実装。コードサンプルとバージョン管理のヒントを含む。 詳しく読む 公開日 2026年1月21日 IronOCRを使用して.NET OCR SDKを作成する IronOCRの.NET SDKで強力なOCRソリューションを構築。シンプルなAPI、エンタープライズ機能、クロスプラットフォーム対応。 詳しく読む 更新日 2026年1月5日 PDFをOCRする方法:C# .NET OCR PDFでスキャン文書からテキストを抽出する IronOCRを使用してPDFをOCRし、スキャンした文書からテキストを抽出する方法を学びます。 詳しく読む PDFをOCRする方法:C# .NET OCR PDFでスキャン文書からテキストを抽出するC# PDFから画像を抽出する...
公開日 2026年1月21日 OCR C# GitHubインテグレーション:IronOCRでテキスト認識アプリを作る OCR C# GitHubチュートリアル:IronOCRを使用してGitHubプロジェクトにテキスト認識を実装。コードサンプルとバージョン管理のヒントを含む。 詳しく読む
公開日 2026年1月21日 IronOCRを使用して.NET OCR SDKを作成する IronOCRの.NET SDKで強力なOCRソリューションを構築。シンプルなAPI、エンタープライズ機能、クロスプラットフォーム対応。 詳しく読む
更新日 2026年1月5日 PDFをOCRする方法:C# .NET OCR PDFでスキャン文書からテキストを抽出する IronOCRを使用してPDFをOCRし、スキャンした文書からテキストを抽出する方法を学びます。 詳しく読む