Josh Crowder
Josh Crowder

Reputation: 1051

Splitting PDF to png

I'm using paperclip to upload a pdf. Once the file is uploaded I need to split every page into a png. This is the command I think I need to use

convert -size 640x300 fileName.pdf slide.png

Now if I run that command from terminal it works fine, but I need a way of getting each slides name so I can add it into a model.

What's the best way to achieve this?

Upvotes: 3

Views: 1197

Answers (2)

ewall
ewall

Reputation: 28100

You should be able to have Paperclip do this conversion for you at the time of the upload, like this:

has_attached_file :pdfupload, :styles => { :pinged => ["640x300", :png] }

Then you can show the PNG version like so:

<%= image_tag @mymodel.pdfupload.url(:pinged) %>

(Obviously the name of the model and file will need to be changed to match yours.)

Upvotes: 4

fl00r
fl00r

Reputation: 83680

use `command` to execute system commads (`-quotes)

`convert -size 640x300 fileName.pdf slide.png`

Upvotes: 2

Related Questions