我有一些由未知来源生成的文件在PDF浏览器(Reader / Foxit)中打开很好但iText无法处理它们 . 对于特定文件我得到:
Exception in thread "main" java.lang.IllegalArgumentException: Unexpected colorspace /CS0
at com.itextpdf.text.pdf.parser.InlineImageUtils.getComponentsPerPixel(InlineImageUtils.java:238)
at com.itextpdf.text.pdf.parser.InlineImageUtils.computeBytesPerRow(InlineImageUtils.java:251)
at com.itextpdf.text.pdf.parser.InlineImageUtils.parseUnfilteredSamples(InlineImageUtils.java:280)
at com.itextpdf.text.pdf.parser.InlineImageUtils.parseInlineImageSamples(InlineImageUtils.java:320)
at com.itextpdf.text.pdf.parser.InlineImageUtils.parseInlineImage(InlineImageUtils.java:153)
at com.itextpdf.text.pdf.parser.PdfContentStreamProcessor.processContent(PdfContentStreamProcessor.java:370)
at com.itextpdf.text.pdf.parser.PdfReaderContentParser.processContent(PdfReaderContentParser.java:79)
有时/ CS0颜色空间变为/ CS1到/ CS9(或类似的东西) .
这是一个iText错误(我使用的是java 1.7,iText 5.4.1)还是我的pdf文件坏了?即使pdf文件坏了,我有什么方法可以修复它们吗? (Adobe Reader似乎以某种方式这样做,但不幸的是打开文件并再次保存它不起作用) .
1 回答
我不熟悉PDF规范,因此我不知道我使用过的PDF是否有效 . 然而,我确实通过在文件com.itextpdf.text.pdf.parser.InlineIamgeUtils方法getComponentsPerPixel(...)中更改iText来解决问题:
至