Skip to content

Instantly share code, notes, and snippets.

@yosriady
Created October 25, 2014 14:54
Show Gist options
  • Select an option

  • Save yosriady/6edd116f7ee43703ebff to your computer and use it in GitHub Desktop.

Select an option

Save yosriady/6edd116f7ee43703ebff to your computer and use it in GitHub Desktop.
Rails Paperclip Multi-page PDF Watermark Processor with MiniMagick
module Paperclip
class Watermark < Processor
WATERMARK_PATH = "#{Rails.root}/public/images/watermark.png"
def initialize(file, options = {}, attachment = nil)
super
@file = file
@watermark_path = options[:watermark_path]
@current_format = File.extname(@file.path)
@basename = File.basename(@file.path, @current_format)
end
def make
pdf = MiniMagick::Image.open(File.expand_path(@file.path))
watermark = MiniMagick::Image.open(File.expand_path(WATERMARK_PATH))
composited = pdf.pages.inject([]) do |composited, page|
composited << page.composite(watermark) do |c|
c.compose "Over"
c.gravity "SouthEast"
end
end
MiniMagick::Tool::Convert.new do |b|
composited.each { |page| b << page.path }
b << pdf.path
end
return pdf
end
end
end
@jackson-sandland
Copy link

If I comment out the entire file - there is no difference. This is the only processor I am calling in my model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment