朋友,我正在使用PDFBox 2.0.6。我從PDF文件中提取圖像已取得成功,但現在它正在爲單個PDF頁面創建圖像。但問題是,可能會有任何不。在一個PDF頁面中的圖像,我希望每個嵌入圖像應該被提取爲一個單一的圖像本身。使用PDFBox從單個PDF頁提取多個嵌入圖像
下面是代碼,
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;
public class DemoPdf {
public static void main(String args[]) throws Exception {
//Loading an existing PDF document
File file = new File("C:/Users/ADMIN/Downloads/Vehicle_Photographs.pdf");
PDDocument document = PDDocument.load(file);
//Instantiating the PDFRenderer class
PDFRenderer renderer = new PDFRenderer(document);
File imageFolder = new File("C:/Users/ADMIN/Desktop/image");
for (int page = 0; page < document.getNumberOfPages(); ++page) {
//Rendering an image from the PDF document
BufferedImage image = renderer.renderImage(page);
//Writing the image to a file
ImageIO.write(image, "JPEG", new File(imageFolder+"/" + page +".jpg"));
System.out.println("Image created"+ page);
}
//Closing the document
document.close();
}
}
是否有可能在PDFBox的,我可以提取所有嵌入圖像作爲單獨的圖像,由於
https://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/ExtractImages.java?view=markup –
2.0.7已發佈。 –