Class: Libis::Format::Converter::PdfWatermarkerHeader

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

#initializePdfWatermarkerHeader

Returns a new instance of PdfWatermarkerHeader.



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

def initialize
  super
end

Class Method Details

.input_typesObject



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



34
35
36
37
38
39
40
41
42
# File 'lib/libis/format/converter/pdf_watermarker_header.rb', line 34

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



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/libis/format/converter/pdf_watermarker_header.rb', line 45

def convert_pdf(source, target)

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

end

#pdf_watermark_header(_) ⇒ Object



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

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

#text(v) ⇒ Object



30
31
32
# File 'lib/libis/format/converter/pdf_watermarker_header.rb', line 30

def text(v)
  @options[:text] = v.blank? ? nil : v
end