【发布时间】:2012-02-01 01:45:39
【问题描述】:
我正在尝试使用 pdfbox 从 pdf 中提取图像。示例pdfhere
但我只得到空白图像。
我正在尝试的代码:-
public static void main(String[] args) {
PDFImageExtract obj = new PDFImageExtract();
try {
obj.read_pdf();
} catch (IOException ex) {
System.out.println("" + ex);
}
}
void read_pdf() throws IOException {
PDDocument document = null;
try {
document = PDDocument.load("C:\\Users\\Pradyut\\Documents\\MCS-034.pdf");
} catch (IOException ex) {
System.out.println("" + ex);
}
List pages = document.getDocumentCatalog().getAllPages();
Iterator iter = pages.iterator();
int i =1;
String name = null;
while (iter.hasNext()) {
PDPage page = (PDPage) iter.next();
PDResources resources = page.getResources();
Map pageImages = resources.getImages();
if (pageImages != null) {
Iterator imageIter = pageImages.keySet().iterator();
while (imageIter.hasNext()) {
String key = (String) imageIter.next();
PDXObjectImage image = (PDXObjectImage) pageImages.get(key);
image.write2file("C:\\Users\\Pradyut\\Documents\\image" + i);
i ++;
}
}
}
}
谢谢
【问题讨论】:
-
PDF 由 JBIG2 编码的图像组成。我不确定 pdfBox 是否支持这些。
-
我可以在这个应用程序中使用库 jbig2-imageio:code.google.com/p/jbig2-imageio/wiki/Usage 吗?将其作为库 jar 或类路径添加到应用程序吗?
-
我在测试您的代码时遇到了问题:“UnsupportedOper”
-
你找到了如何解码 JBIG2 图像的答案吗?
-
@PradyutBhattacharya 您是否找到了如何使用
jbig2-imageio解码 JBIG2 图像的解决方案?谢谢