Class: WatermarkToPdf::Watermark

Inherits:
Object
  • Object
show all
Defined in:
lib/watermark_to_pdf.rb

Overview

The Watermark class provides methods to add watermarks to PDF files.

Constant Summary collapse

DEFAULT_TEXT_OPTIONS =
{
  text: "Watermark Text",
  position: [0, 0],
  size: 200,
  color: "rgba(128, 128, 128, 0.2)",
  font: "Helvetica-Oblique",
  weight: 700
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(file, options = {}) ⇒ Watermark

Returns a new instance of Watermark.



21
22
23
24
# File 'lib/watermark_to_pdf.rb', line 21

def initialize(file, options = {})
  @file = file
  @options = default_options.merge(options)
end

Instance Method Details

#add_watermarkObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/watermark_to_pdf.rb', line 26

def add_watermark
  Dir.mktmpdir do |dir|
    temp_file = create_temp_pdf(dir)
    image_paths = convert_pdf_to_images(temp_file, dir)

    watermark_images(image_paths, dir)
    watermarked_pdf_path = convert_images_to_pdf(dir)

    cleanup(temp_file, dir)
    watermarked_pdf_path
  end
end