views:

76

answers:

2

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?

+1  A: 

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

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

fl00r
I am using paperclip, so wouldn't I want to use the Paperclip.run command?Using command to execute it still leaves me with my initial problem as well, how do I get all the file names?
Josh Crowder
Attaches.all.each{|attach| \`convert -size 640x300 #{attach.your_file_name} #{attach.your_file_name}.png\`} - you can execute system commands in model callbacks like after_save and so on. So you can convert your pdfs right after saving your attach
fl00r
+1  A: 

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.)

ewall
I didn't know that I can set image fromat in styles. Cool feature.
fl00r