无法使用 TesseractOCRConfig Apache Tika 提取扫描的 pdf [英] Unable to extract scanned pdf using TesseractOCRConfig Apache Tika
问题描述
我的 pdf 包含扫描图像,我想从中提取文本.
My pdf contains scanned images and I want to extract text from it.
我的尝试:我尝试使用 AutoDetectParsers 但没有输出.
What I tried : I tried with AutoDetectParsers but no output.
我遵循了 Apache Tika 提取中提供的解决方案扫描的 PDF 文件以及 https://issues.apache 的 Apache Tika Jira.org/jira/browse/TIKA-1729 但得到空字符串没有任何错误.
I followed the solution provided in Apache Tika extract scanned PDF files and also Apache Tika Jira at https://issues.apache.org/jira/browse/TIKA-1729 but getting empty string without any error.
我的配置:Win 7 64 位操作系统,JDK 1.8.0_45.
My configuration : Win 7 64-bit OS, JDK 1.8.0_45.
欢迎任何形式的帮助.
推荐答案
解决此问题的步骤:
使用适用于 Windows 的tesseract-ocr-setup-3.05.00dev.exe"在您的系统中安装 Tesseract:https://sourceforge.net/projects/tesseract-ocr-alt/files/ 并在您的配置中设置其位置.
Install Tesseract in your system using 'tesseract-ocr-setup-3.05.00dev.exe' for Windows from: https://sourceforge.net/projects/tesseract-ocr-alt/files/ and set its location in your config.
Java 代码:
Parser parser = new AutoDetectParser();
BodyContentHandler handler = new BodyContentHandler(Integer.MAX_VALUE);
TesseractOCRConfig config = new TesseractOCRConfig();
config.setTesseractPath(tPath);
PDFParserConfig pdfConfig = new PDFParserConfig();
pdfConfig.setExtractInlineImages(true);
pdfConfig.setExtractUniqueInlineImagesOnly(false); // set to false if pdf contains multiple images.
ParseContext parseContext = new ParseContext();
parseContext.set(TesseractOCRConfig.class, config);
parseContext.set(PDFParserConfig.class, pdfConfig);
//need to add this to make sure recursive parsing happens!
parseContext.set(Parser.class, parser);
Maven 依赖项:
Maven dependencies :
<代码><依赖项><依赖><groupId>org.apache.tika</groupId><artifactId>tika-parsers</artifactId><version>1.13</version></依赖><依赖><groupId>com.levigo.jbig2</groupId><artifactId>levigo-jbig2-imageio</artifactId><version>1.6.5</version></依赖><依赖><groupId>com.github.jai-imageio</groupId><artifactId>jai-imageio-core</artifactId><version>1.3.1</version></依赖></dependencies>
我认为这可能会有所帮助.谢谢.
I think it may be helpful. Thanks.
这篇关于无法使用 TesseractOCRConfig Apache Tika 提取扫描的 pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!