pdf_paradise 0.1.66
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of pdf_paradise might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/README.md +705 -0
- data/bin/automatic_pdf_title +7 -0
- data/bin/combine_these_pdf_pages +7 -0
- data/bin/compress_via_hexapdf +7 -0
- data/bin/convert_markdown_to_pdf +7 -0
- data/bin/convert_pdf_to_text +7 -0
- data/bin/delete_first_page_of_this_pdf_file +7 -0
- data/bin/merge_then_open +7 -0
- data/bin/n_pages +10 -0
- data/bin/open_main_pdf +7 -0
- data/bin/pdf_paradise +9 -0
- data/bin/set_main_book +7 -0
- data/bin/set_title_of_this_pdf_file +15 -0
- data/doc/README.gen +662 -0
- data/doc/todo/todo.md +7 -0
- data/lib/pdf_paradise/base/base.rb +239 -0
- data/lib/pdf_paradise/base/colours.rb +36 -0
- data/lib/pdf_paradise/commandline/commandline.rb +101 -0
- data/lib/pdf_paradise/commandline/help.rb +73 -0
- data/lib/pdf_paradise/commandline/menu.rb +142 -0
- data/lib/pdf_paradise/compress/compress_via_hexapdf.rb +27 -0
- data/lib/pdf_paradise/compress_this_pdf_file.rb +87 -0
- data/lib/pdf_paradise/constants/constants.rb +76 -0
- data/lib/pdf_paradise/convert_text_to_pdf.rb +94 -0
- data/lib/pdf_paradise/css/project.css +17 -0
- data/lib/pdf_paradise/djvu_to_pdf.rb +85 -0
- data/lib/pdf_paradise/gui/README.md +6 -0
- data/lib/pdf_paradise/gui/fox/split_pdf_file.rb +77 -0
- data/lib/pdf_paradise/gui/gtk2/delete_the_first_or_the_last_page_of_this_pdf_file/delete_the_first_or_the_last_page_of_this_pdf_file.rb +39 -0
- data/lib/pdf_paradise/gui/gtk2/pdf_viewer/pdf_viewer.rb +34 -0
- data/lib/pdf_paradise/gui/gtk2/split_pdf_file/split_pdf_file.rb +34 -0
- data/lib/pdf_paradise/gui/gtk2/statistics_widget/statistics_widget.rb +34 -0
- data/lib/pdf_paradise/gui/gtk2/to_pdf/to_pdf.rb +32 -0
- data/lib/pdf_paradise/gui/gtk3/controller/controller.rb +212 -0
- data/lib/pdf_paradise/gui/gtk3/convert_pdf_to_text/convert_pdf_to_text.rb +34 -0
- data/lib/pdf_paradise/gui/gtk3/delete_the_first_or_the_last_page_of_this_pdf_file/delete_the_first_or_the_last_page_of_this_pdf_file.rb +39 -0
- data/lib/pdf_paradise/gui/gtk3/pdf_viewer/pdf_viewer.rb +34 -0
- data/lib/pdf_paradise/gui/gtk3/split_pdf_file/split_pdf_file.rb +34 -0
- data/lib/pdf_paradise/gui/gtk3/statistics_widget/statistics_widget.rb +34 -0
- data/lib/pdf_paradise/gui/gtk3/to_pdf/to_pdf.rb +32 -0
- data/lib/pdf_paradise/gui/libui/extract_all_images_from_this_pdf_file/extract_all_images_from_this_pdf_file.rb +223 -0
- data/lib/pdf_paradise/gui/libui/statistics_widget/statistics_widget.rb +233 -0
- data/lib/pdf_paradise/gui/shared_code/convert_pdf_to_text/convert_pdf_to_text_module.rb +277 -0
- data/lib/pdf_paradise/gui/shared_code/delete_the_first_or_the_last_page_of_this_pdf_file/delete_the_first_or_the_last_page_of_this_pdf_file_module.rb +443 -0
- data/lib/pdf_paradise/gui/shared_code/pdf_viewer/pdf_viewer.css +5 -0
- data/lib/pdf_paradise/gui/shared_code/pdf_viewer/pdf_viewer_module.rb +284 -0
- data/lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file.css +0 -0
- data/lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb +294 -0
- data/lib/pdf_paradise/gui/shared_code/statistics_widget/statistics_widget_module.rb +349 -0
- data/lib/pdf_paradise/gui/shared_code/to_pdf/to_pdf_module.rb +281 -0
- data/lib/pdf_paradise/hexapdf/001_rainbow_pattern_example.rb +0 -0
- data/lib/pdf_paradise/hexapdf/hexapdf.rb +123 -0
- data/lib/pdf_paradise/images/PDF_PARADISE_LOGO.png +0 -0
- data/lib/pdf_paradise/main_pdf/main_pdf.rb +444 -0
- data/lib/pdf_paradise/merge_pdf/menu.rb +63 -0
- data/lib/pdf_paradise/merge_pdf/merge_pdf.rb +306 -0
- data/lib/pdf_paradise/merge_pdf_namespace.rb +9 -0
- data/lib/pdf_paradise/merge_then_open/merge_then_open.rb +105 -0
- data/lib/pdf_paradise/pdf_file_n_total_pages.rb +249 -0
- data/lib/pdf_paradise/prawn_addons/README.md +2 -0
- data/lib/pdf_paradise/prawn_addons/prawn_addons.rb +17 -0
- data/lib/pdf_paradise/project/project.rb +22 -0
- data/lib/pdf_paradise/remove_pdf_password.rb +391 -0
- data/lib/pdf_paradise/requires/batch_require_toplevel_files.rb +22 -0
- data/lib/pdf_paradise/requires/colours.rb +7 -0
- data/lib/pdf_paradise/requires/colours_and_esystem_and_save_file_and_fileutils_and_opn.rb +11 -0
- data/lib/pdf_paradise/requires/esystem_and_colours.rb +10 -0
- data/lib/pdf_paradise/requires/esystem_and_opn_and_colours.rb +8 -0
- data/lib/pdf_paradise/requires/require_the_whole_project.rb +28 -0
- data/lib/pdf_paradise/requires/require_utility_scripts.rb +9 -0
- data/lib/pdf_paradise/set_main_book.rb +156 -0
- data/lib/pdf_paradise/set_pdf_title.rb +220 -0
- data/lib/pdf_paradise/sinatra/embeddable_interface.rb +318 -0
- data/lib/pdf_paradise/toplevel_methods/automatic_pdf_title.rb +55 -0
- data/lib/pdf_paradise/toplevel_methods/convert_epub_to_pdf.rb +27 -0
- data/lib/pdf_paradise/toplevel_methods/convert_markdown_to_pdf.rb +45 -0
- data/lib/pdf_paradise/toplevel_methods/convert_ppt_to_pdf.rb +35 -0
- data/lib/pdf_paradise/toplevel_methods/e.rb +16 -0
- data/lib/pdf_paradise/toplevel_methods/esystem.rb +19 -0
- data/lib/pdf_paradise/toplevel_methods/misc.rb +76 -0
- data/lib/pdf_paradise/toplevel_methods/number_pages.rb +38 -0
- data/lib/pdf_paradise/toplevel_methods/opened_pdf_files.rb +221 -0
- data/lib/pdf_paradise/toplevel_methods/query_pdf_title.rb +191 -0
- data/lib/pdf_paradise/toplevel_methods/reduce_size_of_this_pdf_file.rb +46 -0
- data/lib/pdf_paradise/toplevel_methods/roebe.rb +17 -0
- data/lib/pdf_paradise/toplevel_methods/rotate_pdf_file.rb +143 -0
- data/lib/pdf_paradise/toplevel_methods/to_pdf.rb +38 -0
- data/lib/pdf_paradise/utility_scripts/README.md +3 -0
- data/lib/pdf_paradise/utility_scripts/combine_these_pdf_pages.rb +118 -0
- data/lib/pdf_paradise/utility_scripts/convert_pdf_to_text.rb +175 -0
- data/lib/pdf_paradise/utility_scripts/delete_first_page_of_this_pdf_file.rb +221 -0
- data/lib/pdf_paradise/utility_scripts/delete_last_page_of_this_pdf_file.rb +180 -0
- data/lib/pdf_paradise/utility_scripts/delete_this_page_of_this_pdf_file.rb +329 -0
- data/lib/pdf_paradise/utility_scripts/extract_all_images_from_this_pdf_file.rb +129 -0
- data/lib/pdf_paradise/utility_scripts/extract_pdf_page.rb +283 -0
- data/lib/pdf_paradise/utility_scripts/pdf_optimizer.rb +111 -0
- data/lib/pdf_paradise/utility_scripts/pdf_statistics.rb +148 -0
- data/lib/pdf_paradise/utility_scripts/pdf_to_html.rb +75 -0
- data/lib/pdf_paradise/utility_scripts/remove_images.rb +110 -0
- data/lib/pdf_paradise/utility_scripts/split_pdf.rb +340 -0
- data/lib/pdf_paradise/utility_scripts/to_qdf.rb +82 -0
- data/lib/pdf_paradise/version/version.rb +19 -0
- data/lib/pdf_paradise/www/README.md +2 -0
- data/lib/pdf_paradise/www/sinatra/app.rb +276 -0
- data/lib/pdf_paradise/yaml/working_on_these_pdf_files.yml +4 -0
- data/lib/pdf_paradise.rb +5 -0
- data/pdf_paradise.gemspec +61 -0
- data/test/testing_pdf_paradise.rb +9 -0
- metadata +219 -0
@@ -0,0 +1,180 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === PdfParadise::DeleteLastPageOfThisPdfFile
|
6
|
+
#
|
7
|
+
# This class will accept one (or several) .pdf files and then proceed
|
8
|
+
# to remove the very last .pdf page in that file. So if that pdf-file
|
9
|
+
# has had 100 pages, we will end up with 99 pages.
|
10
|
+
#
|
11
|
+
# By default, the class here will create a new output file and leave
|
12
|
+
# the original file untouched.
|
13
|
+
#
|
14
|
+
# Note that this functionality depends on either "qpdf" or "pdftk".
|
15
|
+
# =========================================================================== #
|
16
|
+
# require 'pdf_paradise/utility_scripts/delete_last_page_of_this_pdf_file.rb'
|
17
|
+
# =========================================================================== #
|
18
|
+
require 'pdf_paradise/base/base.rb'
|
19
|
+
require 'pdf_paradise/pdf_file_n_total_pages.rb'
|
20
|
+
|
21
|
+
module PdfParadise
|
22
|
+
|
23
|
+
class DeleteLastPageOfThisPdfFile < Base
|
24
|
+
|
25
|
+
# ========================================================================= #
|
26
|
+
# === NAMESPACE
|
27
|
+
# ========================================================================= #
|
28
|
+
NAMESPACE = inspect
|
29
|
+
|
30
|
+
# ========================================================================= #
|
31
|
+
# === OVERWRITE_THE_OLD_PDF_FILE
|
32
|
+
#
|
33
|
+
# If the following constant is set to true then the given input
|
34
|
+
# file will be overwritten.
|
35
|
+
# ========================================================================= #
|
36
|
+
OVERWRITE_THE_OLD_PDF_FILE = true
|
37
|
+
|
38
|
+
# ========================================================================= #
|
39
|
+
# === initialize
|
40
|
+
# ========================================================================= #
|
41
|
+
def initialize(
|
42
|
+
input_files = ARGV,
|
43
|
+
run_already = true
|
44
|
+
)
|
45
|
+
reset
|
46
|
+
set_input_files(input_files)
|
47
|
+
run if run_already
|
48
|
+
end
|
49
|
+
|
50
|
+
# ========================================================================= #
|
51
|
+
# === reset
|
52
|
+
# ========================================================================= #
|
53
|
+
def reset
|
54
|
+
super()
|
55
|
+
# ======================================================================= #
|
56
|
+
# === @namespace
|
57
|
+
# ======================================================================= #
|
58
|
+
@namespace = NAMESPACE
|
59
|
+
# ======================================================================= #
|
60
|
+
# === @overwrite_the_old_pdf_file
|
61
|
+
# ======================================================================= #
|
62
|
+
@overwrite_the_old_pdf_file = OVERWRITE_THE_OLD_PDF_FILE
|
63
|
+
end
|
64
|
+
|
65
|
+
# ========================================================================= #
|
66
|
+
# === set_input_files
|
67
|
+
# ========================================================================= #
|
68
|
+
def set_input_files(i)
|
69
|
+
i = [i] unless i.is_a? Array
|
70
|
+
if i.empty? and is_on_roebe?
|
71
|
+
# ===================================================================== #
|
72
|
+
# In this case we will use the main-pdf file, if it exists.
|
73
|
+
# ===================================================================== #
|
74
|
+
if ENV.has_key?('MAIN_BOOK') and
|
75
|
+
File.exist?(ENV['MAIN_BOOK'])
|
76
|
+
i << ENV['MAIN_BOOK'].dup
|
77
|
+
end
|
78
|
+
end
|
79
|
+
@input_files = i
|
80
|
+
sanitize_input_files
|
81
|
+
end
|
82
|
+
|
83
|
+
# ========================================================================= #
|
84
|
+
# === sanitize_input_files
|
85
|
+
# ========================================================================= #
|
86
|
+
def sanitize_input_files
|
87
|
+
unless @input_files.empty?
|
88
|
+
# ===================================================================== #
|
89
|
+
# Select only .pdf files next.
|
90
|
+
# ===================================================================== #
|
91
|
+
@input_files.select! {|entry|
|
92
|
+
entry.end_with? '.pdf'
|
93
|
+
}
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# ========================================================================= #
|
98
|
+
# === process_each_pdf
|
99
|
+
# ========================================================================= #
|
100
|
+
def process_each_pdf
|
101
|
+
@input_files.each {|this_pdf_file|
|
102
|
+
# ===================================================================== #
|
103
|
+
# First, we must find out how many pdf pages are in the given
|
104
|
+
# pdf file at hand.
|
105
|
+
# ===================================================================== #
|
106
|
+
if File.exist? this_pdf_file
|
107
|
+
opnn; e 'Now working on the .pdf file '+sfancy(this_pdf_file)
|
108
|
+
has_n_pages = PdfParadise.n_pages_in_this_pdf_file?(this_pdf_file) # This is also the last page.
|
109
|
+
if use_pdftk?
|
110
|
+
_ = 'pdftk '+this_pdf_file+' cat 1-'+(has_n_pages.to_i - 1).to_s+' '+
|
111
|
+
has_n_pages.to_s+'-end output '+
|
112
|
+
name_of_the_output_file?(this_pdf_file)
|
113
|
+
else # else we use qpdf
|
114
|
+
_ = 'qpdf'.dup
|
115
|
+
if @overwrite_the_old_pdf_file
|
116
|
+
_ << ' --replace-input'
|
117
|
+
end
|
118
|
+
if @overwrite_the_old_pdf_file
|
119
|
+
_ << ' --pages '+this_pdf_file+' 1-'+(has_n_pages.to_i - 1).to_s+' -- '+
|
120
|
+
this_pdf_file
|
121
|
+
else
|
122
|
+
_ << ' --pages '+this_pdf_file+' 1-'+(has_n_pages.to_i - 1).to_s+' -- '+
|
123
|
+
this_pdf_file+' '+name_of_the_output_file?(this_pdf_file)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
esystem _
|
127
|
+
else
|
128
|
+
opnn; e 'No file exists at `'+sfile(this_pdf_file)+'`.'
|
129
|
+
end
|
130
|
+
}
|
131
|
+
end
|
132
|
+
|
133
|
+
# ========================================================================= #
|
134
|
+
# === name_of_the_output_file?
|
135
|
+
# ========================================================================= #
|
136
|
+
def name_of_the_output_file?(i)
|
137
|
+
if @overwrite_the_old_pdf_file
|
138
|
+
i.sub(/\.pdf$/,'')+'.pdf'
|
139
|
+
else
|
140
|
+
i.sub(/\.pdf$/,'')+'_output_file.pdf'
|
141
|
+
end
|
142
|
+
end; alias output? name_of_the_output_file? # === output?
|
143
|
+
|
144
|
+
# ========================================================================= #
|
145
|
+
# === use_pdftk?
|
146
|
+
# ========================================================================= #
|
147
|
+
def use_pdftk?
|
148
|
+
false
|
149
|
+
end
|
150
|
+
|
151
|
+
# ========================================================================= #
|
152
|
+
# === input?
|
153
|
+
# ========================================================================= #
|
154
|
+
def input?
|
155
|
+
@input_files
|
156
|
+
end
|
157
|
+
|
158
|
+
# ========================================================================= #
|
159
|
+
# === run
|
160
|
+
# ========================================================================= #
|
161
|
+
def run
|
162
|
+
process_each_pdf
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
# =========================================================================== #
|
168
|
+
# === PdfParadise.delete_last_page_of_this_pdf_file
|
169
|
+
#
|
170
|
+
# Easier method-way to invoke the above class.
|
171
|
+
# =========================================================================== #
|
172
|
+
def self.delete_last_page_of_this_pdf_file(i = ARGV)
|
173
|
+
PdfParadise::DeleteLastPageOfThisPdfFile.new(i)
|
174
|
+
end; self.instance_eval { alias remove_the_last_page_of_this_pdf_file delete_last_page_of_this_pdf_file } # === PdfParadise.remove_the_last_page_of_this_pdf_file
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
if __FILE__ == $PROGRAM_NAME
|
179
|
+
PdfParadise::DeleteLastPageOfThisPdfFile.new(ARGV)
|
180
|
+
end # delete_last_page_of_this_pdf_file
|
@@ -0,0 +1,329 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === PdfParadise::DeleteThisPageOfThisPdfFile
|
6
|
+
#
|
7
|
+
# This class will accept one (or several) .pdf files and then proceed
|
8
|
+
# to remove the specified .pdf page in that file.
|
9
|
+
#
|
10
|
+
# By default, the class here will honour the constant called
|
11
|
+
# OVERWRITE_THE_OLD_PDF_FILE in order to determine whether a new
|
12
|
+
# .pdf file is to be created, or whether to modify the original
|
13
|
+
# .pdf file as-is.
|
14
|
+
#
|
15
|
+
# Note that this functionality "contained" in this .rb file depends
|
16
|
+
# on either "qpdf" or "pdftk" - personally I much prefer qpdf these
|
17
|
+
# days.
|
18
|
+
# =========================================================================== #
|
19
|
+
# require 'pdf_paradise/utility_scripts/delete_this_page_of_this_pdf_file.rb'
|
20
|
+
# =========================================================================== #
|
21
|
+
require 'pdf_paradise/base/base.rb'
|
22
|
+
|
23
|
+
module PdfParadise
|
24
|
+
|
25
|
+
class DeleteThisPageOfThisPdfFile < Base
|
26
|
+
|
27
|
+
require 'pdf_paradise/pdf_file_n_total_pages.rb'
|
28
|
+
|
29
|
+
# ========================================================================= #
|
30
|
+
# === NAMESPACE
|
31
|
+
# ========================================================================= #
|
32
|
+
NAMESPACE = inspect
|
33
|
+
|
34
|
+
# ========================================================================= #
|
35
|
+
# === OVERWRITE_THE_OLD_PDF_FILE
|
36
|
+
#
|
37
|
+
# If the following constant is set to true then the given input
|
38
|
+
# file will be overwritten. I prefer this on my home system, so
|
39
|
+
# the default is true for now.
|
40
|
+
# ========================================================================= #
|
41
|
+
OVERWRITE_THE_OLD_PDF_FILE = true
|
42
|
+
|
43
|
+
# ========================================================================= #
|
44
|
+
# === DEFAULT_REMOVE_THIS_PDF_PAGE
|
45
|
+
#
|
46
|
+
# If you don't feel like manually passing data to the .rb file, use
|
47
|
+
# the hardcoded value here.
|
48
|
+
# ========================================================================= #
|
49
|
+
DEFAULT_REMOVE_THIS_PDF_PAGE = 126
|
50
|
+
|
51
|
+
# ========================================================================= #
|
52
|
+
# === initialize
|
53
|
+
# ========================================================================= #
|
54
|
+
def initialize(
|
55
|
+
input_files = ARGV,
|
56
|
+
run_already = true
|
57
|
+
)
|
58
|
+
reset
|
59
|
+
set_commandline_arguments(
|
60
|
+
input_files
|
61
|
+
)
|
62
|
+
set_input_files(
|
63
|
+
input_files
|
64
|
+
)
|
65
|
+
# ======================================================================= #
|
66
|
+
# === Handle Blocks next
|
67
|
+
# ======================================================================= #
|
68
|
+
if block_given?
|
69
|
+
yielded = yield
|
70
|
+
case yielded
|
71
|
+
when :do_not_run_yet
|
72
|
+
run_already = false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
run if run_already
|
76
|
+
end
|
77
|
+
|
78
|
+
# ========================================================================= #
|
79
|
+
# === reset
|
80
|
+
# ========================================================================= #
|
81
|
+
def reset
|
82
|
+
super()
|
83
|
+
# ======================================================================= #
|
84
|
+
# === @namespace
|
85
|
+
# ======================================================================= #
|
86
|
+
@namespace = NAMESPACE
|
87
|
+
# ======================================================================= #
|
88
|
+
# === @overwrite_the_old_pdf_file
|
89
|
+
#
|
90
|
+
# This determines whether the old .pdf file will be overwritten.
|
91
|
+
# ======================================================================= #
|
92
|
+
@overwrite_the_old_pdf_file = OVERWRITE_THE_OLD_PDF_FILE
|
93
|
+
# ======================================================================= #
|
94
|
+
# === @remove_this_pdf_page
|
95
|
+
#
|
96
|
+
# This variable keeps track as to which particular page we wish
|
97
|
+
# to remove from our .pdf file. By default we will set to one
|
98
|
+
# as is anyway.
|
99
|
+
# ======================================================================= #
|
100
|
+
@remove_this_pdf_page = DEFAULT_REMOVE_THIS_PDF_PAGE
|
101
|
+
# ======================================================================= #
|
102
|
+
# === @use_this_program
|
103
|
+
# ======================================================================= #
|
104
|
+
@use_this_program = 'hexapdf' # qpdf'
|
105
|
+
end
|
106
|
+
|
107
|
+
# ========================================================================= #
|
108
|
+
# === show_help
|
109
|
+
# ========================================================================= #
|
110
|
+
def show_help
|
111
|
+
e
|
112
|
+
e 'The first argument should be the .pdf file.'
|
113
|
+
e 'The second argument should be the page number.'
|
114
|
+
e
|
115
|
+
end
|
116
|
+
|
117
|
+
# ========================================================================= #
|
118
|
+
# === set_input_files
|
119
|
+
# ========================================================================= #
|
120
|
+
def set_input_files(i)
|
121
|
+
i = [i] unless i.is_a? Array
|
122
|
+
@input_files = i
|
123
|
+
sanitize_input_files
|
124
|
+
end; alias set_pdf_file set_input_files # === set_pdf_file
|
125
|
+
alias set_pdf_files set_input_files # === set_pdf_files
|
126
|
+
|
127
|
+
# ========================================================================= #
|
128
|
+
# === sanitize_input_files
|
129
|
+
# ========================================================================= #
|
130
|
+
def sanitize_input_files
|
131
|
+
unless @input_files.empty?
|
132
|
+
set_page_number(
|
133
|
+
@input_files.select {|entry|
|
134
|
+
# ================================================================= #
|
135
|
+
# Get numbers.
|
136
|
+
# ================================================================= #
|
137
|
+
entry =~ /^\d+$/
|
138
|
+
}
|
139
|
+
)
|
140
|
+
# ===================================================================== #
|
141
|
+
# Select only .pdf files next.
|
142
|
+
# ===================================================================== #
|
143
|
+
@input_files.select! {|entry|
|
144
|
+
entry.end_with? '.pdf'
|
145
|
+
}
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
# ========================================================================= #
|
150
|
+
# === return_the_proper_range
|
151
|
+
#
|
152
|
+
# This method will return the proper range, such as:
|
153
|
+
#
|
154
|
+
# 1-9,11-z
|
155
|
+
#
|
156
|
+
# The ',' will be included in the return value by this method.
|
157
|
+
# ========================================================================= #
|
158
|
+
def return_the_proper_range
|
159
|
+
before_part = "1-#{(@remove_this_pdf_page - 1).to_s}"
|
160
|
+
after_part = (@remove_this_pdf_page + 1).to_s+'-z'
|
161
|
+
"#{before_part},#{after_part}"
|
162
|
+
end
|
163
|
+
|
164
|
+
# ========================================================================= #
|
165
|
+
# === name_of_the_output_file?
|
166
|
+
# ========================================================================= #
|
167
|
+
def name_of_the_output_file?(i)
|
168
|
+
if @overwrite_the_old_pdf_file
|
169
|
+
i.sub(/\.pdf$/,'')+'.pdf'
|
170
|
+
else
|
171
|
+
i.sub(/\.pdf$/,'')+'_output_file.pdf'
|
172
|
+
end
|
173
|
+
end; alias output? name_of_the_output_file? # === output?
|
174
|
+
|
175
|
+
# ========================================================================= #
|
176
|
+
# === input?
|
177
|
+
# ========================================================================= #
|
178
|
+
def input?
|
179
|
+
@input_files
|
180
|
+
end
|
181
|
+
|
182
|
+
# ========================================================================= #
|
183
|
+
# === process_each_pdf
|
184
|
+
# ========================================================================= #
|
185
|
+
def process_each_pdf
|
186
|
+
@input_files.each {|this_pdf_file|
|
187
|
+
# ===================================================================== #
|
188
|
+
# The command should be something like this:
|
189
|
+
#
|
190
|
+
# qpdf input.pdf --pages input.pdf 1-9,26-z -- outputfile.pdf
|
191
|
+
#
|
192
|
+
# See: https://superuser.com/a/1297395
|
193
|
+
# ===================================================================== #
|
194
|
+
if File.exist? this_pdf_file
|
195
|
+
opnn; e 'Now working on the .pdf file '+sfancy(this_pdf_file)+
|
196
|
+
', containing '+n_pages?(this_pdf_file).to_s+' pages.'
|
197
|
+
opnn; e 'The page that will be removed is: '+
|
198
|
+
steelblue(@remove_this_pdf_page.to_s)
|
199
|
+
case @use_this_program
|
200
|
+
when /qpdf/
|
201
|
+
_ = @use_this_program.dup
|
202
|
+
_ << " #{this_pdf_file}"
|
203
|
+
_ << " --pages #{this_pdf_file} "+return_the_proper_range
|
204
|
+
_ << " -- output.pdf"
|
205
|
+
when /hexapdf/
|
206
|
+
_ = @use_this_program.dup
|
207
|
+
_ << ' modify'
|
208
|
+
_ << " #{this_pdf_file}"
|
209
|
+
_ << ' -i '+return_the_proper_range.tr('z','e')
|
210
|
+
_ << " output.pdf"
|
211
|
+
end
|
212
|
+
e
|
213
|
+
esystem _
|
214
|
+
e
|
215
|
+
if @overwrite_the_old_pdf_file
|
216
|
+
output_file = 'output.pdf'
|
217
|
+
if File.exist? output_file
|
218
|
+
File.delete(this_pdf_file) if File.exist? this_pdf_file
|
219
|
+
move_file(output_file, this_pdf_file)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
opnn; e 'The .pdf file at '+sfancy(this_pdf_file)+
|
223
|
+
' now contains '+n_pages?(this_pdf_file).to_s+' pages.'
|
224
|
+
else
|
225
|
+
opnn; e "No file exists at `#{sfile(this_pdf_file)}`."
|
226
|
+
end
|
227
|
+
}
|
228
|
+
end
|
229
|
+
|
230
|
+
# ========================================================================= #
|
231
|
+
# === remove_this_pdf_page?
|
232
|
+
# ========================================================================= #
|
233
|
+
def remove_this_pdf_page?
|
234
|
+
@remove_this_pdf_page
|
235
|
+
end; alias page_number? remove_this_pdf_page? # === page_number?
|
236
|
+
|
237
|
+
# ========================================================================= #
|
238
|
+
# === set_remove_this_pdf_page
|
239
|
+
# ========================================================================= #
|
240
|
+
def set_remove_this_pdf_page(
|
241
|
+
i = nil
|
242
|
+
)
|
243
|
+
if i
|
244
|
+
if i.is_a? Array
|
245
|
+
i = i.first
|
246
|
+
end
|
247
|
+
if i.nil?
|
248
|
+
# In this case use the default value.
|
249
|
+
i = DEFAULT_REMOVE_THIS_PDF_PAGE
|
250
|
+
end
|
251
|
+
@remove_this_pdf_page = i.to_i
|
252
|
+
end
|
253
|
+
end; alias set_page_number set_remove_this_pdf_page # === set_page_number
|
254
|
+
|
255
|
+
# ========================================================================= #
|
256
|
+
# === menu (menu tag)
|
257
|
+
# ========================================================================= #
|
258
|
+
def menu(
|
259
|
+
i = return_commandline_arguments_starting_with_hyphens
|
260
|
+
)
|
261
|
+
if i.is_a? Array
|
262
|
+
i.each {|entry| menu(entry) }
|
263
|
+
else
|
264
|
+
case i
|
265
|
+
# ===================================================================== #
|
266
|
+
# === deletethispageofthispdffile DONE*pdf --remove-this-page-number=430
|
267
|
+
#
|
268
|
+
# Remove specific pages from a given .pdf file.
|
269
|
+
#
|
270
|
+
# Usage example:
|
271
|
+
#
|
272
|
+
# pagegone DONE*pdf --remove-this-page-number=360
|
273
|
+
# pagegone DONE*pdf --remove=94
|
274
|
+
# pagegone DONE*pdf --remove=162
|
275
|
+
# pagegone DONE*pdf --remove=307
|
276
|
+
#
|
277
|
+
# ===================================================================== #
|
278
|
+
when /^-?-?remove(-|_)?this(-|_)?page(-|_)?number=(.+)$/i, # === $4
|
279
|
+
/^-?-?remove=(.+)$/i # === $1
|
280
|
+
_ = $1.to_s.dup
|
281
|
+
_ = $4.to_s.dup if $4
|
282
|
+
set_remove_this_pdf_page(_)
|
283
|
+
# ===================================================================== #
|
284
|
+
# === --help
|
285
|
+
# ===================================================================== #
|
286
|
+
when /help/
|
287
|
+
show_help
|
288
|
+
exit
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
# ========================================================================= #
|
294
|
+
# === run
|
295
|
+
# ========================================================================= #
|
296
|
+
def run
|
297
|
+
menu
|
298
|
+
process_each_pdf
|
299
|
+
end
|
300
|
+
|
301
|
+
end
|
302
|
+
|
303
|
+
# =========================================================================== #
|
304
|
+
# === PdfParadise.remove_this_page_of_that_pdf_file
|
305
|
+
# =========================================================================== #
|
306
|
+
def self.remove_this_page_of_that_pdf_file(
|
307
|
+
this_page,
|
308
|
+
that_pdf_file
|
309
|
+
)
|
310
|
+
_ = PdfParadise::DeleteThisPageOfThisPdfFile.new { :do_not_run_yet }
|
311
|
+
_.set_pdf_file(that_pdf_file)
|
312
|
+
_.set_remove_this_pdf_page(this_page)
|
313
|
+
_.run
|
314
|
+
end
|
315
|
+
|
316
|
+
# =========================================================================== #
|
317
|
+
# === PdfParadise.delete_last_page_of_this_pdf_file
|
318
|
+
#
|
319
|
+
# Easier method-way to invoke the above class.
|
320
|
+
# =========================================================================== #
|
321
|
+
def self.delete_last_page_of_this_pdf_file(i = ARGV)
|
322
|
+
PdfParadise::DeleteThisPageOfThisPdfFile.new(i)
|
323
|
+
end
|
324
|
+
|
325
|
+
end
|
326
|
+
|
327
|
+
if __FILE__ == $PROGRAM_NAME
|
328
|
+
PdfParadise::DeleteThisPageOfThisPdfFile.new(ARGV)
|
329
|
+
end # deletethispageofthispdffile
|
@@ -0,0 +1,129 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === PdfParadise::ExtractAllImagesFromThisPdfFile
|
6
|
+
# =========================================================================== #
|
7
|
+
# require 'pdf_paradise/utility_scripts/extract_all_images_from_this_pdf_file.rb'
|
8
|
+
# PdfParadise::ExtractAllImagesFromThisPdfFile.new
|
9
|
+
# =========================================================================== #
|
10
|
+
require 'pdf_paradise/base/base.rb'
|
11
|
+
|
12
|
+
module PdfParadise
|
13
|
+
|
14
|
+
class ExtractAllImagesFromThisPdfFile < PdfParadise::Base # === PdfParadise::ExtractAllImagesFromThisPdfFile
|
15
|
+
|
16
|
+
require 'pdf_paradise/pdf_file_n_total_pages.rb'
|
17
|
+
|
18
|
+
# ========================================================================= #
|
19
|
+
# === NAMESPACE
|
20
|
+
# ========================================================================= #
|
21
|
+
NAMESPACE = inspect
|
22
|
+
|
23
|
+
# ========================================================================= #
|
24
|
+
# === initialize
|
25
|
+
# ========================================================================= #
|
26
|
+
def initialize(
|
27
|
+
commandline_arguments = ARGV,
|
28
|
+
run_already = true
|
29
|
+
)
|
30
|
+
reset
|
31
|
+
set_commandline_arguments(
|
32
|
+
commandline_arguments
|
33
|
+
)
|
34
|
+
case run_already
|
35
|
+
# ======================================================================= #
|
36
|
+
# === :do_not_run_yet
|
37
|
+
# ======================================================================= #
|
38
|
+
when :do_not_run_yet
|
39
|
+
run_already = false
|
40
|
+
end
|
41
|
+
make_sure_that_the_first_argument_is_not_a_symbol
|
42
|
+
run if run_already
|
43
|
+
end
|
44
|
+
|
45
|
+
# ========================================================================= #
|
46
|
+
# === reset (reset tag)
|
47
|
+
# ========================================================================= #
|
48
|
+
def reset
|
49
|
+
super()
|
50
|
+
end
|
51
|
+
|
52
|
+
# ========================================================================= #
|
53
|
+
# === make_sure_that_the_first_argument_is_not_a_symbol
|
54
|
+
# ========================================================================= #
|
55
|
+
def make_sure_that_the_first_argument_is_not_a_symbol
|
56
|
+
if @commandline_arguments
|
57
|
+
if @commandline_arguments.is_a? Symbol
|
58
|
+
@commandline_arguments = []
|
59
|
+
elsif @commandline_arguments.first.is_a? Symbol
|
60
|
+
@commandline_arguments.shift
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# ========================================================================= #
|
66
|
+
# === opnn
|
67
|
+
# ========================================================================= #
|
68
|
+
def opnn
|
69
|
+
super(NAMESPACE)
|
70
|
+
end
|
71
|
+
|
72
|
+
# ========================================================================= #
|
73
|
+
# === determine_the_raw_name
|
74
|
+
#
|
75
|
+
# This method will determine the raw filename.
|
76
|
+
# ========================================================================= #
|
77
|
+
def determine_the_raw_name(
|
78
|
+
_ = first_argument?
|
79
|
+
)
|
80
|
+
if _ and _.is_a?(Array)
|
81
|
+
_ = _.first
|
82
|
+
end
|
83
|
+
if _
|
84
|
+
_ = _.dup # Work on a copy.
|
85
|
+
_.delete_suffix!('.pdf')
|
86
|
+
_ = File.basename(_) if _.include? '/'
|
87
|
+
end
|
88
|
+
# ======================================================================= #
|
89
|
+
# === @raw_name
|
90
|
+
# ======================================================================= #
|
91
|
+
@raw_name = _
|
92
|
+
end
|
93
|
+
|
94
|
+
# ========================================================================= #
|
95
|
+
# === do_extract_the_pdf_file
|
96
|
+
# ========================================================================= #
|
97
|
+
def do_extract_the_pdf_file(
|
98
|
+
i = first_argument?
|
99
|
+
)
|
100
|
+
if @raw_name.nil?
|
101
|
+
determine_the_raw_name(i) if i
|
102
|
+
end
|
103
|
+
if i and File.exist?(i)
|
104
|
+
cmd = "pdfimages -j #{i} #{@raw_name}"
|
105
|
+
e
|
106
|
+
esystem cmd
|
107
|
+
e
|
108
|
+
else
|
109
|
+
e "No file exists at `#{i}`."
|
110
|
+
false
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# ========================================================================= #
|
115
|
+
# === run (run tag)
|
116
|
+
# ========================================================================= #
|
117
|
+
def run
|
118
|
+
_ = first_argument?
|
119
|
+
determine_the_raw_name(_)
|
120
|
+
if _ and File.exist?(_)
|
121
|
+
do_extract_the_pdf_file(_)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end; end
|
126
|
+
|
127
|
+
if __FILE__ == $PROGRAM_NAME
|
128
|
+
PdfParadise::ExtractAllImagesFromThisPdfFile.new(ARGV)
|
129
|
+
end # eimages
|