List of usage examples for org.apache.pdfbox.pdmodel.graphics.image PDImageXObject createFromFileByExtension
public static PDImageXObject createFromFileByExtension(File file, PDDocument doc) throws IOException
From source file:costumetrade.common.util.PdfUtils.java
License:Open Source License
public static PDDocument createImagePdf(File file) { PDPageContentStream contentStream = null; try {/*from w w w. jav a 2 s. c om*/ BufferedImage bimg = ImageIO.read(file); PDDocument document = new PDDocument(); PDPage page = new PDPage(new PDRectangle(bimg.getWidth(), bimg.getHeight())); document.addPage(page); PDImageXObject image = PDImageXObject.createFromFileByExtension(file, document); contentStream = new PDPageContentStream(document, page); contentStream.drawImage(image, 0, 0); return document; } catch (IOException e) { throw new RuntimeException("?PDF", e); } finally { IOUtils.closeQuietly(contentStream); } }