Class: Paperclip::PdfMerge
- Inherits:
-
Processor
- Object
- Processor
- Paperclip::PdfMerge
- Defined in:
- lib/paperclip_processors/pdf_merge.rb
Instance Method Summary collapse
-
#initialize(file, options = {}, attachment = nil) ⇒ PdfMerge
constructor
A new instance of PdfMerge.
- #make ⇒ Object
Constructor Details
#initialize(file, options = {}, attachment = nil) ⇒ PdfMerge
Returns a new instance of PdfMerge.
29 30 31 32 33 34 |
# File 'lib/paperclip_processors/pdf_merge.rb', line 29 def initialize file, = {}, = nil super @format = File.extname(@file.path) @basename = File.basename(@file.path, @format) @files = .instance.pdf_files end |
Instance Method Details
#make ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/paperclip_processors/pdf_merge.rb', line 36 def make src = @file if @current_format && @current_format.downcase == '.pdf' 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)}" ) return dst else return src end end |