Python pdfminer extract image produces multiple images per page (should be single image)
<p>I am attempting to extract images that are in a PDF. The file I am working with is 2+ pages. Page 1 is text and pages 2-n are images (one per page, or it may be a single image spanning multiple pages; I do not have control over the origin).</p>

<p>I am able to parse the text out from page 1 but when I try to get the images I am getting 3 images per image page. I cannot determine the image type which makes saving it difficult. Additionally trying to save each pages 3 pictures as a single img provides no result (as in cannot be opened via finder on OSX)</p>

<p>Sample:</p>

<pre><code>fp = open('the_file.pdf', 'rb')
parser = PDFParser(fp)
document = PDFDocument(parser)
rsrcmgr = PDFResourceManager()
laparams = LAParams()
device = PDFPageAggregator(rsrcmgr, laparams=laparams)
interpreter = PDFPageInterpreter(rsrcmgr, device)


for page in PDFPage.create_pages(document):
    interpreter.process_page(page)
    pdf_item = device.get_result()
    for thing in pdf_item:
        if isinstance(thing, LTImage):
            save_image(thing)
        if isinstance(thing, LTFigure):
            find_images_in_thing(thing)


def find_images_in_thing(outer_layout):
    for thing in outer_layout:
        if isinstance(thing, LTImage):
            save_image(thing)
</code></pre>

<p><code>save_image</code> either writes a file per image in <code>pageNum_imgNum</code> format in <code>'wb'</code> mode or a single image per page in <code>'a'</code> mode. I have tried numerous file extensions with no luck.</p>

<p>Resources I've looked into:</p>

<p><a href="http://denis.papathanasiou.org/posts/2010.08.04.post.html" rel="noreferrer">http://denis.papathanasiou.org/posts/2010.08.04.post.html</a> (outdatted pdfminer version)
<a href="http://nedbatchelder.com/blog/200712/extracting_jpgs_from_pdfs.html" rel="noreferrer">http://nedbatchelder.com/blog/200712/extracting_jpgs_from_pdfs.html</a></p>