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,22 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'pdf_paradise/project/project.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module PdfParadise
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === PdfParadise::PROJECT_BASE_DIRECTORY
|
11
|
+
# ========================================================================= #
|
12
|
+
PROJECT_BASE_DIRECTORY =
|
13
|
+
File.absolute_path("#{__dir__}/..")+'/'
|
14
|
+
|
15
|
+
# ========================================================================= #
|
16
|
+
# === PdfParadise.project_base_dir?
|
17
|
+
# ========================================================================= #
|
18
|
+
def self.project_base_dir?
|
19
|
+
PROJECT_BASE_DIRECTORY
|
20
|
+
end; self.instance_eval { alias project_base_directory? project_base_dir? } # === PdfParadise.project_base_directory?
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,391 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: false
|
4
|
+
# =========================================================================== #
|
5
|
+
# === PdfParadise::RemovePdfPassword
|
6
|
+
#
|
7
|
+
# Use this class to remove a password from a .pdf file.
|
8
|
+
#
|
9
|
+
# We can either use "qpdf" or "pdftk".
|
10
|
+
#
|
11
|
+
# We could also fetch the password from ENV['PASSWORD'].
|
12
|
+
#
|
13
|
+
# Usage example:
|
14
|
+
#
|
15
|
+
# PdfParadise::RemovePdfPassword.new(ARGV)
|
16
|
+
#
|
17
|
+
# =========================================================================== #
|
18
|
+
# require 'pdf_paradise/remove_pdf_password.rb'
|
19
|
+
# =========================================================================== #
|
20
|
+
require 'pdf_paradise/base/base.rb'
|
21
|
+
|
22
|
+
module PdfParadise
|
23
|
+
|
24
|
+
class RemovePdfPassword < ::PdfParadise::Base # === PdfParadise::RemovePdfPassword
|
25
|
+
|
26
|
+
include FileUtils::Verbose
|
27
|
+
|
28
|
+
# ========================================================================= #
|
29
|
+
# === NAMESPACE
|
30
|
+
# ========================================================================= #
|
31
|
+
NAMESPACE = inspect
|
32
|
+
|
33
|
+
# ========================================================================= #
|
34
|
+
# === PASSWORD
|
35
|
+
#
|
36
|
+
# The password in use can be hardcoded here.
|
37
|
+
# ========================================================================= #
|
38
|
+
PASSWORD = 'Quellbrunn' # AGLMT15'
|
39
|
+
|
40
|
+
# ========================================================================= #
|
41
|
+
# === ARRAY_ALLOWED_PASSWORD_FILES
|
42
|
+
#
|
43
|
+
# A directory may include a PASSWORD.md file. In this case, we will use
|
44
|
+
# that particular file as the new password.
|
45
|
+
# ========================================================================= #
|
46
|
+
ARRAY_ALLOWED_PASSWORD_FILES = %w(
|
47
|
+
PASSWORD.md
|
48
|
+
PASSWORT.md
|
49
|
+
)
|
50
|
+
|
51
|
+
# ========================================================================= #
|
52
|
+
# === REGEX_FOR_PASSWORD
|
53
|
+
# ========================================================================= #
|
54
|
+
REGEX_FOR_PASSWORD = /--password(=| )(.+) ?/
|
55
|
+
|
56
|
+
# ========================================================================= #
|
57
|
+
# === AUTOMATICALLY_REPLACE
|
58
|
+
#
|
59
|
+
# If this constant is set to true then we will automatically
|
60
|
+
# replace the old, existing .pdf file with the newly generated
|
61
|
+
# file.
|
62
|
+
# ========================================================================= #
|
63
|
+
AUTOMATICALLY_REPLACE = false
|
64
|
+
|
65
|
+
# ========================================================================= #
|
66
|
+
# === COMMAND_NOT_FOUND
|
67
|
+
# ========================================================================= #
|
68
|
+
COMMAND_NOT_FOUND = "command not found\n"
|
69
|
+
|
70
|
+
# ========================================================================= #
|
71
|
+
# === initialize
|
72
|
+
# ========================================================================= #
|
73
|
+
def initialize(
|
74
|
+
i = nil,
|
75
|
+
run_already = true
|
76
|
+
)
|
77
|
+
reset
|
78
|
+
set_input(i)
|
79
|
+
run if run_already
|
80
|
+
end
|
81
|
+
|
82
|
+
# ========================================================================= #
|
83
|
+
# === reset (reset tag)
|
84
|
+
# ========================================================================= #
|
85
|
+
def reset
|
86
|
+
super()
|
87
|
+
set_password # Reset it here.
|
88
|
+
@output_file = nil
|
89
|
+
# ======================================================================= #
|
90
|
+
# === @automatically_replace
|
91
|
+
# ======================================================================= #
|
92
|
+
@automatically_replace = AUTOMATICALLY_REPLACE
|
93
|
+
end
|
94
|
+
|
95
|
+
# ========================================================================= #
|
96
|
+
# === input?
|
97
|
+
# ========================================================================= #
|
98
|
+
def input?
|
99
|
+
@input
|
100
|
+
end
|
101
|
+
|
102
|
+
# ========================================================================= #
|
103
|
+
# === run_sys_command
|
104
|
+
# ========================================================================= #
|
105
|
+
def run_sys_command(i = string?)
|
106
|
+
esystem i
|
107
|
+
end
|
108
|
+
|
109
|
+
# ========================================================================= #
|
110
|
+
# === string?
|
111
|
+
# ========================================================================= #
|
112
|
+
def string?
|
113
|
+
@string
|
114
|
+
end
|
115
|
+
|
116
|
+
# ========================================================================= #
|
117
|
+
# === set_password
|
118
|
+
# ========================================================================= #
|
119
|
+
def set_password(i = PASSWORD)
|
120
|
+
@password = i
|
121
|
+
end
|
122
|
+
|
123
|
+
# ========================================================================= #
|
124
|
+
# === mv
|
125
|
+
# ========================================================================= #
|
126
|
+
def mv(old, new)
|
127
|
+
new = new.strip # We don't want any newlines.
|
128
|
+
if File.exist? old
|
129
|
+
opnn; e "Now replacing `#{sfancy(old)}` with `#{simp(new)}`."
|
130
|
+
FileUtils.mv(old, new)
|
131
|
+
else
|
132
|
+
opnn; e "No file exists at `#{sfile(old)}`, thus can not rename/replace."
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
# ========================================================================= #
|
137
|
+
# === password?
|
138
|
+
# ========================================================================= #
|
139
|
+
def password?
|
140
|
+
@password
|
141
|
+
end
|
142
|
+
|
143
|
+
# ========================================================================= #
|
144
|
+
# === tell_the_user_that_we_will_remove_the_password_next
|
145
|
+
# ========================================================================= #
|
146
|
+
def tell_the_user_that_we_will_remove_the_password_next(this_file = input?)
|
147
|
+
opnn; e 'Now removing the password ('+orange(password?.to_s)+') '\
|
148
|
+
'from the file `'+sfile(this_file)+'`.'
|
149
|
+
end
|
150
|
+
|
151
|
+
# ========================================================================= #
|
152
|
+
# === check_commandline (menu tag)
|
153
|
+
#
|
154
|
+
# Pass the commandline arguments through this method.
|
155
|
+
# ========================================================================= #
|
156
|
+
def check_commandline(i)
|
157
|
+
if i.is_a? Array
|
158
|
+
i.each {|entry|
|
159
|
+
check_commandline(entry)
|
160
|
+
}
|
161
|
+
else
|
162
|
+
case i.to_s # case tag
|
163
|
+
# ===================================================================== #
|
164
|
+
# === remove_password --batch
|
165
|
+
# ===================================================================== #
|
166
|
+
when /-?-?batch/
|
167
|
+
@input = Dir['*.pdf']
|
168
|
+
# ===================================================================== #
|
169
|
+
# === remove_password --password?
|
170
|
+
# ===================================================================== #
|
171
|
+
when '--password?',
|
172
|
+
'password?',
|
173
|
+
'password'
|
174
|
+
e password?
|
175
|
+
exit
|
176
|
+
# ===================================================================== #
|
177
|
+
# === remove_password --help
|
178
|
+
# ===================================================================== #
|
179
|
+
when 'HELP',
|
180
|
+
'--help',
|
181
|
+
'help'
|
182
|
+
show_help
|
183
|
+
exit
|
184
|
+
else
|
185
|
+
if i.include? '--'
|
186
|
+
if i.include?('--password ') or i.include?('--password')
|
187
|
+
i =~ REGEX_FOR_PASSWORD # See here for the test: http://rubular.com/r/P6LScCOVYZ
|
188
|
+
set_password($2.to_s.dup) # The second capture group holds our result.
|
189
|
+
i.gsub!(REGEX_FOR_PASSWORD, '')
|
190
|
+
end
|
191
|
+
end unless i.is_a? Symbol
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
# ========================================================================= #
|
197
|
+
# === show_help (help tag)
|
198
|
+
#
|
199
|
+
# Show some instructions in how to use this class.
|
200
|
+
#
|
201
|
+
# Invocation example:
|
202
|
+
#
|
203
|
+
# nopassword --help
|
204
|
+
#
|
205
|
+
# ========================================================================= #
|
206
|
+
def show_help
|
207
|
+
e
|
208
|
+
e 'You can set a different password via:'
|
209
|
+
e
|
210
|
+
e sfancy(' --password NEW_PASSWORD_HERE')
|
211
|
+
e
|
212
|
+
e 'nopdf *.pdf --password '+password?
|
213
|
+
e
|
214
|
+
e 'If you want to batch-process all .pdf files in the '\
|
215
|
+
'current directory,'
|
216
|
+
e 'and subsequently remove all password-protection '\
|
217
|
+
'from these files, do:'
|
218
|
+
e
|
219
|
+
e sfancy(' --batch')
|
220
|
+
e
|
221
|
+
end
|
222
|
+
|
223
|
+
# ========================================================================= #
|
224
|
+
# === remove_password_through_qpdf
|
225
|
+
#
|
226
|
+
# Here we make use of qpdf.
|
227
|
+
# ========================================================================= #
|
228
|
+
def remove_password_through_qpdf(
|
229
|
+
work_on_this_file = input?
|
230
|
+
)
|
231
|
+
if qpdf_exists?
|
232
|
+
set_output_file(work_on_this_file)
|
233
|
+
@string = 'qpdf --password='+password?+' --decrypt '+
|
234
|
+
work_on_this_file+' '+output_file?
|
235
|
+
else
|
236
|
+
e 'qpdf does not exist. Please install it. Exiting now.'
|
237
|
+
exit
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
# ========================================================================= #
|
242
|
+
# === set_output_file
|
243
|
+
# ========================================================================= #
|
244
|
+
def set_output_file(i)
|
245
|
+
i = file_name_without_extension?(i)
|
246
|
+
i = "no_password_#{i}.pdf"
|
247
|
+
@output_file = i
|
248
|
+
end
|
249
|
+
|
250
|
+
# ========================================================================= #
|
251
|
+
# === file_name_without_extension?
|
252
|
+
# ========================================================================= #
|
253
|
+
def file_name_without_extension?(i = input?)
|
254
|
+
i.strip.sub(/\.pdf$/,'') # Chop off trailing extension name.
|
255
|
+
end
|
256
|
+
|
257
|
+
# ========================================================================= #
|
258
|
+
# === output_file?
|
259
|
+
# ========================================================================= #
|
260
|
+
def output_file?
|
261
|
+
@output_file
|
262
|
+
end; alias output? output_file? # === output?
|
263
|
+
|
264
|
+
# ========================================================================= #
|
265
|
+
# === opnn
|
266
|
+
# ========================================================================= #
|
267
|
+
def opnn
|
268
|
+
super(NAMESPACE)
|
269
|
+
end
|
270
|
+
|
271
|
+
# ========================================================================= #
|
272
|
+
# === qpdf_exists?
|
273
|
+
#
|
274
|
+
# Query method to try to find out whether qpdf is installed.
|
275
|
+
# ========================================================================= #
|
276
|
+
def qpdf_exists?
|
277
|
+
result = `qpdf 2>&1`
|
278
|
+
! result.include?(COMMAND_NOT_FOUND)
|
279
|
+
end
|
280
|
+
|
281
|
+
# ========================================================================= #
|
282
|
+
# === remove_password_through_pdftk
|
283
|
+
# ========================================================================= #
|
284
|
+
def remove_password_through_pdftk(this_file)
|
285
|
+
# ======================================================================= #
|
286
|
+
# Decrypt a PDF called input.pdf with YOURPASSWORD-HERE password
|
287
|
+
# and create unencrypted output.pdf, enter:
|
288
|
+
# ======================================================================= #
|
289
|
+
@string = 'pdftk '+this_file+' output no_password_output.pdf user_pw '+password?
|
290
|
+
end
|
291
|
+
|
292
|
+
# ========================================================================= #
|
293
|
+
# === consider_replacing_the_old_file
|
294
|
+
# ========================================================================= #
|
295
|
+
def consider_replacing_the_old_file(
|
296
|
+
old_file = input?,
|
297
|
+
output_file = @output_file
|
298
|
+
)
|
299
|
+
if @automatically_replace
|
300
|
+
opnn; e 'The constant '+swarn('AUTOMATICALLY_REPLACE')+' is set to true.'
|
301
|
+
opnn; e 'This means that we will automatically try to replace '\
|
302
|
+
'the old .pdf with the new .pdf'
|
303
|
+
mv(output_file, old_file)
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
# ========================================================================= #
|
308
|
+
# === set_input
|
309
|
+
#
|
310
|
+
# Since as of Jul 2016, the input given to this class must always
|
311
|
+
# be ketp as an Array.
|
312
|
+
# ========================================================================= #
|
313
|
+
def set_input(
|
314
|
+
i = '', do_check_the_commandline = true
|
315
|
+
)
|
316
|
+
case do_check_the_commandline
|
317
|
+
when :do_not_check_the_commandline
|
318
|
+
do_check_the_commandline = false
|
319
|
+
end
|
320
|
+
# ======================================================================= #
|
321
|
+
# Next we will have special symbol-instructions here, in
|
322
|
+
# particular :all_pdf_files
|
323
|
+
# ======================================================================= #
|
324
|
+
if i.is_a? Symbol
|
325
|
+
case i
|
326
|
+
when :all_pdf_files
|
327
|
+
i = Dir['*.pdf']
|
328
|
+
end
|
329
|
+
end
|
330
|
+
if i.is_a? Array
|
331
|
+
i.flatten!
|
332
|
+
else
|
333
|
+
i = [i]
|
334
|
+
end
|
335
|
+
@input = i # This is guaranteed to be an Array.
|
336
|
+
check_commandline(i) if do_check_the_commandline
|
337
|
+
end
|
338
|
+
|
339
|
+
# ========================================================================= #
|
340
|
+
# === run (run tag)
|
341
|
+
# ========================================================================= #
|
342
|
+
def run
|
343
|
+
check_for_a_password_file_in_the_current_directory
|
344
|
+
# ======================================================================= #
|
345
|
+
# Iterate over the given input-files.
|
346
|
+
# ======================================================================= #
|
347
|
+
input?.each {|file|
|
348
|
+
remove_password_through_qpdf(file)
|
349
|
+
# remove_password_through_pdftk(file) # Pick this, or the other one.
|
350
|
+
tell_the_user_that_we_will_remove_the_password_next(file)
|
351
|
+
run_sys_command
|
352
|
+
consider_replacing_the_old_file(file)
|
353
|
+
}
|
354
|
+
end
|
355
|
+
|
356
|
+
# ========================================================================= #
|
357
|
+
# === check_for_a_password_file_in_the_current_directory (password tag)
|
358
|
+
#
|
359
|
+
# We can check for several password files.
|
360
|
+
# ========================================================================= #
|
361
|
+
def check_for_a_password_file_in_the_current_directory
|
362
|
+
_ = ARRAY_ALLOWED_PASSWORD_FILES
|
363
|
+
does_any_file_exist = _.select {|entry|
|
364
|
+
File.exist?(entry)
|
365
|
+
}
|
366
|
+
does_a_password_file_exist = !does_any_file_exist.empty?
|
367
|
+
if does_a_password_file_exist
|
368
|
+
this_selection = does_any_file_exist.first
|
369
|
+
opnn; e 'A file called `'+sfile(this_selection)+'` was found in the current directory.'
|
370
|
+
if File.zero? this_selection # Check whether it is empty.
|
371
|
+
opnn; e 'As it is, however had, empty, we will not change the '\
|
372
|
+
"password to the file's content."
|
373
|
+
else
|
374
|
+
# =================================================================== #
|
375
|
+
# Read in the new password from the existing file.
|
376
|
+
# =================================================================== #
|
377
|
+
use_this_dataset = File.readlines(this_selection).map(&:chomp)
|
378
|
+
set_password(
|
379
|
+
use_this_dataset.first # <- We will only honour the first line of this file.
|
380
|
+
)
|
381
|
+
opnn; e 'We will use the content of this file as the new password '\
|
382
|
+
'(Password thus being: '+orange(password?)+').'
|
383
|
+
end
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
end; end
|
388
|
+
|
389
|
+
if __FILE__ == $PROGRAM_NAME
|
390
|
+
PdfParadise::RemovePdfPassword.new(ARGV)
|
391
|
+
end # no_password
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
module PdfParadise
|
6
|
+
|
7
|
+
require 'pdf_paradise/project/project.rb'
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === PdfParadise.batch_require_toplevel_files
|
11
|
+
#
|
12
|
+
# Batch require all .rb files that are part of the project.
|
13
|
+
# ========================================================================= #
|
14
|
+
def self.batch_require_toplevel_files
|
15
|
+
files = Dir["#{PdfParadise.project_base_dir?}*.rb"]
|
16
|
+
files.reject! {|entry| entry.include? 'merge_pdf_namespace' }
|
17
|
+
files.each {|file|
|
18
|
+
require "pdf_paradise/#{File.basename(file)}"
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
end; PdfParadise.batch_require_toplevel_files # And call it at once.
|
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'pdf_paradise/requires/colours_and_esystem_and_save_file_and_fileutils_and_opn.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'pdf_paradise/requires/esystem_and_opn_and_colours.rb'
|
8
|
+
require 'fileutils'
|
9
|
+
begin
|
10
|
+
require 'save_file'
|
11
|
+
rescue LoadError; end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'pdf_paradise/requires/esystem_and_colours.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
begin
|
8
|
+
require 'esystem'
|
9
|
+
rescue LoadError; end
|
10
|
+
require 'pdf_paradise/requires/colours.rb'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'pdf_paradise/requires/esystem_and_opn_and_colours.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'pdf_paradise/requires/esystem_and_colours.rb'
|
8
|
+
require 'opn'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'pdf_paradise/requires/require_the_whole_project.rb
|
6
|
+
# =========================================================================== #
|
7
|
+
# The second require statement will pull in all relevant .rb files
|
8
|
+
# from the project toplevel area.
|
9
|
+
# =========================================================================== #
|
10
|
+
require 'pdf_paradise/version/version.rb'
|
11
|
+
require 'pdf_paradise/requires/batch_require_toplevel_files.rb'
|
12
|
+
require 'pdf_paradise/merge_pdf/merge_pdf.rb' # Extra-call for class MergePdf
|
13
|
+
require 'pdf_paradise/main_pdf/main_pdf.rb'
|
14
|
+
# =========================================================================== #
|
15
|
+
# Add pdf_paradise/toplevel_methods/ files next:
|
16
|
+
# =========================================================================== #
|
17
|
+
require 'pdf_paradise/toplevel_methods/reduce_size_of_this_pdf_file.rb'
|
18
|
+
require 'pdf_paradise/toplevel_methods/opened_pdf_files.rb'
|
19
|
+
require 'pdf_paradise/toplevel_methods/misc.rb'
|
20
|
+
# =========================================================================== #
|
21
|
+
# And the commandline-part as well:
|
22
|
+
# =========================================================================== #
|
23
|
+
require 'pdf_paradise/commandline/menu.rb'
|
24
|
+
require 'pdf_paradise/prawn_addons/prawn_addons.rb'
|
25
|
+
|
26
|
+
require 'pdf_paradise/compress/compress_via_hexapdf.rb'
|
27
|
+
|
28
|
+
require 'pdf_paradise/requires/require_utility_scripts.rb'
|
@@ -0,0 +1,9 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'pdf_paradise/requires/require_utility_scripts.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'pdf_paradise/toplevel_methods/misc.rb'
|
8
|
+
|
9
|
+
PdfParadise.do_require_the_utility_scripts
|
@@ -0,0 +1,156 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === PdfParadise::SetMainBook
|
6
|
+
#
|
7
|
+
# This class can set the new main-book for use on my computer system.
|
8
|
+
# It will be assumed that the book is kept in a .pdf file format.
|
9
|
+
#
|
10
|
+
# It is not very useful to other people though.
|
11
|
+
#
|
12
|
+
# Usage example:
|
13
|
+
#
|
14
|
+
# PdfParadise::SetMainBook.new(ARGV)
|
15
|
+
#
|
16
|
+
# =========================================================================== #
|
17
|
+
# require 'pdf_paradise/set_main_book.rb'
|
18
|
+
# PdfParadise::SetMainBook.new(ARGV)
|
19
|
+
# =========================================================================== #
|
20
|
+
require 'pdf_paradise/base/base.rb'
|
21
|
+
|
22
|
+
module PdfParadise
|
23
|
+
|
24
|
+
class SetMainBook < ::PdfParadise::Base # === PdfParadise::SetMainBook
|
25
|
+
|
26
|
+
# ========================================================================= #
|
27
|
+
# === NAMESPACE
|
28
|
+
# ========================================================================= #
|
29
|
+
NAMESPACE = inspect
|
30
|
+
|
31
|
+
# ========================================================================= #
|
32
|
+
# === FILE_ROEBERIA_SETTINGS
|
33
|
+
# ========================================================================= #
|
34
|
+
FILE_ROEBERIA_SETTINGS =
|
35
|
+
'/home/x/data/personal/yaml/roeberia_settings.yml'
|
36
|
+
|
37
|
+
# ========================================================================= #
|
38
|
+
# === initialize
|
39
|
+
# ========================================================================= #
|
40
|
+
def initialize(
|
41
|
+
commandline_arguments = nil,
|
42
|
+
run_already = true
|
43
|
+
)
|
44
|
+
reset
|
45
|
+
set_commandline_arguments(
|
46
|
+
commandline_arguments
|
47
|
+
)
|
48
|
+
run if run_already
|
49
|
+
end
|
50
|
+
|
51
|
+
# ========================================================================= #
|
52
|
+
# === reset (reset tag)
|
53
|
+
# ========================================================================= #
|
54
|
+
def reset
|
55
|
+
super()
|
56
|
+
# ======================================================================= #
|
57
|
+
# === @namespace
|
58
|
+
# ======================================================================= #
|
59
|
+
@namespace = NAMESPACE
|
60
|
+
end
|
61
|
+
|
62
|
+
# ========================================================================= #
|
63
|
+
# === set_commandline_arguments
|
64
|
+
# ========================================================================= #
|
65
|
+
def set_commandline_arguments(i = '')
|
66
|
+
i = [i].flatten.compact
|
67
|
+
@commandline_arguments = i
|
68
|
+
consider_sanitizing_the_first_argument
|
69
|
+
end
|
70
|
+
|
71
|
+
# ========================================================================= #
|
72
|
+
# === consider_sanitizing_the_first_argument
|
73
|
+
#
|
74
|
+
# This method currently only makes sure that the argument given to
|
75
|
+
# this class will have the proper full path.
|
76
|
+
# ========================================================================= #
|
77
|
+
def consider_sanitizing_the_first_argument
|
78
|
+
if @commandline_arguments.first
|
79
|
+
unless @commandline_arguments.first.include? '/'
|
80
|
+
@commandline_arguments[0] = return_pwd+File.basename(@commandline_arguments[0])
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# ========================================================================= #
|
86
|
+
# === modify_this_file
|
87
|
+
#
|
88
|
+
# This method will modify the file at hand, which is typically a
|
89
|
+
# .yml file (aka "roeberia_settings.yml").
|
90
|
+
#
|
91
|
+
# Call this method after you have made sure that the file at hand
|
92
|
+
# DOES exist.
|
93
|
+
# ========================================================================= #
|
94
|
+
def modify_this_file(
|
95
|
+
this_file = FILE_ROEBERIA_SETTINGS
|
96
|
+
)
|
97
|
+
seek_this_word = 'MAIN_BOOK'
|
98
|
+
require 'find_line_in_file'
|
99
|
+
result = FindLineInFile[
|
100
|
+
search_term: seek_this_word,
|
101
|
+
where: this_file
|
102
|
+
]
|
103
|
+
n_padding = 23 # This is hard-coded for now.
|
104
|
+
dataset = File.readlines(this_file)
|
105
|
+
line = dataset[result - 1]
|
106
|
+
if line.include? seek_this_word
|
107
|
+
padding = ' ' * (n_padding - ('MAIN_BOOK:'.size))
|
108
|
+
line = "MAIN_BOOK:"\
|
109
|
+
"#{padding}"\
|
110
|
+
"#{first_argument?}"
|
111
|
+
target = '/home/Temp/'+File.basename(this_file)
|
112
|
+
e "Backing up the old file next, onto `#{sfile(target)}`."
|
113
|
+
FileUtils.copy(this_file, target)
|
114
|
+
# ===================================================================== #
|
115
|
+
# Now we can store this dataset.
|
116
|
+
# ===================================================================== #
|
117
|
+
dataset[result - 1] = line
|
118
|
+
unless dataset.last == "\n"
|
119
|
+
dataset << "\n" # I like a trailing newline.
|
120
|
+
end
|
121
|
+
write_what_into(dataset, this_file)
|
122
|
+
else
|
123
|
+
e "The line does not include our search "\
|
124
|
+
"term #{sfancy(seek_this_word)}."
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# ========================================================================= #
|
129
|
+
# === run (run tag)
|
130
|
+
# ========================================================================= #
|
131
|
+
def run
|
132
|
+
first_argument = first_argument?
|
133
|
+
if first_argument and File.file?(first_argument)
|
134
|
+
opnn; e rev+
|
135
|
+
'Next assigning the file '+sfile(first_argument)
|
136
|
+
opnn; e 'to be the new main .pdf file.'
|
137
|
+
if File.exist? FILE_ROEBERIA_SETTINGS
|
138
|
+
modify_this_file(FILE_ROEBERIA_SETTINGS)
|
139
|
+
else
|
140
|
+
e 'No file exists at '+sfile(FILE_ROEBERIA_SETTINGS)+'.'
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# ========================================================================= #
|
146
|
+
# === PdfParadise::SetMainBook[]
|
147
|
+
# ========================================================================= #
|
148
|
+
def self.[](i = '')
|
149
|
+
new(i)
|
150
|
+
end
|
151
|
+
|
152
|
+
end; end
|
153
|
+
|
154
|
+
if __FILE__ == $PROGRAM_NAME
|
155
|
+
PdfParadise::SetMainBook.new(ARGV)
|
156
|
+
end # setmainbook /home/x/books/JAVA/DONE_Learn_Java_the_Easy_Way_2017.pdf
|