title: My code is not extracting Images from all PDF files
body: <p>Kindly help me, my code which extracts images from PDF file, is not extracting images from all PDF files. Although it works good for Some PDF Files. Please help me.
  Here is my Code : 
  ExtractImages.java</p>
  
  <pre><code>package pdttotextconvertor;
  
  import java.io.IOException;
  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 {
  
      /**
       * PDF to extract images from
       */
      public static final String SOURCE_PDF = "C:/Latest Maven Code/pdttotextconvertor/src/main/resources/LC DPF example 1.pdf";
  
      /**
       * Parses a PDF and extracts all the images.
       *
       * @param filename the source PDF
       * @param destination the directory to save images
       */
      public void extractImages(String filename, String destination)
              throws IOException, DocumentException {
          System.out.println("Processing PDF at " + filename);
          System.out.println("Saving images to " + destination);
  
          PdfReader reader = new PdfReader(filename);
          PdfReaderContentParser parser = new PdfReaderContentParser(reader);
          ImageRenderListener listener = new ImageRenderListener(destination + "/Img%s.%s");
          for (int i = 1; i &lt;= 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 {
          String sourcePDF = SOURCE_PDF;
          String destination = "target/images";
          if (args.length &gt; 0) {
              sourcePDF = args[0];
              if (args.length &gt; 1) {
                  destination = args[1];
              }
          }
  
          new ExtractImages().extractImages(sourcePDF, destination);
      }
  }
  </code></pre>
  
  <p>ImageRenderListener.java</p>
  
  <pre><code>package scannedPdfConvertor;
  
  import java.io.FileOutputStream;
  import java.io.IOException;
  
  import com.itextpdf.text.pdf.parser.ImageRenderInfo;
  import com.itextpdf.text.pdf.parser.PdfImageObject;
  import com.itextpdf.text.pdf.parser.RenderListener;
  import com.itextpdf.text.pdf.parser.TextRenderInfo;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  
  /**
   * Saves images to a directory.
   *
   * @author mnguyen
   */
  public class ImageRenderListener implements RenderListener {
  
      /**
       * The directory path to store images.
       */
      protected String path;
  
      /**
       * Creates a RenderListener that will look for images.
       */
      public ImageRenderListener(String path) {
          this.path = path;
      }
  
      /**
       * @see com.itextpdf.text.pdf.parser.RenderListener#beginTextBlock()
       */
      public void beginTextBlock() {
      }
  
      /**
       * @see com.itextpdf.text.pdf.parser.RenderListener#endTextBlock()
       */
      public void endTextBlock() {
      }
  
      /**
       * @see com.itextpdf.text.pdf.parser.RenderListener#renderImage(
       * com.itextpdf.text.pdf.parser.ImageRenderInfo)
       */
      public void renderImage(ImageRenderInfo renderInfo) {
          try {
              String filename;
              FileOutputStream os;
              PdfImageObject image = renderInfo.getImage();
              if (image == null) {
                  return;
              }
              filename = String.format(path, renderInfo.getRef().getNumber(), image.getFileType());
              System.out.println("Writing image to file: " + filename);
              os = new FileOutputStream(filename);
              os.write(image.getImageAsBytes());
              os.flush();
              os.close();
          } catch (IOException e) {
              Logger.getLogger(ImageRenderListener.class.getName()).log(Level.SEVERE, null, e);
          }
      }
  
      /**
       * @see com.itextpdf.text.pdf.parser.RenderListener#renderText(
       * com.itextpdf.text.pdf.parser.TextRenderInfo)
       */
      public void renderText(TextRenderInfo renderInfo) {
  
      }
  }
  </code></pre>
  
  <p>Pdf file link which is not working is <a href="http://www.filedropper.com/lcdpfexample23" rel="nofollow noreferrer">http://www.filedropper.com/lcdpfexample23</a></p>
  
  <p>Please Help Thanks in Advance.</p>