Created
June 21, 2013 16:35
-
-
Save jessieay/5832466 to your computer and use it in GitHub Desktop.
custom paperclip processor - lives in lib/paperclip_processors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Paperclip | |
class Merge < Processor | |
def initialize file, options = {}, attachment = nil | |
super | |
@format = File.extname(@file.path) | |
@basename = File.basename(@file.path, @format) | |
@files = attachment.instance.files | |
end | |
def make | |
src = @file | |
dst = Tempfile.new([@basename, @format]) | |
dst.binmode | |
file_paths = @files.map { |file| "#{Rails.root}/tmp/#{file.original_filename}" } | |
all_page_file_paths = "" | |
file_paths.each do |file_path| | |
pdf = PDF::Reader.new(file_path) | |
count = pdf.page_count | |
counter = 0 | |
count.times do | |
all_page_file_paths += "#{file_path}[#{counter}] " | |
counter += 1 | |
end | |
end | |
Paperclip.run( | |
'convert', | |
"-density 150 #{all_page_file_paths} #{File.expand_path(dst.path)}" | |
) | |
dst | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment