views:

246

answers:

2

I'd like to take a pdf and convert it to images...each pdf page becoming a separate image.

There's a similar post here: http://stackoverflow.com/questions/65250/convert-a-doc-or-pdf-to-an-image-and-display-a-thumbnail-in-ruby But it doesn't cover how to make separate images for each page.

+3  A: 

ImageMagick can do that with PDFs. Presumably RMagick can do it too, but I'm not familiar with it.

EDIT:

The code from the post you linked to:

require 'RMagick'
pdf = Magick::ImageList.new("doc.pdf")

pdf is an ImageList object, which according to the documentation delegates many of its methods to Array. You should be able to iterate over pdf and call write to write the individual images to files.

scompt.com
No doubt... I'm just wondering if someone has some sample code.
tybro0103
A: 

Since I can't find a way to deal with PDFs on a per-page basis in RMagick, I'd recommend first splitting the PDF into pages with pdftk's burst command, then dealing with the individual pages in RMagick. This is probably less performant than an all-in-one solution, but unfortunately no all-in-one solution presents itself.

There's also PDF::Toolkit for Ruby that hooks into pdftk but I've never used it.

Jordan