使用 GroupDocs for Java 與 Aspose 的文件管理 OCR

在本指南中,您將了解 如何使用 GroupDocs 為您的 Java 應用程式加入 OCR 驅動的搜尋,這是任何現代 文件管理 OCR 解決方案的核心功能。結合 GroupDocs.Search 與 Aspose.OCR,您可以將基於影像的內容轉換為可搜尋的文字,使文件管理系統對最終使用者更有價值。我們將逐步說明設定、索引、搜尋以及自訂 OCR 整合,並提供可直接複製到專案中的清晰範例。

快速解答

  • 哪個函式庫提供 OCR 索引? GroupDocs.Search paired with Aspose.OCR.
  • 需要哪個 Java 版本? JDK 8 or higher.
  • 我需要授權嗎? 提供免費試用;正式上線需購買授權。
  • 我可以同時索引獨立與嵌入的影像嗎? 可以,請在 IndexingOptions 中啟用兩個選項。
  • 是否支援多執行緒? 可以,您可以將大型資料集的索引工作平行化。

什麼是文件管理 OCR?

文件管理 OCR 會從影像(包括掃描的 PDF)中提取文字,並將其儲存於可搜尋的索引中。GroupDocs.Search 負責索引與查詢執行,而 Aspose.OCR 則執行實際的字元辨識,為您提供完整的 文件管理 OCR 流程。

為什麼在 Java 中使用 GroupDocs 進行 OCR 索引?

  • 高精度,得益於 Aspose 先進的 OCR 引擎。
  • 無縫的 Java 整合,透過 Maven 或直接使用 JAR。
  • 彈性設定,支援獨立或嵌入的影像。
  • 可擴展效能,支援多執行緒與記憶體最佳化。
  • 企業級授權選項,適用於正式部署。

前置條件

  • GroupDocs.Search ≥ 25.4
  • Aspose.OCR (latest version)
  • JDK 8+ 以及 IDE(IntelliJ、Eclipse、NetBeans)
  • 具備基本的 Java 知識;Maven 有助但非必須

設定 GroupDocs.Search(Java 版)

使用 Maven

Add the repository and dependency to your pom.xml:

<repositories>
    <repository>
        <id>repository.groupdocs.com</id>
        <name>GroupDocs Repository</name>
        <url>https://releases.groupdocs.com/search/java/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>com.groupdocs</groupId>
        <artifactId>groupdocs-search</artifactId>
        <version>25.4</version>
    </dependency>
</dependencies>

直接下載

或者,從 GroupDocs releases 下載最新的 GroupDocs.Search for Java 版本。

取得授權

  • Free Trial – 免費試用所有功能。
  • Temporary License – 延長測試期間。
  • Purchase – 正式部署時必須購買。

基本初始化與設定

Create an index folder and initialize the Index object:

import com.groupdocs.search.Index;
// Specify the directory where the index will be stored.
String indexFolder = "YOUR_OUTPUT_DIRECTORY/OcrSupport";
// Create an instance of Index class at the specified location.
Index index = new Index(indexFolder);

如何使用 GroupDocs 進行 OCR 索引

建立索引

First, set up the folder that will hold the index files:

String indexFolder = "YOUR_OUTPUT_DIRECTORY/OcrSupport";
Index index = new Index(indexFolder);

設定 OCR 索引選項

Enable OCR for both separate and embedded images, and plug in a custom OCR connector:

import com.groupdocs.search.options.IndexingOptions;
IndexingOptions options = new IndexingOptions();
options.getOcrIndexingOptions().setEnabledForSeparateImages(true);
options.getOcrIndexingOptions().setEnabledForEmbeddedImages(true);
// Set a custom OCR connector.
options.getOcrIndexingOptions().setOcrConnector(new OcrConnector());

索引文件

Add your source documents (PDFs, Word files, images, etc.) to the index:

String documentsFolder = "YOUR_DOCUMENT_DIRECTORY";
index.add(documentsFolder, options);

在索引中搜尋

Run a search query against the indexed content:

import com.groupdocs.search.results.SearchResult;
String query = "water";
SearchResult result = index.search(query);

實作 OCR 連接器

Use Aspose.OCR to recognize text from images. Implement the IOcrConnector interface as shown:

import com.groupdocs.search.options.IOcrConnector;
import com.groupdocs.search.options.OcrContext;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import com.aspose.ocr.AsposeOCR;

public class OcrConnector implements IOcrConnector {
    @Override
    public final String recognize(OcrContext context) {
        if (null == context.getImageLocation()) {
            throw new RuntimeException("The image type is not supported: " + context.getImageLocation());
        }
        
        BufferedImage image = ImageIO.read(context.getImageLocation().toFile());
        AsposeOCR api = new AsposeOCR();
        String text = api.RecognizePage(image);
        return text;
    }
}

實務應用

  1. Document Management Systems – 快速檢索包含掃描影像的文件。
  2. Archival Retrieval – 在龐大的檔案庫中定位歷史紀錄。
  3. Legal Document Analysis – 搜尋包含掃描簽名或圖表的合約與證據。
  4. Medical Records Search – 索引患者表單、實驗結果與 X‑ray 註解。

效能考量

  • Index Size – 排除不必要的中繼資料,以保持索引精簡。
  • Multi‑Threading – 以平行方式處理大量批次,加速索引。
  • Memory Management – 處理高解析度影像時,監控 JVM 堆積記憶體。

常見問題與解決方案

  • License Errors – 確認正確的授權檔案已放置於應用程式的工作目錄。
  • Missing Images – 檢查影像路徑是否可存取且為支援格式(PNG、JPEG、BMP)。
  • Out‑Of‑Memory – 增加 JVM 堆積記憶體 (-Xmx) 或將文件分成較小批次處理。

常見問答

Q: 如何解決 GroupDocs.Search 的授權問題?
A: 從 GroupDocs website 取得臨時授權,以解鎖全部功能。

Q: 處理大型文件索引的最佳方式是什麼?
A: 使用多執行緒與批次處理,以提升效能並減少記憶體壓力。

Q: 我可以在 GroupDocs.Search 中進一步自訂 OCR 設定嗎?
A: 可以,IndexingOptions 允許您微調 OCR 行為,例如語言選擇與影像前處理。

Q: 使用 GroupDocs.Search 時有哪些常見的故障排除技巧?
A: 再次確認目錄路徑、確保所有相依項皆已存在,並檢查日誌輸出是否有缺少檔案。

Q: 如何將 Aspose.OCR 整合到現有的 Java 應用程式中?
A: 如上所示實作 IOcrConnector 介面,並確保正確處理影像輸入。

資源


最後更新: 2026-03-20
測試環境: GroupDocs.Search 25.4、Aspose.OCR 最新版
作者: GroupDocs