C# PDF 解析器
This article was translated from English: Does it need improvement?
TranslatedView the article in English
擁有適當的工具,您可以輕鬆地在 C# 中處理 PDF 檔案,並使用所有適用於 .NET 應用程式所需的功能,包括使用 C# 解析 PDF 檔案的能力。 本教程將使用 IronPDF 這個 C# 函式庫,只需幾個簡單的步驟即可完成。



開始使用 IronPDF
立即在您的專案中使用IronPDF,並享受免費試用。
在 C# 中如何解析 PDF 檔案
- 下載 C# PDF 解析器庫
- 在您的 Visual Studio 中安裝
- 使用
提取所有文本
提取每一行文字的方法 - 從單頁提取所有文字使用
從頁面提取文本
方法 - 查看解析的 PDF 內容
C# 解析 PDF 檔案
解析 PDF 文件相當容易。 在下面的代碼中,我們使用 ExtractAllText
方法從整個 PDF 文件中提取每一行文本。 稍後您可以看到提取的PDF內容的並排輸出。
:path=/static-assets/pdf/content-code-examples/how-to/csharp-parse-pdf-parse-pdf.cs
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)
VB C#
查看解析的 PDF 內容
我們使用了一個 C# 表單來顯示上述代碼執行中解析的 PDF 內容。 此輸出提供了 PDF 中的確切文字,因此您可以將其用於個人或客戶的文件需求。