I want to convert each pdf page into an image (like a screen shot), and then upload that image to a storage service.
private void getImageBytes(PDDocument document, int pageIndex, int dpi, ConcurrentHashMap<String, byte[]> imgsToUpload, String imgKey) throws IOException {
PDFRenderer pdfRenderer = new PDFRenderer(document);
BufferedImage bim = pdfRenderer.renderImageWithDPI(pageIndex, dpi, ImageType.RGB);
final ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(bim, "png", os); // import javax.imageio.ImageIO;
os.flush();
os.close();
imgsToUpload.put(imgKey, os.toByteArray());
}
I did import jbig2-imageio
by adding this snippet to pom.xml
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.19</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.pdfbox/jbig2-imageio -->
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>jbig2-imageio</artifactId>
<version>3.0.3</version>
</dependency>
but still the generated images are blank. and this error is logged : Cannot read JPEG2000 image: Java Advanced Imaging (JAI) Image I/O Tools are not installed
So, what did i miss ? , i assumed that adding the dependency would resolve that error.
should i use pdfbox-tools.imageIo instead of java.imageio
PS: I am New to Java, so i it might be a configuration thing ??