/* * This class is part of the book "iText in Action - 2nd Edition" * written by Bruno Lowagie (ISBN: 9781935182610) * For more info, go to: http://itextpdf.com/examples/ * This example only works with the AGPL version of iText. */ package part4.chapter15; import java.io.IOException; import part3.chapter10.ImageTypes; import com.itextpdf.text.DocumentException; import com.itextpdf.text.pdf.PdfReader; import com.itextpdf.text.pdf.parser.PdfReaderContentParser; /** * Extracts images from a PDF file. */ public class ExtractImages { /** The new document to which we've added a border rectangle. */ public static final String RESULT = "results/part4/chapter15/Img%s.%s"; /** * Parses a PDF and extracts all the images. * @param src the source PDF * @param dest the resulting PDF */ public void extractImages(String filename) throws IOException, DocumentException { PdfReader reader = new PdfReader(filename); PdfReaderContentParser parser = new PdfReaderContentParser(reader); MyImageRenderListener listener = new MyImageRenderListener(RESULT); for (int i = 1; i <= reader.getNumberOfPages(); i++) { parser.processContent(i, listener); } reader.close(); } /** * Main method. * @param args no arguments needed * @throws DocumentException * @throws IOException */ public static void main(String[] args) throws IOException, DocumentException { new ImageTypes().createPdf(ImageTypes.RESULT); new ExtractImages().extractImages(ImageTypes.RESULT); } }