pdf_paradise 0.3.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +933 -0
  3. data/bin/automatic_pdf_title +7 -0
  4. data/bin/burst_this_pdf_file +7 -0
  5. data/bin/combine_these_pdf_pages +7 -0
  6. data/bin/compress_via_hexapdf +7 -0
  7. data/bin/convert_markdown_to_pdf +7 -0
  8. data/bin/convert_pdf_to_text +7 -0
  9. data/bin/delete_first_page_of_this_pdf_file +7 -0
  10. data/bin/djvu_to_pdf +7 -0
  11. data/bin/merge_then_open +7 -0
  12. data/bin/n_pages +10 -0
  13. data/bin/open_main_pdf +7 -0
  14. data/bin/pdf_paradise +9 -0
  15. data/bin/rotate_pdf +7 -0
  16. data/bin/set_main_book +7 -0
  17. data/bin/set_title_of_this_pdf_file +15 -0
  18. data/doc/README.gen +871 -0
  19. data/doc/todo/todo.md +13 -0
  20. data/images/Logo_for_the_pdf_paradise_project.avif +0 -0
  21. data/lib/pdf_paradise/base/base.rb +344 -0
  22. data/lib/pdf_paradise/base/colours.rb +67 -0
  23. data/lib/pdf_paradise/colours/colours.rb +27 -0
  24. data/lib/pdf_paradise/commandline/commandline.rb +109 -0
  25. data/lib/pdf_paradise/commandline/help.rb +77 -0
  26. data/lib/pdf_paradise/commandline/menu.rb +173 -0
  27. data/lib/pdf_paradise/compress/compress_this_pdf_file.rb +108 -0
  28. data/lib/pdf_paradise/compress/compress_via_hexapdf.rb +27 -0
  29. data/lib/pdf_paradise/compress/compress_via_qpdf.rb +32 -0
  30. data/lib/pdf_paradise/constants/constants.rb +76 -0
  31. data/lib/pdf_paradise/convert_text_to_pdf.rb +94 -0
  32. data/lib/pdf_paradise/css/project.css +17 -0
  33. data/lib/pdf_paradise/fpdf/README.md +2 -0
  34. data/lib/pdf_paradise/fpdf/bookmark.rb +129 -0
  35. data/lib/pdf_paradise/fpdf/chinese.rb +454 -0
  36. data/lib/pdf_paradise/fpdf/fpdf.rb +1902 -0
  37. data/lib/pdf_paradise/fpdf/fpdf_eps.rb +138 -0
  38. data/lib/pdf_paradise/fpdf/makefont.rb +1794 -0
  39. data/lib/pdf_paradise/gui/README.md +6 -0
  40. data/lib/pdf_paradise/gui/fox/split_pdf_file.rb +77 -0
  41. data/lib/pdf_paradise/gui/gtk2/pdf_viewer/pdf_viewer.rb +34 -0
  42. data/lib/pdf_paradise/gui/gtk2/split_pdf_file/split_pdf_file.rb +34 -0
  43. data/lib/pdf_paradise/gui/gtk2/statistics_widget/statistics_widget.rb +34 -0
  44. data/lib/pdf_paradise/gui/gtk3/controller/controller.rb +214 -0
  45. data/lib/pdf_paradise/gui/gtk3/pdf_viewer/pdf_viewer.rb +34 -0
  46. data/lib/pdf_paradise/gui/gtk3/split_pdf_file/split_pdf_file.rb +34 -0
  47. data/lib/pdf_paradise/gui/jruby/delete_the_first_or_the_last_page_of_this_pdf_file/delete_the_first_or_the_last_page_of_this_pdf_file.rb +167 -0
  48. data/lib/pdf_paradise/gui/jruby/remove_the_first_page_of_this_pdf_file/remove_the_first_page_of_this_pdf_file.rb +103 -0
  49. data/lib/pdf_paradise/gui/libui/extract_all_images_from_this_pdf_file/extract_all_images_from_this_pdf_file.rb +223 -0
  50. data/lib/pdf_paradise/gui/libui/remove_the_first_page_of_this_pdf_file/remove_the_first_page_of_this_pdf_file.rb +267 -0
  51. data/lib/pdf_paradise/gui/libui/rotate_pdf_file/rotate_pdf_file.rb +219 -0
  52. data/lib/pdf_paradise/gui/libui/statistics_widget/statistics_widget.rb +233 -0
  53. data/lib/pdf_paradise/gui/shared_code/pdf_viewer/pdf_viewer.css +5 -0
  54. data/lib/pdf_paradise/gui/shared_code/pdf_viewer/pdf_viewer_module.rb +287 -0
  55. data/lib/pdf_paradise/gui/shared_code/remove_the_first_page_of_this_pdf_file_module/remove_the_first_page_of_this_pdf_file_module.rb +31 -0
  56. data/lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb +295 -0
  57. data/lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb +366 -0
  58. data/lib/pdf_paradise/gui/universal_widgets/delete_the_first_or_the_last_page_of_this_pdf_file/delete_the_first_or_the_last_page_of_this_pdf_file.rb +776 -0
  59. data/lib/pdf_paradise/gui/universal_widgets/statistics_widget/statistics_widget.rb +407 -0
  60. data/lib/pdf_paradise/gui/universal_widgets/to_pdf/to_pdf.rb +351 -0
  61. data/lib/pdf_paradise/hexapdf/001_rainbow_pattern_example.rb +0 -0
  62. data/lib/pdf_paradise/hexapdf/hexapdf.rb +123 -0
  63. data/lib/pdf_paradise/images/PDF_PARADISE_LOGO.png +0 -0
  64. data/lib/pdf_paradise/main_pdf/main_pdf.rb +474 -0
  65. data/lib/pdf_paradise/merge_pdf/menu.rb +63 -0
  66. data/lib/pdf_paradise/merge_pdf/merge_pdf.rb +307 -0
  67. data/lib/pdf_paradise/merge_pdf_namespace.rb +9 -0
  68. data/lib/pdf_paradise/merge_then_open/merge_then_open.rb +105 -0
  69. data/lib/pdf_paradise/prawn_addons/README.md +2 -0
  70. data/lib/pdf_paradise/prawn_addons/prawn_addons.rb +17 -0
  71. data/lib/pdf_paradise/project/project.rb +22 -0
  72. data/lib/pdf_paradise/remove_pdf_password.rb +391 -0
  73. data/lib/pdf_paradise/requires/batch_require_toplevel_files.rb +22 -0
  74. data/lib/pdf_paradise/requires/colours.rb +11 -0
  75. data/lib/pdf_paradise/requires/colours_and_esystem_and_save_file_and_fileutils_and_opn.rb +13 -0
  76. data/lib/pdf_paradise/requires/esystem_and_colours.rb +11 -0
  77. data/lib/pdf_paradise/requires/esystem_and_opn_and_colours.rb +10 -0
  78. data/lib/pdf_paradise/requires/require_the_whole_project.rb +30 -0
  79. data/lib/pdf_paradise/requires/require_utility_scripts.rb +9 -0
  80. data/lib/pdf_paradise/set_main_book.rb +156 -0
  81. data/lib/pdf_paradise/set_pdf_title.rb +220 -0
  82. data/lib/pdf_paradise/sinatra/embeddable_interface.rb +389 -0
  83. data/lib/pdf_paradise/toplevel_methods/convert_epub_to_pdf.rb +27 -0
  84. data/lib/pdf_paradise/toplevel_methods/convert_markdown_to_pdf.rb +45 -0
  85. data/lib/pdf_paradise/toplevel_methods/convert_ppt_to_pdf.rb +35 -0
  86. data/lib/pdf_paradise/toplevel_methods/e.rb +16 -0
  87. data/lib/pdf_paradise/toplevel_methods/esystem.rb +20 -0
  88. data/lib/pdf_paradise/toplevel_methods/misc.rb +228 -0
  89. data/lib/pdf_paradise/toplevel_methods/number_pages.rb +38 -0
  90. data/lib/pdf_paradise/toplevel_methods/opened_pdf_files.rb +221 -0
  91. data/lib/pdf_paradise/toplevel_methods/query_pdf_title.rb +201 -0
  92. data/lib/pdf_paradise/toplevel_methods/reduce_size_of_this_pdf_file.rb +46 -0
  93. data/lib/pdf_paradise/toplevel_methods/roebe.rb +17 -0
  94. data/lib/pdf_paradise/toplevel_methods/to_pdf.rb +12 -0
  95. data/lib/pdf_paradise/utility_scripts/README.md +3 -0
  96. data/lib/pdf_paradise/utility_scripts/automatic_pdf_title.rb +104 -0
  97. data/lib/pdf_paradise/utility_scripts/check_syntax_of_pdf_files.rb +106 -0
  98. data/lib/pdf_paradise/utility_scripts/combine_these_pdf_pages.rb +118 -0
  99. data/lib/pdf_paradise/utility_scripts/convert_pdf_to_text.rb +179 -0
  100. data/lib/pdf_paradise/utility_scripts/delete_last_page_of_this_pdf_file.rb +180 -0
  101. data/lib/pdf_paradise/utility_scripts/delete_the_first_page_of_this_pdf_file/delete_the_first_page_of_this_pdf_file.rb +429 -0
  102. data/lib/pdf_paradise/utility_scripts/delete_this_page_of_this_pdf_file.rb +356 -0
  103. data/lib/pdf_paradise/utility_scripts/djvu_to_pdf.rb +87 -0
  104. data/lib/pdf_paradise/utility_scripts/extract_all_images_from_this_pdf_file.rb +129 -0
  105. data/lib/pdf_paradise/utility_scripts/extract_pdf_page.rb +283 -0
  106. data/lib/pdf_paradise/utility_scripts/pdf_file_n_total_pages.rb +348 -0
  107. data/lib/pdf_paradise/utility_scripts/pdf_optimizer.rb +111 -0
  108. data/lib/pdf_paradise/utility_scripts/pdf_statistics.rb +148 -0
  109. data/lib/pdf_paradise/utility_scripts/pdf_to_html.rb +75 -0
  110. data/lib/pdf_paradise/utility_scripts/remove_images.rb +110 -0
  111. data/lib/pdf_paradise/utility_scripts/rotate_pdf_file.rb +303 -0
  112. data/lib/pdf_paradise/utility_scripts/split_pdf.rb +364 -0
  113. data/lib/pdf_paradise/utility_scripts/to_pdf.rb +130 -0
  114. data/lib/pdf_paradise/utility_scripts/to_qdf.rb +66 -0
  115. data/lib/pdf_paradise/version/version.rb +19 -0
  116. data/lib/pdf_paradise/www/README.md +2 -0
  117. data/lib/pdf_paradise/www/sinatra/app.rb +304 -0
  118. data/lib/pdf_paradise/yaml/working_on_these_pdf_files.yml +4 -0
  119. data/lib/pdf_paradise.rb +5 -0
  120. data/pdf_paradise.gemspec +61 -0
  121. data/test/fpdf/001_minimal_example.rb +12 -0
  122. data/test/fpdf/002.pdf +0 -0
  123. data/test/fpdf/002_header_and_footer_example.rb +64 -0
  124. data/test/fpdf/003.pdf +98 -0
  125. data/test/fpdf/003_justified_paragraphs.rb +96 -0
  126. data/test/fpdf/file1.md +3 -0
  127. data/test/fpdf/file2.md +3 -0
  128. data/test/fpdf/test.pdf +0 -0
  129. data/test/testing_pdf_paradise.rb +12 -0
  130. metadata +239 -0
@@ -0,0 +1,429 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === PdfParadise::DeleteTheFirstPageOfThisPdfFile
6
+ #
7
+ # This class can be used to delete the first page of a .pdf file.
8
+ #
9
+ # The user can pass one (or several) .pdf files to this class, and this
10
+ # class will then proceed to try to remove the very first .pdf page,
11
+ # in that given .pdf file. So, for instance, if the pdf-file at hand
12
+ # has 100 pages, the new .pdf file should have 99 pages, and the first
13
+ # page will be gone. That is the primary rationale this class follows.
14
+ #
15
+ # By default, the class will overwrite the original file; this behaviour
16
+ # depends on the constant SHALL_WE_OVERWRITE_THE_ORIGINAL_PDF_FILE and
17
+ # the user can toggle this to false, to NOT overwrite the original file.
18
+ #
19
+ # Note that the functionality made available through this class here
20
+ # depends on external tools, such as the binary called "qpdf" or the
21
+ # binary called "pdftk" or "hexapdf".
22
+ #
23
+ # Since as of July 2023 the class will also log its action, by storing
24
+ # the path to the last .pdf file that was modified.
25
+ #
26
+ # Usage example:
27
+ #
28
+ # PdfParadise::DeleteTheFirstPageOfThisPdfFile.new(ARGV)
29
+ #
30
+ # =========================================================================== #
31
+ # require 'pdf_paradise/utility_scripts/delete_the_first_page_of_this_pdf_file/delete_the_first_page_of_this_pdf_file.rb'
32
+ # PdfParadise.delete_the_first_page_of_this_pdf_file('foobar.pdf')
33
+ # PdfParadise::DeleteTheFirstPageOfThisPdfFile.new(ARGV)
34
+ # =========================================================================== #
35
+ require 'pdf_paradise/base/base.rb'
36
+
37
+ module PdfParadise
38
+
39
+ class DeleteTheFirstPageOfThisPdfFile < Base # === PdfParadise::DeleteTheFirstPageOfThisPdfFile
40
+
41
+ require 'pdf_paradise/utility_scripts/pdf_file_n_total_pages.rb'
42
+
43
+ # ========================================================================= #
44
+ # === SHALL_WE_OVERWRITE_THE_ORIGINAL_PDF_FILE
45
+ #
46
+ # Set this constant to false if you do not want to overwrite the
47
+ # original .pdf file.
48
+ # ========================================================================= #
49
+ SHALL_WE_OVERWRITE_THE_ORIGINAL_PDF_FILE = true
50
+
51
+ # ========================================================================= #
52
+ # === initialize
53
+ # ========================================================================= #
54
+ def initialize(
55
+ commandline_arguments = nil,
56
+ run_already = true,
57
+ &block
58
+ )
59
+ reset
60
+ case commandline_arguments
61
+ # ======================================================================= #
62
+ # === :do_not_run_yet
63
+ # ======================================================================= #
64
+ when :do_not_run_yet
65
+ commandline_arguments = []
66
+ run_already = false
67
+ end
68
+ set_commandline_arguments(
69
+ commandline_arguments
70
+ )
71
+ # ======================================================================= #
72
+ # === Handle blocks next
73
+ # ======================================================================= #
74
+ if block_given?
75
+ yielded = yield
76
+ case yielded
77
+ # ===================================================================== #
78
+ # === :be_quiet
79
+ # ===================================================================== #
80
+ when :be_quiet
81
+ set_be_quiet
82
+ end
83
+ end
84
+ run if run_already
85
+ end
86
+
87
+ # ========================================================================= #
88
+ # === reset (reset tag)
89
+ # ========================================================================= #
90
+ def reset
91
+ super()
92
+ infer_the_namespace
93
+ reset_the_internal_hash
94
+ # ======================================================================= #
95
+ # === :work_on_these_files
96
+ # ======================================================================= #
97
+ @internal_hash[:work_on_these_files] = []
98
+ # ======================================================================= #
99
+ # === :array_backup_files
100
+ #
101
+ # We also keep track of backup fiels next.
102
+ # ======================================================================= #
103
+ @internal_hash[:array_backup_files] = []
104
+ # ======================================================================= #
105
+ # === :use_this_pdf_application
106
+ #
107
+ # The following variable may have any of the following values:
108
+ #
109
+ # :hexapdf
110
+ # :pdftk
111
+ # :qpdf
112
+ #
113
+ # It specifies which application can be used for deleting .pdf pages.
114
+ # ======================================================================= #
115
+ @internal_hash[:use_this_pdf_application] = :hexapdf # :qpdf # :hexapdf # :pdftk
116
+ # ======================================================================= #
117
+ # === :original_pwd
118
+ #
119
+ # Keep track of the original working directory.
120
+ # ======================================================================= #
121
+ @internal_hash[:original_pwd] = return_pwd
122
+ # ======================================================================= #
123
+ # === :shall_we_overwrite_the_original_pdf_file
124
+ # ======================================================================= #
125
+ @internal_hash[:shall_we_overwrite_the_original_pdf_file] =
126
+ SHALL_WE_OVERWRITE_THE_ORIGINAL_PDF_FILE
127
+ end
128
+
129
+ # ========================================================================= #
130
+ # === use_this_pdf_application?
131
+ # ========================================================================= #
132
+ def use_this_pdf_application?
133
+ @internal_hash[:use_this_pdf_application]
134
+ end
135
+
136
+ # ========================================================================= #
137
+ # === use_pdftk?
138
+ # ========================================================================= #
139
+ def use_pdftk?
140
+ use_this_pdf_application? == :pdftk
141
+ end
142
+
143
+ # ========================================================================= #
144
+ # === array_backup_files?
145
+ # ========================================================================= #
146
+ def array_backup_files?
147
+ @internal_hash[:array_backup_files]
148
+ end; alias backups? array_backup_files? # === backups?
149
+
150
+ # ========================================================================= #
151
+ # === run (run tag)
152
+ # ========================================================================= #
153
+ def run
154
+ determine_the_input_files
155
+ _ = work_on_these_files?
156
+ if _.empty?
157
+ opne 'No .pdf file was assigned to this class.'
158
+ else
159
+ do_work_on_these_pdf_files(_)
160
+ end
161
+ end
162
+
163
+ # ========================================================================= #
164
+ # === determine_the_input_files
165
+ #
166
+ # This method will specifically select for all .pdf files.
167
+ # ========================================================================= #
168
+ def determine_the_input_files(
169
+ commandline_arguments = commandline_arguments?
170
+ )
171
+ # ======================================================================= #
172
+ # Next, if i is empty, and we are on Roebe, we will use the default
173
+ # book, if a certain ENV variable exists AND if the file that points
174
+ # to that location also exists.
175
+ # ======================================================================= #
176
+ if commandline_arguments.empty? and is_on_roebe?
177
+ if ENV.has_key?('MAIN_BOOK') and
178
+ File.exist?(ENV['MAIN_BOOK'])
179
+ this_file = ENV['MAIN_BOOK'].dup
180
+ e "#{rev}As we are on roebe, we will use this file:"
181
+ e
182
+ e sfile(" #{this_file}")
183
+ e
184
+ commandline_arguments << this_file
185
+ end
186
+ end
187
+ commandline_arguments.map! {|entry|
188
+ entry = entry.to_s unless entry.is_a?(String)
189
+ entry = Dir[entry] if entry.include? '*'
190
+ entry
191
+ }
192
+ commandline_arguments.flatten!
193
+ _ = commandline_arguments.select {|entry|
194
+ entry.end_with?('.pdf') and File.file?(entry)
195
+ }
196
+ _.map! {|entry| File.absolute_path(entry) } if _ and !_.empty?
197
+ @internal_hash[:work_on_these_files] = _
198
+ end
199
+
200
+ # ========================================================================= #
201
+ # === create_a_backup_file
202
+ # ========================================================================= #
203
+ def create_a_backup_file(
204
+ entry,
205
+ temp_dir = temp_dir?
206
+ )
207
+ e "#{rev}First, #{steelblue('a backup file will be created')}#{rev}."
208
+ # ======================================================================= #
209
+ # Next ensure that the temp-dir exists.
210
+ # ======================================================================= #
211
+ try_to_ensure_that_this_directory_exists(temp_dir)
212
+ target = temp_dir+File.basename(entry)
213
+ if File.exist? target # Delete the old .pdf copy here.
214
+ delete_file(target)
215
+ end
216
+ copy_file(entry, target)
217
+ if File.exist? target
218
+ e "#{rev}A backup-file (a copy) now exists at `#{sfile(target)}#{rev}`."
219
+ @internal_hash[:array_backup_files] << File.absolute_path(target)
220
+ end
221
+ end
222
+
223
+ # ========================================================================= #
224
+ # === work_on_these_files?
225
+ # ========================================================================= #
226
+ def work_on_these_files?
227
+ @internal_hash[:work_on_these_files]
228
+ end; alias input? work_on_these_files? # === input?
229
+ alias input_files? work_on_these_files? # === input_files?
230
+
231
+ # ========================================================================= #
232
+ # === do_work_on_these_pdf_files (main tag)
233
+ #
234
+ # This is the method that will delete the first page of a given .pdf
235
+ # file.
236
+ # ========================================================================= #
237
+ def do_work_on_these_pdf_files(
238
+ i = work_on_these_files?,
239
+ temp_dir = temp_dir?
240
+ )
241
+ i.each {|entry|
242
+ opnn { :no_trailing }
243
+ e; e
244
+ e "#{rev}Working on the file #{sfile(entry)} #{rev}next."
245
+ create_a_backup_file(entry)
246
+ backup_copy = backups?.last # Refer to the last entry there.
247
+ n_pages = PdfParadise.n_pages?(backup_copy)
248
+ e "#{rev}Now that a backup file has been created, it is time to "\
249
+ "work on that backup"
250
+ e "#{rev}copy. The .pdf currently has #{steelblue(n_pages)} #{rev}pages."
251
+ # ===================================================================== #
252
+ # Always cd into the target directory next - we have to remember
253
+ # the original working directory, though, so that we cd back
254
+ # into it:
255
+ # ===================================================================== #
256
+ if temp_dir and File.directory?(temp_dir)
257
+ @internal_hash[:original_pwd] = temp_dir
258
+ cd(temp_dir)
259
+ end
260
+ new_path = do_delete_the_first_page_of_this_pdf_file(backup_copy)
261
+ n_pages = PdfParadise.n_pages?(new_path)
262
+ e "#{rev}The .pdf file now has #{steelblue(n_pages)} #{rev}pages."
263
+ e 'It can be found at '+sfile(new_path)+'.' if File.exist?(new_path)
264
+ # ===================================================================== #
265
+ # === Keeping track of changes via a log-file
266
+ #
267
+ # Sine as of July 2023 we will also log into a .yml file. We will
268
+ # store the original .pdf file, though, as the modified .pdf
269
+ # file tends to be volatile.
270
+ # ===================================================================== #
271
+ if File.exist?(entry)
272
+ store_this_pdf_file_in_the_log_file(entry) # See the explanation above.
273
+ end
274
+ if @internal_hash[:shall_we_overwrite_the_original_pdf_file] and
275
+ File.exist?(new_path)
276
+ e "#{rev}The variable #{gold(':shall_we_overwrite_the_original_pdf_file')}"\
277
+ " #{rev}was set to"
278
+ e "#{rev}true, so the file at"
279
+ e "#{sfile(entry)}#{rev} will be overwritten now."
280
+ # =================================================================== #
281
+ # In this case we will overwrite the original .pdf file. The
282
+ # following call to mv() does this.
283
+ # =================================================================== #
284
+ delete_file(entry) if File.exist?(new_path)
285
+ mv(
286
+ new_path,
287
+ entry
288
+ )
289
+ end
290
+ }
291
+ cd(@internal_hash[:original_pwd]) # And go back to the initial working directory again.
292
+ end; alias process_each_pdf do_work_on_these_pdf_files # === process_each_pdf
293
+
294
+ # ========================================================================= #
295
+ # === shall_we_overwrite_the_original_pdf_file?
296
+ # ========================================================================= #
297
+ def shall_we_overwrite_the_original_pdf_file?
298
+ @internal_hash[:shall_we_overwrite_the_original_pdf_file]
299
+ end
300
+
301
+ # ========================================================================= #
302
+ # === store_this_pdf_file_in_the_log_file
303
+ # ========================================================================= #
304
+ def store_this_pdf_file_in_the_log_file(i)
305
+ PdfParadise.set_use_this_file(i)
306
+ what = YAML.dump(i)
307
+ # ======================================================================= #
308
+ # Find out the full, absolute path to the .yml file next:
309
+ # ======================================================================= #
310
+ into = File.absolute_path("#{log_directory?}last_modified_pdf_file.yml")
311
+ e "#{rev}Logging information into the file `#{sfile(into)}#{rev}`."
312
+ write_what_into(what, into)
313
+ end
314
+
315
+ # ========================================================================= #
316
+ # === use_hexapdf?
317
+ # ========================================================================= #
318
+ def use_hexapdf?
319
+ use_this_pdf_application? == :hexapdf
320
+ end
321
+
322
+ # ========================================================================= #
323
+ # === name_of_the_output_file?
324
+ #
325
+ # This method will determine the output file of the .pdf file.
326
+ # ========================================================================= #
327
+ def name_of_the_output_file?(i)
328
+ i.delete_suffix('.pdf')+'_output_file.pdf'
329
+ end; alias output? name_of_the_output_file? # === output?
330
+
331
+ # ========================================================================= #
332
+ # === do_delete_the_first_page_of_this_pdf_file
333
+ # ========================================================================= #
334
+ def do_delete_the_first_page_of_this_pdf_file(
335
+ i,
336
+ use_this_pdf_application = @internal_hash[:use_this_pdf_application],
337
+ be_verbose = be_verbose?
338
+ )
339
+ use_this_pdf_application = use_this_pdf_application.to_s
340
+ # ======================================================================= #
341
+ # Determine the name of the (new) output file next:
342
+ # ======================================================================= #
343
+ name_of_the_output_file = name_of_the_output_file?(i)
344
+ if File.exist?(name_of_the_output_file) # Delete the output file first.
345
+ delete_file(name_of_the_output_file)
346
+ end
347
+ if i.include? ' '
348
+ i = '"'+i+'"'
349
+ end
350
+ # ======================================================================= #
351
+ # Store how many pages this .pdf file has.
352
+ # ======================================================================= #
353
+ has_n_pages = PdfParadise.n_pages_in_this_pdf_file?(i)
354
+ _ = ''.dup
355
+ _ << use_this_pdf_application
356
+ case _
357
+ # ======================================================================= #
358
+ # === Support for pdftk
359
+ # ======================================================================= #
360
+ when /pdftk/
361
+ _ << ' '+i+' cat 2-'+(has_n_pages.to_i).to_s+' '+
362
+ has_n_pages.to_s+'-end output '+
363
+ name_of_the_output_file
364
+ # ======================================================================= #
365
+ # === Support for hexapdf
366
+ # ======================================================================= #
367
+ when /hexapdf/
368
+ _ << ' modify '+i+' -i 2-e '+name_of_the_output_file
369
+ # ======================================================================= #
370
+ # === Support for qpdf
371
+ # ======================================================================= #
372
+ when /qpdf/
373
+ _ << ' '+'--pages '+i+' 2-'+(has_n_pages.to_i).to_s+' -- '+
374
+ i+' '+
375
+ name_of_the_output_file
376
+ else
377
+ e 'Unknown pdf handler: '+steelblue(_)
378
+ e 'Exiting.'
379
+ exit
380
+ end
381
+ e "Deleting the first page of this .pdf file next: "\
382
+ "#{sfile(i)}" if be_verbose
383
+ # ======================================================================= #
384
+ # Next, do the actual work as-such, via esystem() and a bit of padding:
385
+ # ======================================================================= #
386
+ e; e " #{_}"; system(_); e
387
+ return name_of_the_output_file
388
+ end
389
+
390
+ # ========================================================================= #
391
+ # === PdfParadise::DeleteTheFirstPageOfThisPdfFile[]
392
+ # ========================================================================= #
393
+ def self.[](i = ARGV)
394
+ new(i)
395
+ end
396
+
397
+ end
398
+
399
+ # =========================================================================== #
400
+ # === PdfParadise.use_which_pdf_application_for_deleting_the_first_page_of_a_pdf_file?
401
+ #
402
+ # Usage example:
403
+ #
404
+ # PdfParadise.use_which_pdf_application_for_deleting_the_first_page_of_a_pdf_file? # => :hexapdf
405
+ #
406
+ # =========================================================================== #
407
+ def self.use_which_pdf_application_for_deleting_the_first_page_of_a_pdf_file?
408
+ _ = PdfParadise::DeleteTheFirstPageOfThisPdfFile.new(:do_not_run_yet)
409
+ return _.use_this_pdf_application?
410
+ end
411
+
412
+ # =========================================================================== #
413
+ # === PdfParadise.delete_first_page_of_this_pdf_file
414
+ #
415
+ # Easier method-way to invoke the above class.
416
+ # =========================================================================== #
417
+ def self.delete_first_page_of_this_pdf_file(
418
+ i = ARGV, &block
419
+ )
420
+ PdfParadise::DeleteTheFirstPageOfThisPdfFile.new(i, &block)
421
+ end; self.instance_eval { alias remove_the_first_page_of_this_pdf_file delete_first_page_of_this_pdf_file } # === PdfParadise.remove_the_first_page_of_this_pdf_file
422
+ self.instance_eval { alias remove_first_page_of_this_pdf_file delete_first_page_of_this_pdf_file } # === PdfParadise.remove_first_page_of_this_pdf_file
423
+ self.instance_eval { alias delete_the_first_page_of_this_pdf_file delete_first_page_of_this_pdf_file } # === PdfParadise.delete_the_first_page_of_this_pdf_file
424
+
425
+ end
426
+
427
+ if __FILE__ == $PROGRAM_NAME
428
+ PdfParadise::DeleteTheFirstPageOfThisPdfFile.new(ARGV)
429
+ end # deletethefirstpageofthispdffile