scala 尝试解析包含图像的文本的pdf时,使用Apache tika解析器时出现问题

yacmzcpb  于 2022-11-23  发布在  Scala
关注(0)|答案(1)|浏览(305)

I am using these two dependencies:- tika core 2.6.0 tika parser standard package 2.6.0 .Parsing is working fine for these cases:- pdf file with text. pdf file with images. text files and other extensions.
Parsing is failing with pdfparser runtime exception for the use case below:- pdf file with text inside images.
Can someone pls suggest how to resolve failed case here. Thanks
Full error Stack trace:-
org.apache.tika.exception.TikaException: Unexpected RuntimeException from org.apache.tika.parser.pdf.PDFParser@2d539b25 at org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:312) ~[org.apache.tika.tika-core-2.6.0.jar:2.6.0] at org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:298) ~[org.apache.tika.tika-core-2.6.0.jar:2.6.0] at org.apache.tika.parser.AutoDetectParser.parse(AutoDetectParser.java:175) ~[org.apache.tika.tika-core-2.6.0.jar:2.6.0] Caused by: java.lang.NullPointerException at org.apache.tika.parser.pdf.AbstractPDF2XHTML.doOCROnCurrentPage(AbstractPDF2XHTML.java:520) ~[org.apache.tika.tika-parsers-standard-package-2.6.0.jar:2.6.0] at org.apache.tika.parser.pdf.AbstractPDF2XHTML.endPage(AbstractPDF2XHTML.java:786) ~[org.apache.tika.tika-parsers-standard-package-2.6.0.jar:2.6.0] at org.apache.tika.parser.pdf.PDF2XHTML.endPage(PDF2XHTML.java:154) ~[org.apache.tika.tika-parsers-standard-package-2.6.0.jar:2.6.0] at org.apache.pdfbox.text.PDFTextStripper.processPage(PDFTextStripper.java:365) ~[org.apache.pdfbox.pdfbox-2.0.27.jar:2.0.27] at org.apache.tika.parser.pdf.PDF2XHTML.processPage(PDF2XHTML.java:137) ~[org.apache.tika.tika-parsers-standard-package-2.6.0.jar:2.6.0] at org.apache.tika.parser.pdf.AbstractPDF2XHTML.processPages(AbstractPDF2XHTML.java:1277) ~[org.apache.tika.tika-parsers-standard-package-2.6.0.jar:2.6.0] at org.apache.pdfbox.text.PDFTextStripper.writeText(PDFTextStripper.java:238) ~[org.apache.pdfbox.pdfbox-2.0.27.jar:2.0.27] at org.apache.tika.parser.pdf.PDF2XHTML.process(PDF2XHTML.java:108) ~[org.apache.tika.tika-parsers-standard-package-2.6.0.jar:2.6.0] at org.apache.tika.parser.pdf.PDFParser.parse(PDFParser.java:198) ~[org.apache.tika.tika-parsers-standard-package-2.6.0.jar:2.6.0] at org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:298) ~[org.apache.tika.tika-core-2.6.0.jar:2.6.0] ... 37 more

ao218c7q

ao218c7q1#

您应该使用不同的PDFParserConfig有两种类型的pdf文件
1.原生文件(也称为searchble)- Tika能够从原生文件中提取文本,而无需OCR
PDFParserConfig =新建的PDFParserConfig();
(假);
设置OCR策略(NO_OCR);
1.扫描文件(或转换为PDF格式的图像)- Tika必须进行OCR(使用引擎盖下的tesseract)
PDFParserConfig =新建的PDFParserConfig();
(真);
设置OCR策略(OCR_ONLY);

相关问题