Rails - Possible to convert a PDF to Images?

11,138

Take a look at imagemagick and rmagick plugin for ruby. This allows you to do all kinds of image conversions, including PDF to jpeg.

http://rmagick.rubyforge.org/

EDIT:

untested sample code:

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

if doc.pdf has 3 pages, this should output 3 images:
myimage.jpg.0
myimage.jpg.1
myimage.jpg.2

take a look at the end of the documentation on this page, which shows a similar example with a multi-frame gif converted to multiple PNGs using imagelist: http://www.imagemagick.org/RMagick/doc/ilist.html#write

Share:
11,138
AnApprentice
Author by

AnApprentice

working on Matter, a new way to gather professional feedback.

Updated on June 16, 2022

Comments

  • AnApprentice
    AnApprentice about 2 years

    I have a Rails 3 app with PaperClip/S3...

    Is it possible to allow a user to upload a PDF, convert the PDF to images, and then upload?

    Thanks!