Class: Libis::Format::Converter::PdfWatermarkerImage

Inherits:
Base
  • Object
show all
Defined in:
lib/libis/format/converter/pdf_watermarker_image.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

#initializePdfWatermarkerImage

Returns a new instance of PdfWatermarkerImage.



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

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

Class Method Details

.input_typesObject



13
14
15
# File 'lib/libis/format/converter/pdf_watermarker_image.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_image.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



39
40
41
42
43
44
45
46
47
# File 'lib/libis/format/converter/pdf_watermarker_image.rb', line 39

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



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/libis/format/converter/pdf_watermarker_image.rb', line 50

def convert_pdf(source, target)

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

end

#file(v) ⇒ Object



31
32
33
# File 'lib/libis/format/converter/pdf_watermarker_image.rb', line 31

def file(v)
  @file = v
end

#opacity(v) ⇒ Object



35
36
37
# File 'lib/libis/format/converter/pdf_watermarker_image.rb', line 35

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

#pdf_watermark_image(_) ⇒ Object



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

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