Class: Libis::Format::Converter::PdfWatermarkerText

Inherits:
Base
  • Object
show all
Defined in:
lib/libis/format/converter/pdf_watermarker_text.rb

Instance Attribute Summary

Attributes inherited from Base

#flags, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

category, #check_file_exist, inherited, using_temp, #using_temp

Constructor Details

#initializePdfWatermarkerText

Returns a new instance of PdfWatermarkerText.



26
27
28
29
30
# File 'lib/libis/format/converter/pdf_watermarker_text.rb', line 26

def initialize
  super
  @text = []
  @options[:opacity] = '0.3'
end

Class Method Details

.input_typesObject



13
14
15
# File 'lib/libis/format/converter/pdf_watermarker_text.rb', line 13

def self.input_types
  [:PDF]
end

.output_types(format = nil) ⇒ Object



17
18
19
20
# File 'lib/libis/format/converter/pdf_watermarker_text.rb', line 17

def self.output_types(format = nil)
  return [] unless input_types.include?(format) if format
  [:PDF]
end

Instance Method Details

#convert(source, target, format, opts = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/libis/format/converter/pdf_watermarker_text.rb', line 56

def convert(source, target, format, opts = {})
  super

  result = convert_pdf(source, target)
  return nil unless result

  result

end

#convert_pdf(source, target) ⇒ Object

noinspection DuplicatedCode



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/libis/format/converter/pdf_watermarker_text.rb', line 67

def convert_pdf(source, target)

  using_temp(target) do |tmpname|
    result = Libis::Format::Tool::PdfWatermark.run(
        source, tmpname, 'text',
        @options.map {|k, v|
          if v.nil?
            nil
          else
            ["--#{k}", v.to_s]
          end
          }.compact.flatten + @text
    )
    unless result[:err].empty?
      error("Pdf conversion encountered errors:\n%s", result[:err].join(join("\n")))
      next nil
    end
    tmpname
  end

end

#gap(v) ⇒ Object



48
49
50
# File 'lib/libis/format/converter/pdf_watermarker_text.rb', line 48

def gap(v)
  @options[:gap] = v
end

#opacity(v) ⇒ Object



44
45
46
# File 'lib/libis/format/converter/pdf_watermarker_text.rb', line 44

def opacity(v)
  @options[:opacity] = v unless v.blank?
end

#padding(v) ⇒ Object



52
53
54
# File 'lib/libis/format/converter/pdf_watermarker_text.rb', line 52

def padding(v)
  @options[:padding] = v
end

#pdf_watermark_text(_) ⇒ Object



22
23
24
# File 'lib/libis/format/converter/pdf_watermarker_text.rb', line 22

def pdf_watermark_text(_)
  #force usage of this converter
end

#rotation(v) ⇒ Object



36
37
38
# File 'lib/libis/format/converter/pdf_watermarker_text.rb', line 36

def rotation(v)
  @options[:rotation] = v unless v.blank?
end

#size(v) ⇒ Object



40
41
42
# File 'lib/libis/format/converter/pdf_watermarker_text.rb', line 40

def size(v)
  @options[:size] = v unless v.blank?
end

#text(v) ⇒ Object



32
33
34
# File 'lib/libis/format/converter/pdf_watermarker_text.rb', line 32

def text(v)
  @text += v.split("\n")
end