There is a pdf file, and I want to import the 2nd page as an image and save it to a jpeg file. Is it possible and how to do it?
This is the code how I import a page:
Document document = new Document(); File file = File.createTempFile("", ""); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); final int backPage = 2; PdfReader reader = new PdfReader(pdf.getAbsolutePath()); PdfImportedPage importedPage = writer.getImportedPage(reader, backPage); com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(importedPage);
Now I get an
image instance, but I don’t know how to write it to a jpeg file.
Appearently (according to 1T3XT BVBA), you can only save an iText Image from a PDF page, not a raster image. You can store it everywhere, if you will use later to put it in another PDF page… otherwise, you’ll have to use a tool like JPedal:
EDIT: maybe PDFBox can do it for you too!: