本文整理汇总了Java中org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage.getRGBImage方法的典型用法代码示例。如果您正苦于以下问题:Java PDXObjectImage.getRGBImage方法的具体用法?Java PDXObjectImage.getRGBImage怎么用?Java PDXObjectImage.getRGBImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage
的用法示例。
在下文中一共展示了PDXObjectImage.getRGBImage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPDFBox
import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage; //导入方法依赖的package包/类
@Test
public void testPDFBox() throws IOException {
PDDocument document = null;
File file = new File(JazzPDFReader.PDF_TESTE);
document = PDDocument.load(file);
List pages = document.getDocumentCatalog().getAllPages();
for (Object object : pages) {
PDPage page = (PDPage) object;
PDResources resources = page.getResources();
Map images = resources.getImages();
if (images != null) {
Set keySet = images.keySet();
Iterator imageIter = keySet.iterator();
while (imageIter.hasNext()) {
String key = (String) imageIter.next();
PDXObjectImage image = (PDXObjectImage) images.get(key);
BufferedImage bufferedImage = image.getRGBImage();
ImageIO.write(bufferedImage, "jpg", new File("/home/darcio/Desktop/ExamePDFTeste/pdfbox/imgFromPDFBOX" + System.currentTimeMillis() + ".jpg"));
}
}
}
}
示例2: processResources
import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage; //导入方法依赖的package包/类
/**
*
*
* @param resources
*
* @throws IOException
*/
private void processResources(PDResources resources, TikaImageHelper helper)
throws IOException {
if (resources == null)
return;
try {
Map<String, PDXObject> xobjects = resources.getXObjects();
if (xobjects != null) {
Iterator<String> xobjectIter = xobjects.keySet().iterator();
while (xobjectIter.hasNext()) {
String key = xobjectIter.next();
PDXObject xobject = xobjects.get(key);
// write the images
if (xobject instanceof PDXObjectImage) {
PDXObjectImage image = (PDXObjectImage) xobject;
if (ImageTools.imagePerPageRatioValid(imageCount++, pageCount)
&& ImageTools.imageSizeValid(image.getHeight(), image.getWidth())) {
BufferedImage buffImage = image.getRGBImage();
helper.addImage(buffImage);
}
}
// maybe there are more images embedded in a form object
else if (xobject instanceof PDXObjectForm) {
if (ImageTools.imagePerPageRatioValid(imageCount, pageCount)) {
PDXObjectForm xObjectForm = (PDXObjectForm) xobject;
PDResources formResources = xObjectForm.getResources();
processResources(formResources, helper);
}
}
}
}
} catch (Exception e) {
LOG.info("Shit happened", e);
}
}