Class: Libis::Format::Converter::PdfWatermarker
- Inherits:
-
Base
- Object
- Base
- Libis::Format::Converter::PdfWatermarker
show all
- Defined in:
- lib/libis/format/converter/pdf_watermarker.rb
Constant Summary
collapse
- OPTIONS_TABLE =
{
file: 'wm_image',
text: 'wm_text',
rotation: 'wm_text_rotation',
size: 'wm_font_size',
opacity: 'wm_opacity',
gap_size: 'wm_gap_size',
gap_ratio: 'wm_gap_ratio'
}
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
Returns a new instance of PdfWatermarker.
29
30
31
32
33
|
# File 'lib/libis/format/converter/pdf_watermarker.rb', line 29
def initialize
super
@options[:text] = '© LIBIS'
@options[:opacity] = '0.3'
end
|
Class Method Details
16
17
18
|
# File 'lib/libis/format/converter/pdf_watermarker.rb', line 16
def self.input_types
[:PDF]
end
|
.output_types(format = nil) ⇒ Object
20
21
22
23
|
# File 'lib/libis/format/converter/pdf_watermarker.rb', line 20
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
63
64
65
66
67
68
69
70
71
|
# File 'lib/libis/format/converter/pdf_watermarker.rb', line 63
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/libis/format/converter/pdf_watermarker.rb', line 83
def convert_pdf(source, target)
using_temp(target) do |tmpname|
result = Libis::Format::Tool::PdfCopy.run(
source, tmpname,
@options.map {|k, v|
if v.nil?
nil
else
v = v.split('\n') unless v.blank? if k == :text
k = OPTIONS_TABLE[k] || k
["--#{k}", (v.is_a?(Array) ? v : 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
|
#file(v) ⇒ Object
35
36
37
|
# File 'lib/libis/format/converter/pdf_watermarker.rb', line 35
def file(v)
@options[:file] = v.blank? ? nil : v
end
|
#gap_ratio(v) ⇒ Object
59
60
61
|
# File 'lib/libis/format/converter/pdf_watermarker.rb', line 59
def gap_ratio(v)
@options[:gap_ratio] = v
end
|
#gap_size(v) ⇒ Object
55
56
57
|
# File 'lib/libis/format/converter/pdf_watermarker.rb', line 55
def gap_size(v)
@options[:gap_size] = v
end
|
#opacity(v) ⇒ Object
51
52
53
|
# File 'lib/libis/format/converter/pdf_watermarker.rb', line 51
def opacity(v)
@options[:opacity] = v unless v.blank?
end
|
#pdf_watermark(_) ⇒ Object
25
26
27
|
# File 'lib/libis/format/converter/pdf_watermarker.rb', line 25
def pdf_watermark(_)
end
|
#rotation(v) ⇒ Object
43
44
45
|
# File 'lib/libis/format/converter/pdf_watermarker.rb', line 43
def rotation(v)
@options[:rotation] = v unless v.blank?
end
|
#size(v) ⇒ Object
47
48
49
|
# File 'lib/libis/format/converter/pdf_watermarker.rb', line 47
def size(v)
@options[:size] = v unless v.blank?
end
|
#text(v) ⇒ Object
39
40
41
|
# File 'lib/libis/format/converter/pdf_watermarker.rb', line 39
def text(v)
@options[:text] = v
end
|