PDFBox:提取图片 JPEG2000 图片无法提取

huangapple go评论100阅读模式
英文:

PDFBox: ExtractImages JPEG2000 images not extracting

问题

我正在尝试使用PDFBox从PDF文件中提取所有图像。对于包含JPEG和PNG图像的PDF,它运行良好。但对于OpenJPEG2000图像,它无法正常工作,我遇到了以下异常:

获取到以下错误:

  1. org.apache.pdfbox.contentstream.PDFStreamEngine operatorException
  2. SEVERE: 无法读取JPEG2000图像:未安装Java Advanced Imaging (JAI) Image I/O工具

在所有版本的PDFBox中,都出现了相同的异常。也尝试过使用独立的jar包。

我已经在pom.xml中包含了必要的依赖。

  1. <dependency>
  2. <groupId>org.apache.pdfbox</groupId>
  3. <artifactId>jbig2-imageio</artifactId>
  4. </dependency>
  5. <!-- 由于法律原因(不兼容的许可证),这两个依赖项仅用于测试,不得分发。 -->
  6. <dependency>
  7. <groupId>com.github.jai-imageio</groupId>
  8. <artifactId>jai-imageio-core</artifactId>
  9. </dependency>
  10. <dependency>
  11. <groupId>com.github.jai-imageio</groupId>
  12. <artifactId>jai-imageio-jpeg2000</artifactId>
  13. </dependency>

将不胜感激地接受任何帮助。

英文:

I am trying to extract all the images in a PDF file using PDFBox. Its working fine for the pdf containing jpeg and png images. But it is not working for OpenJPEG2000 images. I am getting the below exception:
Getting the below error:

  1. org.apache.pdfbox.contentstream.PDFStreamEngine operatorException
  2. SEVERE: Cannot read JPEG2000 image: Java Advanced Imaging (JAI) Image I/O Tools are not installed

In all version of PDFBox, same exception is coming. Tried with standalone jar as well.

I included the necessary dependencies in pom.xml as well.

  1. &lt;dependency&gt;
  2. &lt;groupId&gt;org.apache.pdfbox&lt;/groupId&gt;
  3. &lt;artifactId&gt;jbig2-imageio&lt;/artifactId&gt;
  4. &lt;/dependency&gt;
  5. &lt;!-- For legal reasons (incompatible license), these two dependencies
  6. are to be used only in the tests and may not be distributed. --&gt;
  7. &lt;dependency&gt;
  8. &lt;groupId&gt;com.github.jai-imageio&lt;/groupId&gt;
  9. &lt;artifactId&gt;jai-imageio-core&lt;/artifactId&gt;
  10. &lt;/dependency&gt;
  11. &lt;dependency&gt;
  12. &lt;groupId&gt;com.github.jai-imageio&lt;/groupId&gt;
  13. &lt;artifactId&gt;jai-imageio-jpeg2000&lt;/artifactId&gt;
  14. &lt;/dependency&gt;

Any help will be appreciated.

答案1

得分: 1

将与图像处理相关的 .jar 文件复制到 lib 子目录中,然后使用以下命令行:

  1. java -cp "pdfbox-app-2.0.21.jar;lib/*" org.apache.pdfbox.tools.PDFBox ExtractImages <parameters>

在 Windows 系统中使用分号 ";",在 Linux 系统中使用冒号 ":"。

org.apache.pdfbox.tools.PDFBox 是主类的名称。

英文:

Copy the imageing related .jar files into the lib subdirectory, and then use this command line:

  1. java -cp &quot;pdfbox-app-2.0.21.jar;lib/*&quot; org.apache.pdfbox.tools.PDFBox ExtractImages &lt;parameters&gt;

Use ";" on windows, ":" on linux.

org.apache.pdfbox.tools.PDFBox is the name of the main class.

huangapple
  • 本文由 发表于 2020年9月29日 22:18:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/64121520.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定