Class: PdfWatermark::WaterMark::Repeated

Inherits:
Base
  • Object
show all
Defined in:
lib/pdf_watermark/water_mark/repeated.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Repeated

Returns a new instance of Repeated.



6
7
8
# File 'lib/pdf_watermark/water_mark/repeated.rb', line 6

def initialize(*args)
  super(*args)
end

Instance Method Details

#renderObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pdf_watermark/water_mark/repeated.rb', line 10

def render
  document.pages.each do |page|
    canvas = page.canvas(type: :overlay)
    canvas.font(:watermark_font, size: @font_size)
    canvas.fill_color(@options[:font_color])
    box_height = @font_size
    box_width = canvas.width_of(@mark_string)
    temp_y = @y
    indent = false
    offset_x = box_width + @options[:repeat_offset] * @font_size
    offset_y = box_height + @options[:repeat_offset] * @font_size


    canvas.opacity(fill_alpha: @options[:transparent]) do
      canvas.rotate(@angle, origin: [@content_width/2, @content_height/2]) do
        while temp_y > 0 do
          temp_x = indent ? (offset_x / 2.0) : 0
          while temp_x <= @content_width
            canvas.text(@mark_string, at: [temp_x, temp_y])
            temp_x += offset_x
          end
          temp_y -= offset_y
          indent = !indent
        end
      end
    end
  end
  document
end