问题描述
我正在尝试使用PDFBox提取PDF文件中的所有图像。对于包含jpeg和png图像的pdf,它的工作效果很好。但是它不适用于Openjpeg2000图像。我收到以下异常: 出现以下错误:
org.apache.pdfBox.contentstream.PDFStreamEngine operatorException
SEVERE: Cannot read jpeg2000 image: Java Advanced Imaging (JAI) Image I/O Tools are not installed
在所有版本的PDFBox中,都会出现相同的异常。也尝试过使用独立的jar。
我也在pom.xml中包括了必要的依赖项。
<dependency>
<groupId>org.apache.pdfBox</groupId>
<artifactId>jbig2-imageio</artifactId>
</dependency>
<!-- For legal reasons (incompatible license),these two dependencies
are to be used only in the tests and may not be distributed. -->
<dependency>
<groupId>com.github.jai-imageio</groupId>
<artifactId>jai-imageio-core</artifactId>
</dependency>
<dependency>
<groupId>com.github.jai-imageio</groupId>
<artifactId>jai-imageio-jpeg2000</artifactId>
</dependency>
任何帮助将不胜感激。
解决方法
将与映像相关的.jar文件复制到lib子目录中,然后使用以下命令行:
java -cp "pdfbox-app-2.0.21.jar;lib/*" org.apache.pdfbox.tools.PDFBox ExtractImages <parameters>
使用“;”在Windows上,在Linux上为“:”。
org.apache.pdfbox.tools.PDFBox
是主类的名称。