I\'d like to have Paperclip create 2 thumbnails for each page of a multipage PDF file that is uploaded.
I\'m running Paperclip 2.3.1.1 and using this in my Asset model:<
Here how I implemented similar task.
Document model:
class Document < ActiveRecord::Base
has_many :pages, :dependent => :destroy
has_attached_file :asset
after_asset_post_process :make_pages
private
def make_pages
if valid?
Paperclip.run('convert', "-quality #{Page::QUALITY} -density #{Page::DENSITY} #{asset.queued_for_write[:original].path} #{asset.queued_for_write[:original].path}%d.png")
images = Dir.glob("#{asset.queued_for_write[:original].path}*.png").sort_by do |line|
line.match(/(\d+)\.png$/)[1].to_i
end
images.each do |page_image|
pages.build(:asset => File.open(page_image))
end
FileUtils.rm images
end
end
end
Page model:
class Page < ActiveRecord::Base
belongs_to :document
has_attached_file :asset
QUALITY = 100
DENSITY = '80x80'
end