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,474 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === PdfParadise::MainPdf
6
+ #
7
+ # Use this file to open one or several .pdf files.
8
+ #
9
+ # The convention is that you can pass both commandlines and also
10
+ # filenames on the commandlines.
11
+ #
12
+ # Usage example:
13
+ #
14
+ # PdfParadise::MainPdf.new
15
+ #
16
+ # =========================================================================== #
17
+ # require 'pdf_paradise/main_pdf/main_pdf.rb'
18
+ # =========================================================================== #
19
+ require 'pdf_paradise/base/base.rb'
20
+
21
+ module PdfParadise
22
+
23
+ class MainPdf < Base # === PdfParadise::MainPdf
24
+
25
+ begin
26
+ require 'directory_paradise'
27
+ rescue LoadError; end
28
+
29
+ # ========================================================================= #
30
+ # === MAIN_PDF_YAML_FILE
31
+ # ========================================================================= #
32
+ MAIN_PDF_YAML_FILE = ::PdfParadise.file_main_pdf_yaml_file?
33
+
34
+ # ========================================================================= #
35
+ # === HOME_DIR
36
+ # ========================================================================= #
37
+ HOME_DIR = ENV['HOME'].to_s+'/'
38
+
39
+ # ========================================================================= #
40
+ # === LAST_DOWNLOADED_FILE
41
+ # ========================================================================= #
42
+ LAST_DOWNLOADED_FILE =
43
+ "#{HOME_DIR}LAST_DOWNLOADED_FILE.md"
44
+
45
+ # ========================================================================= #
46
+ # === LAST_PDF_FILE_OPENED
47
+ # ========================================================================= #
48
+ LAST_PDF_FILE_OPENED =
49
+ "#{HOME_DIR}LAST_PDF_FILE_OPENED.md"
50
+
51
+ # ========================================================================= #
52
+ # === initialize
53
+ #
54
+ # The first argument can be an Array or a String, of pdf-files that
55
+ # we attempt to open.
56
+ # ========================================================================= #
57
+ def initialize(
58
+ these_pdf_files = nil,
59
+ run_already = true,
60
+ &block
61
+ )
62
+ reset
63
+ check_commandline_options(
64
+ these_pdf_files
65
+ )
66
+ case run_already
67
+ when :do_not_run_yet
68
+ run_already = false
69
+ end
70
+ if block_given?
71
+ yielded = yield
72
+ if yielded.is_a? Hash
73
+ # =================================================================== #
74
+ # === :open_via_fullscreen
75
+ # =================================================================== #
76
+ if yielded.has_key? :open_via_fullscreen
77
+ @open_via_fullscreen = yielded[:open_via_fullscreen]
78
+ end
79
+ end
80
+ end
81
+ run if run_already
82
+ end
83
+
84
+ # ========================================================================= #
85
+ # === reset (reset tag)
86
+ # ========================================================================= #
87
+ def reset
88
+ super()
89
+ # ======================================================================= #
90
+ # === @pdf_viewer
91
+ # ======================================================================= #
92
+ if File.exist? MAIN_PDF_YAML_FILE
93
+ @pdf_viewer = YAML.load_file(MAIN_PDF_YAML_FILE)
94
+ else
95
+ ewarn "The file at `#{MAIN_PDF_YAML_FILE}` was not found."
96
+ end
97
+ @pdf_viewer = @pdf_viewer.first if @pdf_viewer.is_a? Array # Use only the first entry for now if we read in an Array.
98
+ # ======================================================================= #
99
+ # === @open_these_pdf_files
100
+ # ======================================================================= #
101
+ @open_these_pdf_files = []
102
+ # ======================================================================= #
103
+ # === @commandline_options
104
+ # ======================================================================= #
105
+ @commandline_options = [] # This array may contain our commandline options.
106
+ # ======================================================================= #
107
+ # === @open_via_fullscreen
108
+ # ======================================================================= #
109
+ @open_via_fullscreen = false
110
+ end
111
+
112
+ # ========================================================================= #
113
+ # === save_new_pdf_handler
114
+ #
115
+ # The first (and only) argument to this method is which new pdf handler
116
+ # we will use. Afterwards we will exit.
117
+ #
118
+ # To invoke this method, do:
119
+ #
120
+ # mpdf SAVE xournal
121
+ # mpdf SAVE okular
122
+ #
123
+ # ========================================================================= #
124
+ def save_new_pdf_handler(
125
+ i = @commandline_options[1]
126
+ )
127
+ i = i.to_s
128
+ e 'Saving `'+sfancy(i)+'` into `'+sfile(MAIN_PDF_YAML_FILE)+'`.'
129
+ write_what_where(i, MAIN_PDF_YAML_FILE)
130
+ exit
131
+ end
132
+
133
+ # ========================================================================= #
134
+ # === show_yaml_file
135
+ # ========================================================================= #
136
+ def show_yaml_file
137
+ e "The main yaml file is at `#{sfile(main_yaml_file?)}`."
138
+ end
139
+
140
+ # ========================================================================= #
141
+ # === MAIN_PDF_YAML_FILE
142
+ # ========================================================================= #
143
+ def main_yaml_file?
144
+ MAIN_PDF_YAML_FILE
145
+ end
146
+
147
+ # ========================================================================= #
148
+ # === feedback_pdf_handler_in_use
149
+ # ========================================================================= #
150
+ def feedback_pdf_handler_in_use
151
+ e 'You currently use this as .pdf handler: '+
152
+ sfancy(@pdf_viewer)
153
+ end
154
+
155
+ # ========================================================================= #
156
+ # === check_whether_we_have_found_any_pdf_file
157
+ #
158
+ # This method checks whether we have found any .pdf file or not. If not,
159
+ # we try to check whether the current directory has any .pdf file at all.
160
+ # ========================================================================= #
161
+ def check_whether_we_have_found_any_pdf_file
162
+ if @open_these_pdf_files.empty?
163
+ any_pdf_file = get_all_pdf_files
164
+ if ! any_pdf_file.empty?
165
+ _ = any_pdf_file.first
166
+ e 'It seems as if no .pdf file was supplied.'
167
+ e 'We did however find at least one .pdf file. We will now '
168
+ e 'use this .pdf file at '+sfile(_)+'.'
169
+ add _
170
+ end
171
+ end
172
+ end
173
+
174
+ # ========================================================================= #
175
+ # === edit_this_file_here
176
+ # ========================================================================= #
177
+ def edit_this_file_here
178
+ _ = 'bluefish '+__FILE__
179
+ esystem _
180
+ end
181
+
182
+ # ========================================================================= #
183
+ # === do_log_this_pdf_file_was_opened_last
184
+ # ========================================================================= #
185
+ def do_log_this_pdf_file_was_opened_last(
186
+ i = @full_file_location
187
+ )
188
+ save_what_into(i, LAST_PDF_FILE_OPENED)
189
+ end
190
+
191
+ # ========================================================================= #
192
+ # === set_full_file_location
193
+ # ========================================================================= #
194
+ def set_full_file_location(i)
195
+ unless i.include? '/'
196
+ i = Dir.pwd+'/'+i
197
+ end
198
+ @full_file_location = i
199
+ end
200
+
201
+ # ========================================================================= #
202
+ # === MainPdf[]
203
+ # ========================================================================= #
204
+ def self.[](
205
+ i, optional_commandline_arguments = nil
206
+ )
207
+ _ = new(i, :do_not_run_yet)
208
+ if optional_commandline_arguments
209
+ _.commandline_arguments = optional_commandline_arguments
210
+ end
211
+ _.run
212
+ end
213
+
214
+ # ========================================================================= #
215
+ # === check_commandline_options
216
+ #
217
+ # The convention is simply - if it is a valid file, we
218
+ # add it to the list of pdf files to open.
219
+ # ========================================================================= #
220
+ def check_commandline_options(i)
221
+ if i.is_a? Array
222
+ i.each {|entry| check_commandline_options(entry) }
223
+ else # We either add it to the list of pdf files to open, or to the commandline options
224
+ if File.exist? i
225
+ # =================================================================== #
226
+ # Open the .pdf file here, if it exists.
227
+ # =================================================================== #
228
+ add_to_open_these_pdf_files(i)
229
+ else
230
+ @commandline_options << i
231
+ end
232
+ end
233
+ end; alias commandline_arguments= check_commandline_options # === commandline_arguments=
234
+
235
+ # ========================================================================= #
236
+ # === process_commandline_options
237
+ #
238
+ # Use this method to process the commandline options given.
239
+ # ========================================================================= #
240
+ def process_commandline_options
241
+ _ = @commandline_options.first
242
+ case _ # case tag
243
+ # ======================================================================= #
244
+ # === mpdf --use-atril
245
+ # ======================================================================= #
246
+ when /^-?-?use(-|_)?atril$/i,
247
+ /^-?-?atril$/i
248
+ save_new_pdf_handler :atril
249
+ # ======================================================================= #
250
+ # === mpdf --use-evince
251
+ # ======================================================================= #
252
+ when /^-?-?use(-|_)?evince$/i,
253
+ /^-?-?EVINCE$/i
254
+ save_new_pdf_handler :evince
255
+ # ======================================================================= #
256
+ # === --open-main-pdf
257
+ # ======================================================================= #
258
+ when /^-?-?open(-|_)?main(-|_)?pdf$/i
259
+ add_to_open_these_pdf_files(:the_main_pdf)
260
+ # ======================================================================= #
261
+ # === mpdf --open-last
262
+ # ======================================================================= #
263
+ when /^-?-?open(-|_)?last$/i,
264
+ 'OPENLATEST',
265
+ 'LATEST',
266
+ 'LAST','last'
267
+ open_last_found_pdf
268
+ # ======================================================================= #
269
+ # === mpdf --query?
270
+ # ======================================================================= #
271
+ when /-?-?query\??/,
272
+ 'QUERY','QUERY?','?','PDF?',/-?-?current\??/
273
+ feedback_pdf_handler_in_use
274
+ exit
275
+ # ======================================================================= #
276
+ # === mpdf --file?
277
+ # ======================================================================= #
278
+ when /-?-?file\??/
279
+ show_yaml_file
280
+ exit
281
+ # ======================================================================= #
282
+ # === mpdf SAVE okular
283
+ # ======================================================================= #
284
+ when 'SAVE',
285
+ 'SET',
286
+ 'save','set','--save','--set'
287
+ save_new_pdf_handler
288
+ # ======================================================================= #
289
+ # === mpdf --help
290
+ # ======================================================================= #
291
+ when /-?-?help/,'HELP'
292
+ feedback_available_commandline_options
293
+ # ======================================================================= #
294
+ # === mpdf --restore
295
+ # ======================================================================= #
296
+ when /-?-?restore/,'RESTORE'
297
+ add( File.readlines(LAST_PDF_FILE_OPENED)[0].to_s.strip )
298
+ # ======================================================================= #
299
+ # === mpdf --edit
300
+ # ======================================================================= #
301
+ when 'EDIT','OPEN','OPEN_SELF','OPENSELF',/edit/
302
+ edit_this_file_here; exit
303
+ # ======================================================================= #
304
+ # === mpdf --okular
305
+ # ======================================================================= #
306
+ when 'USE_OKULAR','OKULAR',/^-?-?okular/
307
+ save_new_pdf_handler :okular
308
+ # ======================================================================= #
309
+ # === mpdf --fullscreen
310
+ # ======================================================================= #
311
+ when /^-?-?fullscreen$/i
312
+ @pdf_viewer << ' --fullscreen'
313
+ # ======================================================================= #
314
+ # === mpdf LAST_DOWNLOAD
315
+ # ======================================================================= #
316
+ when 'LAST_DOWNLOAD','LASTDOWNLOAD'
317
+ last_downloaded_file = LAST_DOWNLOADED_FILE
318
+ if File.exist? last_downloaded_file
319
+ add(File.readlines(last_downloaded_file).first)
320
+ end
321
+ else # else step
322
+ unless File.exist? _
323
+ opn; e 'Unsure what to do with input `'+simp(_)+'`.'
324
+ end if _
325
+ end
326
+ end
327
+
328
+ # ========================================================================= #
329
+ # === feedback_available_commandline_options (help tag)
330
+ #
331
+ # Show the available help options next.
332
+ # ========================================================================= #
333
+ def feedback_available_commandline_options(
334
+ shall_we_exit = true
335
+ )
336
+ cliner {
337
+ ecomment ' RESTORE - open the last opened .pdf file in general'
338
+ ecomment ' OPEN_LAST - open the "youngest" .pdf file in the current working directory'
339
+ ecomment ' EDIT - open this file here'
340
+ ecomment ' QUERY - query which is our current default pdf reader'
341
+ ecomment ' --current? - alias to the above'
342
+ ecomment ' --file? - show the location of the .yml file'
343
+ ecomment ' SAVE / SET - save a new mpdf handler to use (i.e. '\
344
+ '"okular", via "mpdf SAVE okular")'
345
+ ecomment ' LAST_DOWNLOAD - open the last downloaded file stored in '+
346
+ LAST_DOWNLOADED_FILE
347
+ }
348
+ exit if shall_we_exit
349
+ end
350
+
351
+ # ========================================================================= #
352
+ # === get_all_pdf_files
353
+ # ========================================================================= #
354
+ def get_all_pdf_files
355
+ _ = DirectoryParadise::Report.new('', :do_not_run_yetfalse)
356
+ _.menu(:latest)
357
+ _.gather_content
358
+ only_pdf_files = _.content.select {|entry|
359
+ entry.include? '.pdf'
360
+ }
361
+ return only_pdf_files
362
+ end
363
+
364
+ # ========================================================================= #
365
+ # === open_last_found_pdf
366
+ #
367
+ # This will open the last .pdf file in the current directory. Which
368
+ # one is that? We will act on the file information here.
369
+ # ========================================================================= #
370
+ def open_last_found_pdf
371
+ add :latest_pdf
372
+ end
373
+
374
+ # ========================================================================= #
375
+ # === add_to_open_these_pdf_files (add tag)
376
+ # ========================================================================= #
377
+ def add_to_open_these_pdf_files(i)
378
+ case i
379
+ # ======================================================================= #
380
+ # === :main_pdf
381
+ # ======================================================================= #
382
+ when :main_pdf,
383
+ :the_main_pdf
384
+ i = ENV['MAIN_BOOK'].to_s
385
+ # ======================================================================= #
386
+ # === :latest_pdf
387
+ # ======================================================================= #
388
+ when :latest_pdf
389
+ i = get_all_pdf_files.sort.first.to_s # Get the latest .pdf file. [0] Should be the properly sorted one.
390
+ end
391
+ @open_these_pdf_files << i
392
+ end; alias add add_to_open_these_pdf_files # === add
393
+
394
+ # ========================================================================= #
395
+ # === open_all_pdf_files
396
+ # ========================================================================= #
397
+ def open_all_pdf_files(
398
+ i = @open_these_pdf_files
399
+ )
400
+ i.each {|entry|
401
+ consider_opening_this_pdf_file(entry)
402
+ }
403
+ end
404
+
405
+ # ========================================================================= #
406
+ # === run_sys_command
407
+ # ========================================================================= #
408
+ def run_sys_command
409
+ process_commandline_options
410
+ check_whether_we_have_found_any_pdf_file
411
+ open_all_pdf_files
412
+ end
413
+
414
+ # ========================================================================= #
415
+ # === consider_opening_this_pdf_file
416
+ #
417
+ # This method will do the actual opening-part, by using system().
418
+ # ========================================================================= #
419
+ def consider_opening_this_pdf_file(
420
+ i = @open_these_pdf_files,
421
+ open_via_fullscreen = @open_via_fullscreen
422
+ )
423
+ if File.exist? i
424
+ set_full_file_location(i)
425
+ i = '"'+i+'"' if i.include? ' '
426
+ i = '"'+i+'"' if i.include? '('
427
+ i = '"'+i+'"' if i.include? "'"
428
+ extra_options = ' '.dup
429
+ if open_via_fullscreen
430
+ extra_options << '--fullscreen '
431
+ end
432
+ i = @pdf_viewer+extra_options+i+
433
+ ' &'
434
+ do_log_this_pdf_file_was_opened_last
435
+ esystem i
436
+ else # Ok, at this point the file does not exist. Try a regex first.
437
+ results = Dir['*'+i+'*']
438
+ if results.empty?
439
+ opn; e 'No valid .pdf file was found at `'+sfile(i)+'`.'
440
+ opn; e 'Thus we can not open anything.'
441
+ else
442
+ consider_opening_this_pdf_file(results.first)
443
+ end
444
+ end
445
+ end
446
+
447
+ # ========================================================================= #
448
+ # === run (run tag)
449
+ # ========================================================================= #
450
+ def run
451
+ run_sys_command
452
+ end
453
+
454
+ end
455
+
456
+ # =========================================================================== #
457
+ # === PdfParadise.main_pdf
458
+ # =========================================================================== #
459
+ def self.main_pdf(i = ARGV, &block)
460
+ ::PdfParadise::MainPdf.new(i, &block)
461
+ end
462
+
463
+ # =========================================================================== #
464
+ # === PdfParadise.use_which_pdf_viewer?
465
+ # =========================================================================== #
466
+ def self.use_which_pdf_viewer?
467
+ return YAML.load_file(MAIN_PDF_YAML_FILE)
468
+ end
469
+
470
+ end
471
+
472
+ if __FILE__ == $PROGRAM_NAME
473
+ PdfParadise.main_pdf(ARGV)
474
+ end # mpdf AUPC_Einheit_I_Einfuehrung_2013.pdf AUPC_Einheit_II_2013.pdf
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'pdf_paradise/merge_pdf/menu.rb'
6
+ # =========================================================================== #
7
+ require 'pdf_paradise/base/base.rb'
8
+
9
+ module PdfParadise
10
+
11
+ class MergePdf < Base # === PdfParadise::MergePdf
12
+
13
+ # ========================================================================= #
14
+ # === menu (menu tag)
15
+ #
16
+ # This is check_against_menu(). We respond to some given input.
17
+ # ========================================================================= #
18
+ def menu(
19
+ i = commandline_arguments?
20
+ )
21
+ if i.is_a? Array
22
+ i.each {|entry| menu(entry) }
23
+ else
24
+ case i # (case tag)
25
+ # ===================================================================== #
26
+ # === --use-hexapdf
27
+ # ===================================================================== #
28
+ when /^-?-?use(-|_| )?hexapdf$/i,
29
+ /^-?-?hexapdf$/i
30
+ @use_this_program_for_merging_the_pdf_files = :hexapdf
31
+ # ===================================================================== #
32
+ # === --use-ghostscript
33
+ # ===================================================================== #
34
+ when /^-?-?use(-|_| )?ghostscript$/i,
35
+ /^-?-?ghostscript$/i
36
+ @use_this_program_for_merging_the_pdf_files = :ghostscript
37
+ # ===================================================================== #
38
+ # === --remove
39
+ # ===================================================================== #
40
+ when '1',
41
+ /^-?-?last$/i,
42
+ /^-?-?kill$/i,
43
+ /^-?-?remove$/i
44
+ remove_merged_files
45
+ exit
46
+ # ===================================================================== #
47
+ # === --openself
48
+ # ===================================================================== #
49
+ when '2',
50
+ /^-?-?openself$/i
51
+ open_this_file_here
52
+ exit
53
+ # ===================================================================== #
54
+ # === mergepdf --help
55
+ # ===================================================================== #
56
+ when /help/
57
+ show_help
58
+ exit
59
+ end
60
+ end
61
+ end; alias check_against_menu menu # === check_against_menu
62
+
63
+ end; end