Class: PdfParadise::DeleteLastPageOfThisPdfFile
- Inherits:
-
Base
- Object
- Base
- PdfParadise::DeleteLastPageOfThisPdfFile
show all
- Defined in:
- lib/pdf_paradise/utility_scripts/delete_last_page_of_this_pdf_file.rb
Constant Summary
collapse
- OVERWRITE_THE_OLD_PDF_FILE =
#
OVERWRITE_THE_OLD_PDF_FILE
If the following constant is set to true then the given input file will be overwritten.
#
true
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, #opnn, #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
37
38
39
40
41
42
43
44
|
# File 'lib/pdf_paradise/utility_scripts/delete_last_page_of_this_pdf_file.rb', line 37
def initialize(
input_files = ARGV,
run_already = true
)
reset
set_input_files(input_files)
run if run_already
end
|
Instance Method Details
153
154
155
|
# File 'lib/pdf_paradise/utility_scripts/delete_last_page_of_this_pdf_file.rb', line 153
def input?
@input_files
end
|
#name_of_the_output_file?(i) ⇒ Boolean
Also known as:
output?
#
name_of_the_output_file?
#
135
136
137
138
139
140
141
|
# File 'lib/pdf_paradise/utility_scripts/delete_last_page_of_this_pdf_file.rb', line 135
def name_of_the_output_file?(i)
if @overwrite_the_old_pdf_file
i.sub(/\.pdf$/,'')+'.pdf'
else
i.sub(/\.pdf$/,'')+'_output_file.pdf'
end
end
|
#process_each_pdf ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
# File 'lib/pdf_paradise/utility_scripts/delete_last_page_of_this_pdf_file.rb', line 93
def process_each_pdf
@input_files.each {|this_pdf_file|
if File.exist? this_pdf_file
has_n_pages = ::PdfParadise.has_n_pages?(this_pdf_file)
opne 'Now working on the .pdf file '+sfancy(this_pdf_file)+
rev+' ('+steelblue(has_n_pages.to_s+' pages')+rev+')'
has_n_pages = PdfParadise.n_pages_in_this_pdf_file?(this_pdf_file) if use_pdftk?
_ = 'pdftk '+this_pdf_file+' cat 1-'+(has_n_pages.to_i - 1).to_s+' '+
has_n_pages.to_s+'-end output '+
name_of_the_output_file?(this_pdf_file)
else _ = 'qpdf'.dup
if @overwrite_the_old_pdf_file
_ << ' --replace-input'
end
if @overwrite_the_old_pdf_file
_ << ' --pages '+this_pdf_file+' 1-'+(has_n_pages.to_i - 1).to_s+' -- '+
this_pdf_file
else
_ << ' --pages '+this_pdf_file+' 1-'+(has_n_pages.to_i - 1).to_s+' -- '+
this_pdf_file+' '+name_of_the_output_file?(this_pdf_file)
end
end
begin
esystem _ rescue Exception => error
pp error
end
else
opne 'No file exists at `'+sfile(this_pdf_file)+'`.'
end
}
end
|
#reset ⇒ Object
49
50
51
52
53
54
55
56
|
# File 'lib/pdf_paradise/utility_scripts/delete_last_page_of_this_pdf_file.rb', line 49
def reset
super()
infer_the_namespace
@overwrite_the_old_pdf_file = OVERWRITE_THE_OLD_PDF_FILE
end
|
#run ⇒ Object
160
161
162
|
# File 'lib/pdf_paradise/utility_scripts/delete_last_page_of_this_pdf_file.rb', line 160
def run
process_each_pdf
end
|
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/pdf_paradise/utility_scripts/delete_last_page_of_this_pdf_file.rb', line 79
def sanitize_input_files
unless @input_files.empty?
@input_files.select! {|entry|
entry.end_with? '.pdf'
}
end
end
|
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/pdf_paradise/utility_scripts/delete_last_page_of_this_pdf_file.rb', line 61
def set_input_files(i)
i = [i] unless i.is_a? Array
if i.empty? and is_on_roebe?
if ENV.has_key?('MAIN_BOOK') and
File.exist?(ENV['MAIN_BOOK'])
i << ENV['MAIN_BOOK'].dup
end
end
@input_files = i
sanitize_input_files
end
|
#use_pdftk? ⇒ Boolean
146
147
148
|
# File 'lib/pdf_paradise/utility_scripts/delete_last_page_of_this_pdf_file.rb', line 146
def use_pdftk?
false
end
|