title: Extract images from PDF using python PyPDF2
body: <p>Is there any way to extract images as stream from pdf document (using <a href="https://github.com/mstamy2/PyPDF2" rel="nofollow noreferrer">PyPDF2</a> library)? 
  Also is it possible to replace some images to another (generated with PIL for example or loaded from file)?</p>
  
  <p>I'm able to get EncodedStreamObject from pdf objects tree and get encoded stream (by calling getData() method), but looks like it just raw content w/o any image headers and other meta information.</p>
  
  <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; import PyPDF2
  &gt;&gt;&gt; # sample.pdf contains png images
  &gt;&gt;&gt; reader = PyPDF2.PdfFileReader(open('sample.pdf', 'rb'))
  &gt;&gt;&gt; reader.resolvedObjects[0][9]
  {'/BitsPerComponent': 8,
  '/ColorSpace': ['/ICCBased', IndirectObject(20, 0)],
  '/Filter': '/FlateDecode',
  '/Height': 30,
  '/Subtype': '/Image',
  '/Type': '/XObject',
  '/Width': 100}
  &gt;&gt;&gt;
  &gt;&gt;&gt; reader.resolvedObjects[0][9].__class__
  PyPDF2.generic.EncodedStreamObject
  &gt;&gt;&gt;
  &gt;&gt;&gt; s = reader.resolvedObjects[0][9].getData()
  &gt;&gt;&gt; len(s), s[:10]
  (9000, '\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc')
  </code></pre>
  
  <p>I've looked across <a href="https://github.com/mstamy2/PyPDF2" rel="nofollow noreferrer">PyPDF2</a>, <a href="https://bitbucket.org/rptlab/reportlab" rel="nofollow noreferrer">ReportLab</a> and <a href="https://github.com/euske/pdfminer/" rel="nofollow noreferrer">PDFMiner</a> solutions quite a bit, but haven't found anything like what I'm looking for.</p>
  
  <p>Any code samples and links will be very helpful.   </p>