I am getting a pdf in byte array
. I want to convert just the 1st page of the pdf into image
.
I have tired the classes provided by com.lowagie.text.pdf
as follows -
PdfReader reader = new PdfReader(input);
reader.selectPages("1");
File file = new File("D:/img1.jpg");
BufferedImage pdfImage = ImageIO.read(new ByteArrayInputStream(reader.getPageContent(1)));
ImageIO.write(pdfImage, "jpg", file);
Doing this gives me an Exception when ImageIO.write
is called?
When I fetch the size of the byte array returned by reader.getPageContent(1), I get a 1000+ value. What confuses me is why do I get the Exception.
Exception -
java.lang.IllegalArgumentException: image == null!
I tried itext as well but it was of no use.
Could you suggest me a way to get just image of the 1st page (1st page as image) from the byte array of the pdf file?