Search code examples
file-uploadruby-on-rails-3.1carrierwavepdf-conversion

Uploading a PDF in rails using Carrierwave and converting each page to a PNG/JPEG and saving them to a new model


I am fairly new to using carrierwave. Currently I can upload and perform simple actions on images, such as resize_to_fit.
Now I need to change my name-uploader.rb file, so when I upload a PDF file, it automatically converts the pdf to a multiple image files (PNG/JPEG). One main thing I want to understand is how can I check the type of the file uploaded? I know I can set a list of file types to be accepted, I have already set a list of accepted file-types.
Now when a pdf is uploaded I want it to be converted to multiple images, and for each image a new model is created with certain data and the image.

  • How to check the type of the file uploaded?
  • How to convert the PDF into multiple image(PNG/JPEG/etc) files?
  • Can I create models, or call an action from another controller to create the models using the generated pngs inside the uploader.rb file?
  • Is Carrierwave the tool for this job or should I use another gem to upload files?

I have used the convert => "png" , but it was giving me an error.

Note: I have included the RMagic is included at the top of the file.

Thanks,


Solution

  • Try http://documentcloud.github.com/docsplit/