CaMelRyder has asked for the wisdom of the Perl Monks concerning the following question:

Does anyone know anything about extacting images from a PDF? I have found an endless amount of PDF creation tools and libraries but nothing on actually deconstructing a PDF. I need to be able to pull images out of one. If anyone could point me in the right direction or suggest some modules or tutorials that would be a great help.
¥peace from CaMelRyder¥

Replies are listed 'Best First'.
Re: PDF Image Extraction
by McDarren (Abbot) on Jul 16, 2006 at 05:03 UTC
    I've not worked with PDF's myself, but I believe that PDF::Extract is the recommended module for extracting data from them. Although it doesn't appear to have a method to extract images - just pages.

    CAM::PDF::Renderer::Images looks like it might do what you want. Or maybe CAM::PDF::Content

    Hope this helps,
    Darren :)

Re: PDF Image Extraction
by Khen1950fx (Canon) on Jul 16, 2006 at 05:07 UTC
    If you have Adobe, then go to:

    http://ict.cas.psu.edu/training/howto/util/pdf_extract_graphics_v6.htm

    It explains how to extract an image or images.

    If you have xpdf, then see the man pages for pdfimages and xpdfrc. Pdfimages will extract images, then I would recommend PDF::Create to rebundle your images. Darren's suggestion that you use CAM::PDF works too.

Re: PDF Image Extraction
by marto (Cardinal) on Jul 16, 2006 at 09:59 UTC
      Thanks for the posts guys, the CAM::PDF seems to be exactly what I need. However, I'm having some pretty extreme difficulties in getting it to install. I managed to get all of the dependencies installed except for one trouble maker - Text::PDF::File. I install it over and over again and it installs successfully with no errors and no failed tests, yet everytime I try to get CAM::PDF installed it complains about Text::PDF::File not being there and attempts to install it again. Probably a versioning problem

      So I let and it bombs out during the testing phase because it can't find Text::PDF::FlateDecode. This module has completely alluded me. I can't find it anywhere. It doesn't come up in the depedency list either.

      While I've got your attention, perhaps I should elaborate a little on what my project is. I have about 100 pdfs which are technical journals on welding specifications. Welders pay alot of money for people to turn the specifications for a job into a set of legal documents so as to cover there butts if something goes wrong. This is how I view the project thus far and intend to tackle each step as a different problem:

      Step 1:
      --------
      First have to extract the journals from the pdfs(which are stored as images).

      Step 2:
      -------
      I will have to OCR the images in order to turn them into character data.

      Step 3:
      -------
      Use a form of statistical analysis to turn the character data into a searchable database, which will much easier to custom taylor to the needs of the user.

      It will be long road and I really appreciate you're help at these early steps.

      ¥peace from CaMelRyder¥
        I found a simple solution. I simply wrote a script to drive convert which is part of the ImageMagick package. It has the capability of pulling all of the images from a pdf and storing them in any format that I want. Now it's on to the OCR step. I think I'll do that one in the Java because of how easy it is to draw on the screen.
        ¥peace from CaMelRyder¥