title: Extract Image from a particular page in PDF
body: <p>I want to extract an Image from a PDF file. I tried with the following code and it extracted a jpeg Image perfectly from the PDF. The problem is how to extract image from a particular page e.g. Page 1 or from some other page. I don't want to read the whole PDF to search for the Image.</p>
  
  <p>Any suggestions?</p>
  
  <p>Code to extract Image:</p>
  
  <pre><code>private void List&lt;System.Drawing.Image&gt; ExtractImages(String PDFSourcePath)
          {
              List&lt;System.Drawing.Image&gt; ImgList = new List&lt;System.Drawing.Image&gt;();
  
              iTextSharp.text.pdf.RandomAccessFileOrArray RAFObj = null;
              iTextSharp.text.pdf.PdfReader PDFReaderObj = null;
              iTextSharp.text.pdf.PdfObject PDFObj = null;
              iTextSharp.text.pdf.PdfStream PDFStremObj = null;
  
              try
              {
                  RAFObj = new iTextSharp.text.pdf.RandomAccessFileOrArray(PDFSourcePath);
                  PDFReaderObj = new iTextSharp.text.pdf.PdfReader(RAFObj, null);
  
                  for (int i = 0; i &lt;= PDFReaderObj.XrefSize - 1; i++)
                  {
                      PDFObj = PDFReaderObj.GetPdfObject(i);
  
                      if ((PDFObj != null) &amp;&amp; PDFObj.IsStream())
                      {
                          PDFStremObj = (iTextSharp.text.pdf.PdfStream)PDFObj;
                          iTextSharp.text.pdf.PdfObject subtype = PDFStremObj.Get(iTextSharp.text.pdf.PdfName.SUBTYPE);
  
                          if ((subtype != null) &amp;&amp; subtype.ToString() == iTextSharp.text.pdf.PdfName.IMAGE.ToString())
                          {
                              byte[] bytes = iTextSharp.text.pdf.PdfReader.GetStreamBytesRaw((iTextSharp.text.pdf.PRStream)PDFStremObj);
  
                              if ((bytes != null))
                              {
                                  try
                                  {
                                      System.IO.MemoryStream MS = new System.IO.MemoryStream(bytes);
  
                                      MS.Position = 0;
                                      System.Drawing.Image ImgPDF = System.Drawing.Image.FromStream(MS);
                                      pictureBox1.Image = ImgPDF;
                                      MS.Close();
                                      MS.Flush();
  
                                  }
                                  catch (Exception)
                                  {
  
                                  }
                              }
                          }
                      }
                  }
                  PDFReaderObj.Close();
              }
              catch (Exception ex)
              {
                  throw new Exception(ex.Message);
              }                
          }
  </code></pre>