IronOCR 操作指南 流 如何使用 IronOCR 在 C# 中讀取 PDF Curtis Chau 更新:7月 22, 2025 下載 IronOCR NuGet 下載 DLL 下載 Windows 安裝程式 開始免費試用 法學碩士副本 法學碩士副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在雙子座打開 請向 Gemini 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 This article was translated from English: Does it need improvement? Translated View the article in English PDF是"便攜式文件格式"(Portable Document Format)的縮寫。它是由Adobe公司開發的一種文件格式,無論使用何種應用程式和平台創建,都能保留原始文件的字體、圖像、圖形和佈局。 PDF 文件通常用於以一致的格式共用和檢視文檔,而無需考慮開啟它們的軟體或硬體。 IronOcr 可以輕鬆處理各種版本的 PDF 文件。 快速入門:幾秒鐘內完成 PDF 檔案的 OCR 識別 使用 IronOCR 快速設定 OCR,只需建立一個指向 PDF 的 OcrPdfInput,然後呼叫 Read 即可—無需複雜的配置。 這個單行範例展示了使用 IronOCR 從 PDF 中提取文字是多麼容易。 立即開始使用 NuGet 建立 PDF 檔案: 使用 NuGet 套件管理器安裝 IronOCR PM > Install-Package IronOcr 複製並運行這段程式碼。 using var result = new IronOcr.IronTesseract().Read(new IronOcr.OcrPdfInput("document.pdf", PdfContents.TextAndImages)); 部署到您的生產環境進行測試 立即開始在您的專案中使用 IronOCR,免費試用! 免費試用30天 最小工作流程(5 個步驟) 下載用於讀取 PDF 的 C# 庫 準備要閱讀的 PDF 文件 使用 PDF 檔案路徑建立OcrPdfInput對象 使用Read方法對匯入的 PDF 檔案執行 OCR 操作。 通過提供頁面索引列表來閱讀特定頁面 閱讀 PDF 範例 首先實例化 IronTesseract 類別以執行 OCR。 然後,使用"using"語句建立一個OcrPdfInput對象,並將PDF檔案路徑傳遞給它。 最後,使用Read方法執行 OCR。 :path=/static-assets/ocr/content-code-examples/how-to/input-pdfs-read-pdf.cs using IronOcr; // Instantiate IronTesseract IronTesseract ocrTesseract = new IronTesseract(); // Add PDF using var pdfInput = new OcrPdfInput("Potter.pdf"); // Perform OCR OcrResult ocrResult = ocrTesseract.Read(pdfInput); Imports IronOcr ' Instantiate IronTesseract Private ocrTesseract As New IronTesseract() ' Add PDF Private pdfInput = New OcrPdfInput("Potter.pdf") ' Perform OCR Private ocrResult As OcrResult = ocrTesseract.Read(pdfInput) $vbLabelText $csharpLabel 大多數情況下,無需指定 DPI 屬性。 但是,在建構OcrPdfInput時提供較高的 DPI 值可以提高讀取精度。 閱讀 PDF 頁面範例 在讀取 PDF 文件中的特定頁面時,使用者可以指定要匯入的頁面索引號。 為此,在建構OcrPdfInput時,將頁面索引清單傳遞給 PageIndices 參數。 請注意,頁面索引採用從零開始的編號。 :path=/static-assets/ocr/content-code-examples/how-to/input-pdfs-read-pdf-pages.cs using IronOcr; using System.Collections.Generic; // Instantiate IronTesseract IronTesseract ocrTesseract = new IronTesseract(); // Create page indices list List<int> pageIndices = new List<int>() { 0, 2 }; // Add PDF using var pdfInput = new OcrPdfInput("Potter.pdf", PageIndices: pageIndices); // Perform OCR OcrResult ocrResult = ocrTesseract.Read(pdfInput); Imports IronOcr Imports System.Collections.Generic ' Instantiate IronTesseract Private ocrTesseract As New IronTesseract() ' Create page indices list Private pageIndices As New List(Of Integer)() From {0, 2} ' Add PDF Private pdfInput = New OcrPdfInput("Potter.pdf", PageIndices:= pageIndices) ' Perform OCR Private ocrResult As OcrResult = ocrTesseract.Read(pdfInput) $vbLabelText $csharpLabel 指定掃描區域 透過縮小閱讀範圍,可以顯著提高閱讀效率。 為此,您可以指定需要讀取的匯入 PDF 的確切區域。 在下面的程式碼範例中,我指示 IronOcr 只專注於提取章節編號和標題。 :path=/static-assets/ocr/content-code-examples/how-to/input-pdfs-read-specific-region.cs using IronOcr; using IronSoftware.Drawing; using System; // Instantiate IronTesseract IronTesseract ocrTesseract = new IronTesseract(); // Specify crop regions Rectangle[] scanRegions = { new Rectangle(550, 100, 600, 300) }; // Add PDF using (var pdfInput = new OcrPdfInput("Potter.pdf", ContentAreas: scanRegions)) { // Perform OCR OcrResult ocrResult = ocrTesseract.Read(pdfInput); // Output the result to console Console.WriteLine(ocrResult.Text); } Imports IronOcr Imports IronSoftware.Drawing Imports System ' Instantiate IronTesseract Private ocrTesseract As New IronTesseract() ' Specify crop regions Private scanRegions() As Rectangle = { New Rectangle(550, 100, 600, 300) } ' Add PDF Using pdfInput = New OcrPdfInput("Potter.pdf", ContentAreas:= scanRegions) ' Perform OCR Dim ocrResult As OcrResult = ocrTesseract.Read(pdfInput) ' Output the result to console Console.WriteLine(ocrResult.Text) End Using $vbLabelText $csharpLabel OCR結果 常見問題解答 我如何在 C# 中閱讀 PDF 文件? 您可以使用 IronOCR 在 C# 中閱讀 PDF 文件。首先實例化 IronTesseract 類,然後使用 'using' 語句創建帶有文件路徑的 OcrPdfInput 物件。最後,應用 Read 方法對文件執行 OCR。 需要哪些步驟才能對 PDF 的特定頁面執行 OCR? 要使用 IronOCR 對 PDF 的特定頁面執行 OCR,請在構建 OcrPdfInput 時將頁面索引列表傳遞給 PageIndices 參數。IronOCR 中的頁面索引從零開始計數,因此首頁的索引為 0。 我如何提高 PDF 的 OCR 準確性? 在 IronOCR 中,您可以在構建 OcrPdfInput 時指定高 DPI 以提高 PDF 的 OCR 準確性。雖然通常沒必要,但較高的 DPI 可以提高閱讀精度。 是否可以選擇 PDF 的特定區域進行 OCR 處理? 是的,使用 IronOCR,您可以選擇 PDF 的特定區域進行 OCR 處理,通過使用 SelectRegion 方法。這使您可以聚焦於提取定義區域的內容,提高效率。 在閱讀 PDF 頁面時零基編號有什麼意義? 在 IronOCR 中,閱讀 PDF 頁面時使用零基編號指定頁面索引。這意味著首頁的索引為 0,幫助準確指定要處理的頁面。 在對 PDF 執行 OCR 時,我需要手動管理資源嗎? 使用 IronOCR 時,建議在使用 OcrInput 物件時使用 'using' 語句。這可確保在 OCR 過程完成後正確處理資源。 如何開始使用 IronOCR 進行 PDF 閱讀? 要開始使用 IronOCR 進行 PDF 閱讀,從 NuGet 下載 C# 程式庫,準備您的 PDF,使用文件路徑構建 OcrPdfInput 物件,並使用 Read 方法進行 OCR 處理。 Curtis Chau 立即與工程團隊聊天 技術作家 Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。 審核人 Jeffrey T. Fritz 首席程序经理 - .NET 社区团队 Jeff 也是 .NET 和 Visual Studio 团队的首席程序经理。他是 .NET Conf 虚拟会议系列的执行制作人,并主持“Fritz 和朋友”这一每周两次的开发者的直播节目,在节目上讨论技术并与观众一起编写代码。Jeff 撰写研讨会、主持演讲,并计划大型 Microsoft 开发者活动(包括 Microsoft Build、Microsoft Ignite、.NET Conf 和 Microsoft MVP Summit)的内容。 準備好開始了嗎? Nuget 下載 5,167,857 | Version: 2025.11 剛發表 免費下載 NuGet 下載總數:5,167,857 檢視授權