gpt4 book ai didi

java - 异常转换器 com.itextpdf.text.pdf.parser.InlineImageUtils$InlineImageParseException : Could not find image data or EI 420

转载 作者:行者123 更新时间:2023-12-01 11:29:26 26 4
gpt4 key购买 nike

我正在使用iText从PDF中提取文本,但是,我遇到了以下异常,并且无法通过try/catch(Exception e)捕获它,我已在此处附加了文件,实际上我不太关心我是否可以从中提取文本,我只想知道如何捕获异常。

异常:

ExceptionConverter: com.itextpdf.text.pdf.parser.InlineImageUtils$InlineImageParseException: Could not find image data or EI
420
at com.itextpdf.text.pdf.parser.InlineImageUtils.parseInlineImageSamples(InlineImageUtils.java:386)
at com.itextpdf.text.pdf.parser.InlineImageUtils.parseInlineImage(InlineImageUtils.java:156)
at com.itextpdf.text.pdf.parser.PdfContentStreamProcessor.processContent(PdfContentStreamProcessor.java:427)
at com.itextpdf.text.pdf.parser.PdfReaderContentParser.processContent(PdfReaderContentParser.java:80)
at com.itextpdf.text.pdf.parser.PdfTextExtractor.getTextFromPage(PdfTextExtractor.java:74)

文件:https://www.dropbox.com/s/4l4ioqzpcca05vc/Understanding%20the%20High%20Photocatalytic%20Activity%20of%20%28B%2C%20Ag%29-Codopeda312205c_si_001.pdf?dl=0

最佳答案

有问题的内联图像是

q 12 0 0 1.5 598.5 2905.5 cm
BI
/CS/RGB
/W 8
/H 1
/BPC 8
/F[/A85
/Fl]
/DP[null
<</Predictor 15
/Columns 8
/Colors 3>>]
ID
Gar9F/1Xl3A2+09nF?)T!(_,53r~>
EI Q

第 5 页。不幸的是,null 被解析为值为“null”的 PdfLiteral,而不是解析为 PdfNull 实例。因此,PdfReader.decodeBytes() 抛出异常

PdfObject dpEntry = getPdfObject(dp.get(j));
if (dpEntry instanceof PdfDictionary){
decodeParams = (PdfDictionary)dpEntry;
} else if (dpEntry == null || dpEntry instanceof PdfNull) {
decodeParams = null;
} else {
throw new UnsupportedPdfException(MessageLocalization.getComposedMessage("the.decode.parameter.type.1.is.not.supported", dpEntry.getClass().toString()));
}

更换

} else if (dpEntry == null || dpEntry instanceof PdfNull) {

} else if (dpEntry == null || dpEntry instanceof PdfNull || (dpEntry instanceof PdfLiteral && Arrays.equals("null".getBytes(), ((PdfLiteral)dpEntry).getBytes()))) {

使代码适用于 OP 的 PDF。

关于java - 异常转换器 com.itextpdf.text.pdf.parser.InlineImageUtils$InlineImageParseException : Could not find image data or EI 420,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30536032/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com