英文:
How can I find out in Java if a PDF file contains a JBIG2 image?
问题
我正在使用Apache PDFBox来读取PDF文件并将其转换为JPEG图像。
import java.io.ByteArrayInputStream;
import java.awt.image.BufferedImage;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;
...
byte[] fileBytes;
...
PDDocument pdDocument = PDDocument.load(new ByteArrayInputStream(fileBytes));
BufferedImage image = new PDFRenderer(pdDocument).renderImage(0);
pdDocument.close();
有时候PDF文档包含JBIG2图像。我正在使用JBIG2 ImageIO插件来处理这样的PDF文档,这很有效。但我想在转换之后知道原始PDF文档是否包含JBIG2图像。
我查看了PDDocument Javadoc,但似乎无法找到解答这个看似简单的问题的方法:给定的PDF文档是否包含至少一个JBIG2图像?
既然我已经在使用PDFBox,最好使用PDFBox的方法来解决,但其他建议也将不胜感激。
英文:
I am using Apache PDFBox to read a PDF file and convert it into a JPEG image.
import java.io.ByteArrayInputStream;
import java.awt.image.BufferedImage;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;
...
byte[] fileBytes;
...
PDDocument pdDocument = PDDocument.load(new ByteArrayInputStream(fileBytes));
BufferedImage image = new PDFRenderer(pdDocument).renderImage(0);
pdDocument.close();
Sometimes the PDF document contains JBIG2 images. I am using the JBIG2 ImageIO Plugin for PDFBox to correctly process such PDF documents. This works fine. But I would like to know after the conversion whether the orignal PDF document contained a JBIG2 image or not.
I checked the PDDocument Javadoc, but I cannot figure out a way to answer this seemingly simple question: Does a given PDF document contain at least one JBIG2 image or not?
Since I am already using PDFBox, a solution with the means of PDFBox would be preferred, but other suggestions would also be highly appreciated.
答案1
得分: 1
从源代码下载或从这里获取ExtractImages.java
的源代码。在write2file
方法中查找以下代码行:
String suffix = pdImage.getSuffix();
现在添加一些代码,如下所示:
if ("jb2".equals(suffix))
{
// 在这里添加你的代码,比如记住这是JBIG2格式
}
然后从该方法中删除所有其他内容。
英文:
Get the source code of ExtractImages.java
from the source code download or from here. Search for this line in the write2file
method:
String suffix = pdImage.getSuffix();
now add some code like
if ("jb2".equals(suffix))
{
// do your stuff here, i.e. remember that it is JBIG2
}
then remove all the rest from that method.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论