Class: PdfParadise::RotatePdfFile
- Inherits:
-
Base
- Object
- Base
- PdfParadise::RotatePdfFile
show all
- Defined in:
- lib/pdf_paradise/utility_scripts/rotate_pdf_file.rb
Overview
PdfParadise::RotatePdfFile
Constant Summary
collapse
- ROTATE_BY_N_DEGREES =
90
- ROTATE_REGEX =
/(--rotate (\d+))/
Constants inherited
from Base
Base::NAMESPACE
Instance Method Summary
collapse
Methods inherited from Base
#basename, #be_verbose?, #change_directory, #commandline_arguments?, #copy_file, #delete_file, #e, #ecomment, #esystem, #first_argument?, #gold, #infer_the_namespace, #input_without_leading_hyphens?, #internal_hash?, #is_an_image_file?, #is_on_roebe?, #lightsteelblue, #log_dir?, #mkdir, #mv, #n_pages?, #namespace?, #no_file_at, #opne, #orange, #reset_the_internal_hash, #return_commandline_arguments_starting_with_hyphens, #return_files_from_the_commandline_arguments, #return_pwd, #rev, #set_be_quiet, #set_commandline_arguments, #steelblue, #try_to_ensure_that_this_directory_exists, #write_what_into
Constructor Details
#initialize(i = nil, run_already = true) ⇒ RotatePdfFile
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/pdf_paradise/utility_scripts/rotate_pdf_file.rb', line 37
def initialize(
i = nil,
run_already = true
)
reset
case i
when :do_not_run_yet
i = nil
run_already = false
end
set_commandline_arguments(i)
set_input(
i.reject {|entry|
entry.start_with?('--')
}
)
case run_already
when :run_already
run_already = true
when :do_not_run_yet
run_already = false
end
run if run_already
end
|
Instance Method Details
#add_quality ⇒ Object
183
184
185
|
# File 'lib/pdf_paradise/utility_scripts/rotate_pdf_file.rb', line 183
def add_quality
return '-quality 100 '
end
|
#do_convert_this_pdf_file(i, be_verbose = true) ⇒ Object
Also known as:
do_rotate_the_pdf_file
#
do_convert_this_pdf_file
#
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
# File 'lib/pdf_paradise/utility_scripts/rotate_pdf_file.rb', line 235
def do_convert_this_pdf_file(
i, be_verbose = true
)
i = i.to_s
output_file = output_file?
_ = @use_this_command.to_s
_ = _.dup
if _.start_with? 'qpdf'
_ << ' --rotate='+rotate_by_n_degrees?+' '
if @overwrite_the_original_file
_ << ' --replace-input'
end
else
_ << ' -rotate '+rotate_by_n_degrees?+' '
end
_ << add_quality if _.start_with? 'convert'
_ << " #{i}" unless _.include? '--replace-input'
_ << " #{output_file}" end
_.rstrip!
_.squeeze!(' ')
case be_verbose
when :be_quiet
be_verbose = false
end
if be_verbose
esystem _
else
system _
end
if _.include?('--replace-input') and qpdf_was_used?
delete_these_files = Dir['*.pdf.~qpdf-orig']
delete_these_files.each {|this_file|
delete_this_file(this_file)
}
end
if File.exist?(output_file) and is_on_roebe? and be_verbose
require 'open'
Open[output_file] end
end
|
150
151
152
|
# File 'lib/pdf_paradise/utility_scripts/rotate_pdf_file.rb', line 150
def input?
@input
end
|
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
# File 'lib/pdf_paradise/utility_scripts/rotate_pdf_file.rb', line 200
def (
i = @commandline_arguments
)
if i.is_a? Array
i.each {|entry|
(entry)
}
else
case i
when /-?-?help$/i show_help
exit
when /-?-?rotate=(\d{1,5})$/i
set_rotate_level($1.to_s)
end
end
end
|
#notify_the_user_that_the_conversion_has_finished ⇒ Object
#
notify_the_user_that_the_conversion_has_finished
#
190
191
192
193
194
195
|
# File 'lib/pdf_paradise/utility_scripts/rotate_pdf_file.rb', line 190
def notify_the_user_that_the_conversion_has_finished
e 'Finished converting! The file should now reside at:'
e
e sfile(" #{output_file?}")
e
end
|
#opnn ⇒ Object
169
170
171
|
# File 'lib/pdf_paradise/utility_scripts/rotate_pdf_file.rb', line 169
def opnn
Opn.opn(namespace: namespace?)
end
|
#output_file?(i = input?
) ⇒ Boolean
157
158
159
160
161
162
163
164
|
# File 'lib/pdf_paradise/utility_scripts/rotate_pdf_file.rb', line 157
def output_file?(
i = input?
)
return i if @overwrite_the_original_file _ = basename(i).delete_suffix('.pdf')
_.tr(' ','') if _.include? ' '
return "rotated_pdf_file_#{_}.pdf"
end
|
#qpdf_was_used? ⇒ Boolean
92
93
94
|
# File 'lib/pdf_paradise/utility_scripts/rotate_pdf_file.rb', line 92
def qpdf_was_used?
@use_this_command == :qpdf
end
|
#reset ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/pdf_paradise/utility_scripts/rotate_pdf_file.rb', line 74
def reset
infer_the_namespace
@use_this_command = :qpdf set_rotate @overwrite_the_original_file = true
end
|
#rotate_by_n_degrees? ⇒ Boolean
Also known as:
rotate?
176
177
178
|
# File 'lib/pdf_paradise/utility_scripts/rotate_pdf_file.rb', line 176
def rotate_by_n_degrees?
@rotate_by_n_degrees
end
|
#run ⇒ Object
293
294
295
296
297
|
# File 'lib/pdf_paradise/utility_scripts/rotate_pdf_file.rb', line 293
def run
do_convert_this_pdf_file(input?)
notify_the_user_that_the_conversion_has_finished
end
|
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/pdf_paradise/utility_scripts/rotate_pdf_file.rb', line 110
def set_input(i = '')
i = i.join(' ').strip if i.is_a? Array
i = i.to_s.dup
if i.start_with? 'file://'
i.sub!(/^file:\/\//,'')
end
case i
when ROTATE_REGEX, /--rotate/ i =~ ROTATE_REGEX
set_rotate($2.to_s.dup)
i.gsub!(/#{$1.to_s}/, '')
end unless File.exist? i
i = i.to_s.strip
@input = i
end
|
#set_rotate(i = ROTATE_BY_N_DEGREES) ⇒ Object
Also known as:
set_rotate_level
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/pdf_paradise/utility_scripts/rotate_pdf_file.rb', line 133
def set_rotate(
i = ROTATE_BY_N_DEGREES
)
i = i.to_i
case @use_this_command
when :qpdf
i = "+#{i}" if i > 0
end
@rotate_by_n_degrees = i.to_s.dup end
|
#show_help ⇒ Object
99
100
101
102
103
104
105
|
# File 'lib/pdf_paradise/utility_scripts/rotate_pdf_file.rb', line 99
def show_help
opne 'The available options are:'
e
eparse ' --rotate N # rotate by n degrees (into '\
'clockwise direction. Example: rotatepdf --rotate 90 foo.pdf)'
e
end
|