pdf_paradise 0.1.43

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.

Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +376 -0
  3. data/bin/automatic_pdf_title +7 -0
  4. data/bin/convert_markdown_to_pdf +7 -0
  5. data/bin/convert_pdf_to_text +7 -0
  6. data/bin/merge_then_open +7 -0
  7. data/bin/n_pages +10 -0
  8. data/bin/open_main_pdf +7 -0
  9. data/bin/pdf_paradise +7 -0
  10. data/bin/set_main_book +7 -0
  11. data/bin/set_title_of_this_pdf_file +15 -0
  12. data/doc/README.gen +348 -0
  13. data/doc/todo/todo.md +2 -0
  14. data/lib/pdf_paradise.rb +5 -0
  15. data/lib/pdf_paradise/base/base.rb +173 -0
  16. data/lib/pdf_paradise/commandline/help.rb +69 -0
  17. data/lib/pdf_paradise/commandline/menu.rb +160 -0
  18. data/lib/pdf_paradise/compress_this_pdf_file.rb +82 -0
  19. data/lib/pdf_paradise/constants/constants.rb +59 -0
  20. data/lib/pdf_paradise/convert_text_to_pdf.rb +94 -0
  21. data/lib/pdf_paradise/css/project.css +17 -0
  22. data/lib/pdf_paradise/djvu_to_pdf.rb +85 -0
  23. data/lib/pdf_paradise/gui/README.md +6 -0
  24. data/lib/pdf_paradise/gui/fox/split_pdf_file.rb +77 -0
  25. 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
  26. data/lib/pdf_paradise/gui/gtk2/pdf_viewer/pdf_viewer.rb +34 -0
  27. data/lib/pdf_paradise/gui/gtk2/split_pdf_file/split_pdf_file.rb +34 -0
  28. data/lib/pdf_paradise/gui/gtk2/statistics_widget/statistics_widget.rb +34 -0
  29. data/lib/pdf_paradise/gui/gtk2/to_pdf/to_pdf.rb +32 -0
  30. data/lib/pdf_paradise/gui/gtk3/controller/controller.rb +197 -0
  31. data/lib/pdf_paradise/gui/gtk3/convert_pdf_to_text/convert_pdf_to_text.rb +34 -0
  32. 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
  33. data/lib/pdf_paradise/gui/gtk3/pdf_viewer/pdf_viewer.rb +34 -0
  34. data/lib/pdf_paradise/gui/gtk3/split_pdf_file/split_pdf_file.rb +34 -0
  35. data/lib/pdf_paradise/gui/gtk3/statistics_widget/statistics_widget.rb +34 -0
  36. data/lib/pdf_paradise/gui/gtk3/to_pdf/to_pdf.rb +32 -0
  37. data/lib/pdf_paradise/gui/shared_code/convert_pdf_to_text/convert_pdf_to_text_module.rb +277 -0
  38. 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 +428 -0
  39. data/lib/pdf_paradise/gui/shared_code/pdf_viewer/pdf_viewer.css +5 -0
  40. data/lib/pdf_paradise/gui/shared_code/pdf_viewer/pdf_viewer_module.rb +284 -0
  41. data/lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file.css +0 -0
  42. data/lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb +294 -0
  43. data/lib/pdf_paradise/gui/shared_code/statistics_widget/statistics_widget_module.rb +333 -0
  44. data/lib/pdf_paradise/gui/shared_code/to_pdf/to_pdf_module.rb +273 -0
  45. data/lib/pdf_paradise/main_pdf/main_pdf.rb +437 -0
  46. data/lib/pdf_paradise/merge_pdf/menu.rb +63 -0
  47. data/lib/pdf_paradise/merge_pdf/merge_pdf.rb +292 -0
  48. data/lib/pdf_paradise/merge_pdf_namespace.rb +9 -0
  49. data/lib/pdf_paradise/merge_then_open/merge_then_open.rb +105 -0
  50. data/lib/pdf_paradise/pdf_file_n_total_pages.rb +227 -0
  51. data/lib/pdf_paradise/project/project_base_directory.rb +22 -0
  52. data/lib/pdf_paradise/remove_pdf_password.rb +392 -0
  53. data/lib/pdf_paradise/requires/batch_require_toplevel_files.rb +22 -0
  54. data/lib/pdf_paradise/requires/colours.rb +7 -0
  55. data/lib/pdf_paradise/requires/colours_and_esystem_and_save_file_and_fileutils_and_opn.rb +11 -0
  56. data/lib/pdf_paradise/requires/esystem_and_colours.rb +10 -0
  57. data/lib/pdf_paradise/requires/esystem_and_opn_and_colours.rb +8 -0
  58. data/lib/pdf_paradise/requires/require_the_whole_project.rb +25 -0
  59. data/lib/pdf_paradise/requires/require_utility_scripts.rb +7 -0
  60. data/lib/pdf_paradise/rotate_pdf_file.rb +144 -0
  61. data/lib/pdf_paradise/set_main_book.rb +156 -0
  62. data/lib/pdf_paradise/set_pdf_title.rb +218 -0
  63. data/lib/pdf_paradise/sinatra/embeddable_interface.rb +315 -0
  64. data/lib/pdf_paradise/toplevel_methods/automatic_pdf_title.rb +55 -0
  65. data/lib/pdf_paradise/toplevel_methods/convert_epub_to_pdf.rb +27 -0
  66. data/lib/pdf_paradise/toplevel_methods/convert_markdown_to_pdf.rb +43 -0
  67. data/lib/pdf_paradise/toplevel_methods/convert_ppt_to_pdf.rb +35 -0
  68. data/lib/pdf_paradise/toplevel_methods/e.rb +16 -0
  69. data/lib/pdf_paradise/toplevel_methods/esystem.rb +19 -0
  70. data/lib/pdf_paradise/toplevel_methods/misc.rb +52 -0
  71. data/lib/pdf_paradise/toplevel_methods/number_pages.rb +38 -0
  72. data/lib/pdf_paradise/toplevel_methods/opened_pdf_files.rb +191 -0
  73. data/lib/pdf_paradise/toplevel_methods/query_pdf_title.rb +182 -0
  74. data/lib/pdf_paradise/toplevel_methods/reduce_size_of_this_pdf_file.rb +43 -0
  75. data/lib/pdf_paradise/toplevel_methods/roebe.rb +17 -0
  76. data/lib/pdf_paradise/toplevel_methods/to_pdf.rb +38 -0
  77. data/lib/pdf_paradise/utility_scripts/README.md +3 -0
  78. data/lib/pdf_paradise/utility_scripts/convert_pdf_to_text.rb +166 -0
  79. data/lib/pdf_paradise/utility_scripts/delete_first_page_of_this_pdf_file.rb +185 -0
  80. data/lib/pdf_paradise/utility_scripts/delete_last_page_of_this_pdf_file.rb +180 -0
  81. data/lib/pdf_paradise/utility_scripts/delete_this_page_of_this_pdf_file.rb +310 -0
  82. data/lib/pdf_paradise/utility_scripts/extract_pdf_page.rb +280 -0
  83. data/lib/pdf_paradise/utility_scripts/pdf_optimizer.rb +113 -0
  84. data/lib/pdf_paradise/utility_scripts/pdf_statistics.rb +150 -0
  85. data/lib/pdf_paradise/utility_scripts/remove_images.rb +110 -0
  86. data/lib/pdf_paradise/utility_scripts/split_pdf.rb +294 -0
  87. data/lib/pdf_paradise/utility_scripts/to_qdf.rb +82 -0
  88. data/lib/pdf_paradise/version/version.rb +19 -0
  89. data/lib/pdf_paradise/www/README.md +2 -0
  90. data/lib/pdf_paradise/www/sinatra/app.rb +276 -0
  91. data/pdf_paradise.gemspec +64 -0
  92. data/test/testing_pdf_paradise.rb +9 -0
  93. metadata +216 -0
@@ -0,0 +1,273 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === PdfParadise::GUI::Gtk::ToPdfModule
6
+ # =========================================================================== #
7
+ # require 'pdf_paradise/gui/shared_code/to_pdf/to_pdf_module.rb'
8
+ # include ::PdfParadise::GUI::Gtk::ToPdfModule
9
+ # =========================================================================== #
10
+ module PdfParadise
11
+
12
+ module GUI
13
+
14
+ module Gtk
15
+
16
+ module ToPdfModule
17
+
18
+ require 'gtk_paradise/requires/require_the_base_module.rb'
19
+ include ::Gtk::BaseModule
20
+
21
+ require 'pdf_paradise/toplevel_methods/to_pdf.rb'
22
+
23
+ begin
24
+ require 'pdf-reader' # Add an optional dependency here.
25
+ rescue LoadError; end
26
+
27
+ # ========================================================================= #
28
+ # === NAMESPACE
29
+ # ========================================================================= #
30
+ NAMESPACE = inspect
31
+
32
+ # ========================================================================= #
33
+ # === TITLE
34
+ # ========================================================================= #
35
+ TITLE = 'Convert to .pdf'
36
+
37
+ # ========================================================================= #
38
+ # === WIDTH
39
+ # ========================================================================= #
40
+ WIDTH = 1540
41
+
42
+ # ========================================================================= #
43
+ # === HEIGHT
44
+ # ========================================================================= #
45
+ HEIGHT = 400
46
+
47
+ # ========================================================================= #
48
+ # === USE_THIS_FONT
49
+ #
50
+ # Set a default font here.
51
+ # ========================================================================= #
52
+ USE_THIS_FONT = 'Sans 20'
53
+
54
+ # ========================================================================= #
55
+ # === initialize
56
+ # ========================================================================= #
57
+ def initialize(
58
+ commandline_arguments = ARGV,
59
+ run_already = true
60
+ )
61
+ super(:vertical)
62
+ reset
63
+ run if run_already
64
+ end
65
+
66
+ # ========================================================================= #
67
+ # === reset
68
+ # ========================================================================= #
69
+ def reset
70
+ reset_the_internal_variables
71
+ # ======================================================================= #
72
+ # === @configuration
73
+ # ======================================================================= #
74
+ @configuration = [true, __dir__, NAMESPACE]
75
+ # ======================================================================= #
76
+ # === @title
77
+ # ======================================================================= #
78
+ @title = TITLE
79
+ # ======================================================================= #
80
+ # === @width
81
+ # ======================================================================= #
82
+ @width = WIDTH
83
+ # ======================================================================= #
84
+ # === @height
85
+ # ======================================================================= #
86
+ @height = HEIGHT
87
+ set_use_this_font(USE_THIS_FONT)
88
+ use_gtk_paradise_project_css_file
89
+ end
90
+
91
+ # ========================================================================= #
92
+ # === create_skeleton
93
+ # ========================================================================= #
94
+ def create_skeleton
95
+ create_buttons
96
+ create_the_statusbar
97
+ end
98
+
99
+ # ========================================================================= #
100
+ # === create_the_statusbar
101
+ # ========================================================================= #
102
+ def create_the_statusbar
103
+ @statusbar = gtk_statusbar_with_handle
104
+ @status_bar_context_id = @statusbar.get_context_id('to_pdf')
105
+ end
106
+
107
+ # ========================================================================= #
108
+ # === create_buttons (buttons tag, button tag)
109
+ # ========================================================================= #
110
+ def create_buttons
111
+ # ======================================================================= #
112
+ # === @button_do_convert
113
+ # ======================================================================= #
114
+ @button_do_convert = gtk_button('_Convert it to .pdf format')
115
+ @button_do_convert.disallow_resizing
116
+ @button_do_convert.css_class('clear_background')
117
+ @button_do_convert.steelblue
118
+ @button_do_convert.css_class('BG_lightblue')
119
+ @button_do_convert.hint = 'This will use libreoffice '\
120
+ 'to convert the file at hand into a <b>.pdf file</b>.'
121
+ @button_do_convert.on_clicked {
122
+ do_convert_the_given_file
123
+ }
124
+ # ======================================================================= #
125
+ # === @button_choose_file
126
+ #
127
+ # This is the "Open File" button.
128
+ # ======================================================================= #
129
+ @button_choose_file = gtk_file_chooser_button
130
+ @button_choose_file.on_clicked {
131
+ create_a_new_file_chooser_dialog
132
+ main_entry?.set_text(main_file?.to_s)
133
+ }
134
+ # ======================================================================= #
135
+ # === @button_open_the_converted_file
136
+ # ======================================================================= #
137
+ @button_open_the_converted_file = gtk_button('_Open')
138
+ @button_open_the_converted_file.hint = 'Click to open the '\
139
+ 'converted file via main .pdf reader.'
140
+ @button_open_the_converted_file.on_clicked {
141
+ do_open_the_converted_file_via_a_pdf_reader
142
+ }
143
+ end
144
+
145
+ # ========================================================================= #
146
+ # === run
147
+ # ========================================================================= #
148
+ def run
149
+ create_skeleton
150
+ chdir('/Depot/j/') if File.directory? '/Depot/j/'
151
+ vbox = gtk_vbox
152
+ vbox.minimal(
153
+ gtk_label('Input the filename that you wish to convert here:'), 1
154
+ )
155
+ @entry_filename = gtk_entry
156
+ @entry_filename.bblack1
157
+ @entry_filename.yellow_background
158
+ vbox.minimal(@entry_filename, 1)
159
+ minimal(vbox, 1)
160
+ pack_without_expand(@button_choose_file, 1)
161
+ pack_without_expand(@button_do_convert, 1)
162
+ hbox = gtk_hbox
163
+ hbox.maximal(@statusbar, 1)
164
+ hbox.minimal(@button_open_the_converted_file, 1)
165
+ add(hbox)
166
+ @text_buffer = gtk_text_buffer
167
+ @text_view = gtk_text_view(@text_buffer)
168
+ @scrolled_window = gtk_scrolled_window(@text_view) { :top_to_bottom }
169
+ @scrolled_window.bblack1
170
+ @scrolled_window.css_class('pad4px')
171
+ @scrolled_window.width_height(500, 400)
172
+ minimal(@scrolled_window)
173
+ do_style_all_buttons_in_a_uniform_manner
174
+ end
175
+
176
+ # ========================================================================= #
177
+ # === do_style_all_buttons_in_a_uniform_manner
178
+ # ========================================================================= #
179
+ def do_style_all_buttons_in_a_uniform_manner
180
+ return_all_buttons.each {|entry|
181
+ entry.bblack1
182
+ entry.css_class('pad2px')
183
+ }
184
+ end
185
+
186
+ # ========================================================================= #
187
+ # === entry_filename?
188
+ # ========================================================================= #
189
+ def entry_filename?
190
+ @entry_filename
191
+ end; alias main_entry? entry_filename? # === main_entry?
192
+
193
+ # ========================================================================= #
194
+ # === padding?
195
+ # ========================================================================= #
196
+ def padding?
197
+ 0
198
+ end
199
+
200
+ # ========================================================================= #
201
+ # === favicon?
202
+ # ========================================================================= #
203
+ def favicon?
204
+ :tabble
205
+ end
206
+
207
+ # ========================================================================= #
208
+ # === do_open_the_converted_file_via_a_pdf_reader
209
+ # ========================================================================= #
210
+ def do_open_the_converted_file_via_a_pdf_reader
211
+ stored_here = stored_where?
212
+ if File.exist? stored_here
213
+ system 'evince '+stored_here
214
+ else
215
+ e 'No file exists at '+sfile(stored_here)+'.'
216
+ end
217
+ end
218
+
219
+ # ========================================================================= #
220
+ # === stored_where?
221
+ # ========================================================================= #
222
+ def stored_where?(
223
+ i = @entry_filename.text?
224
+ )
225
+ _ = PdfParadise.to_pdf(i)
226
+ _ = _.dup
227
+ _ = _.join(' ').strip if _.is_a? Array
228
+ _.delete_suffix!(File.extname(i))
229
+ _ << '.pdf' unless _.end_with? '.pdf'
230
+ return _.to_s
231
+ end
232
+
233
+ # ========================================================================= #
234
+ # === do_convert_the_given_file
235
+ #
236
+ # This is the method that will convert the target file into the
237
+ # .pdf file, usually by using "soffice".
238
+ # ========================================================================= #
239
+ def do_convert_the_given_file
240
+ _ = stored_where?
241
+ @statusbar.display(
242
+ 'Stored the file at: '+_, :default, @status_bar_context_id
243
+ ) if File.exist? _
244
+ # ======================================================================= #
245
+ # Read in the .pdf file if it exists and if the PDF::Reader namespace
246
+ # exists.
247
+ # ======================================================================= #
248
+ if File.exist?(_) and
249
+ Object.const_defined?(:PDF) and PDF.const_defined?(:Reader)
250
+ reader = PDF::Reader.new(_)
251
+ page = reader.page(1)
252
+ use_this_text = page.text.to_s
253
+ @scrolled_window.set_text(use_this_text.to_s)
254
+ end
255
+ end
256
+
257
+ # ========================================================================= #
258
+ # === PdfParadise::GUI::Gtk::ToPdfModule.run
259
+ # ========================================================================= #
260
+ def self.run(i = ARGV)
261
+ require 'gtk_paradise/run'
262
+ r = ::Gtk.run
263
+ _ = PdfParadise::GUI::Gtk::ToPdf.new(r)
264
+ r << _
265
+ r.automatic
266
+ r.easy_exit_top_left_then_run
267
+ end
268
+
269
+ end; end; end; end
270
+
271
+ if __FILE__ == $PROGRAM_NAME
272
+ PdfParadise::GUI::Gtk::ToPdfModule.run
273
+ end
@@ -0,0 +1,437 @@
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 'yaml'
20
+ require 'cliner'
21
+ require 'pdf_paradise/base/base.rb'
22
+ require 'pdf_paradise/constants/constants.rb'
23
+
24
+ module PdfParadise
25
+
26
+ class MainPdf < Base # === PdfParadise::MainPdf
27
+
28
+ begin
29
+ require 'save_file'
30
+ rescue LoadError; end
31
+
32
+ begin
33
+ require 'directory_paradise'
34
+ rescue LoadError; end
35
+
36
+ # ========================================================================= #
37
+ # === MAIN_PDF_YAML_FILE
38
+ # ========================================================================= #
39
+ MAIN_PDF_YAML_FILE = ::PdfParadise.file_main_pdf_yaml_file?
40
+
41
+ # ========================================================================= #
42
+ # === HOME_DIR
43
+ # ========================================================================= #
44
+ HOME_DIR = ENV['HOME'].to_s+'/'
45
+
46
+ # ========================================================================= #
47
+ # === LAST_DOWNLOADED_FILE
48
+ # ========================================================================= #
49
+ LAST_DOWNLOADED_FILE =
50
+ "#{HOME_DIR}LAST_DOWNLOADED_FILE.md"
51
+
52
+ # ========================================================================= #
53
+ # === LAST_PDF_FILE_OPENED
54
+ # ========================================================================= #
55
+ LAST_PDF_FILE_OPENED =
56
+ "#{HOME_DIR}LAST_PDF_FILE_OPENED.md"
57
+
58
+ # ========================================================================= #
59
+ # === initialize
60
+ #
61
+ # The first argument can be an Array or a String, of pdf-files that
62
+ # we attempt to open.
63
+ # ========================================================================= #
64
+ def initialize(
65
+ these_pdf_files = nil,
66
+ run_already = true
67
+ )
68
+ reset
69
+ check_commandline_options(
70
+ these_pdf_files
71
+ )
72
+ case run_already
73
+ when :do_not_run_yet
74
+ run_already = false
75
+ end
76
+ run if run_already
77
+ end
78
+
79
+ # ========================================================================= #
80
+ # === reset (reset tag)
81
+ # ========================================================================= #
82
+ def reset
83
+ super()
84
+ # ======================================================================= #
85
+ # === @pdf_viewer
86
+ # ======================================================================= #
87
+ if File.exist? MAIN_PDF_YAML_FILE
88
+ @pdf_viewer = YAML.load_file(MAIN_PDF_YAML_FILE)
89
+ else
90
+ ewarn "The file at `#{MAIN_PDF_YAML_FILE}` was not found."
91
+ end
92
+ @pdf_viewer = @pdf_viewer.first if @pdf_viewer.is_a? Array # Use only the first entry for now if we read in an Array.
93
+ # ======================================================================= #
94
+ # === @open_these_pdf_files
95
+ # ======================================================================= #
96
+ @open_these_pdf_files = []
97
+ # ======================================================================= #
98
+ # === @commandline_options
99
+ # ======================================================================= #
100
+ @commandline_options = [] # This array may contain our commandline options.
101
+ end
102
+
103
+ # ========================================================================= #
104
+ # === save_new_pdf_handler
105
+ #
106
+ # The first (and only) argument to this method is which new pdf handler
107
+ # we will use. Afterwards we will exit.
108
+ #
109
+ # To invoke this method, do:
110
+ # mpdf SAVE xournal
111
+ # mpdf SAVE okular
112
+ # ========================================================================= #
113
+ def save_new_pdf_handler(i = @commandline_options[1])
114
+ i = i.to_s
115
+ e 'Saving `'+sfancy(i)+'` into `'+sfile(MAIN_PDF_YAML_FILE)+'`.'
116
+ ::SaveFile.save_what_where(i, MAIN_PDF_YAML_FILE)
117
+ exit
118
+ end
119
+
120
+ # ========================================================================= #
121
+ # === show_yaml_file
122
+ # ========================================================================= #
123
+ def show_yaml_file
124
+ e 'The main yaml file is at `'+sfile(main_yaml_file?)+'`.'
125
+ end
126
+
127
+ # ========================================================================= #
128
+ # === MAIN_PDF_YAML_FILE
129
+ # ========================================================================= #
130
+ def main_yaml_file?
131
+ MAIN_PDF_YAML_FILE
132
+ end
133
+
134
+ # ========================================================================= #
135
+ # === feedback_pdf_handler_in_use
136
+ # ========================================================================= #
137
+ def feedback_pdf_handler_in_use
138
+ e 'You currently use this as .pdf handler: '+
139
+ sfancy(@pdf_viewer)
140
+ end
141
+
142
+ # ========================================================================= #
143
+ # === ecomment
144
+ # ========================================================================= #
145
+ def ecomment(i)
146
+ Colours.ecomment(i)
147
+ end
148
+
149
+ # ========================================================================= #
150
+ # === check_whether_we_have_found_any_pdf_file
151
+ #
152
+ # This method checks whether we have found any .pdf file or not. If not,
153
+ # we try to check whether the current directory has any .pdf file at all.
154
+ # ========================================================================= #
155
+ def check_whether_we_have_found_any_pdf_file
156
+ if @open_these_pdf_files.empty?
157
+ any_pdf_file = get_all_pdf_files
158
+ if ! any_pdf_file.empty?
159
+ _ = any_pdf_file.first
160
+ e 'It seems as if no .pdf file was supplied.'
161
+ e 'We did however find at least one .pdf file. We will now '
162
+ e 'use this .pdf file at '+sfile(_)+'.'
163
+ add _
164
+ end
165
+ end
166
+ end
167
+
168
+ # ========================================================================= #
169
+ # === edit_this_file_here
170
+ # ========================================================================= #
171
+ def edit_this_file_here
172
+ _ = 'bluefish '+__FILE__
173
+ esystem _
174
+ end
175
+
176
+ # ========================================================================= #
177
+ # === do_log_this_pdf_file_was_opened_last
178
+ # ========================================================================= #
179
+ def do_log_this_pdf_file_was_opened_last(i = @full_file_location)
180
+ save_what_into(i, LAST_PDF_FILE_OPENED)
181
+ end
182
+
183
+ # ========================================================================= #
184
+ # === set_full_file_location
185
+ # ========================================================================= #
186
+ def set_full_file_location(i)
187
+ unless i.include? '/'
188
+ i = Dir.pwd+'/'+i
189
+ end
190
+ @full_file_location = i
191
+ end
192
+
193
+ # ========================================================================= #
194
+ # === MainPdf[]
195
+ # ========================================================================= #
196
+ def self.[](i, optional_commandline_arguments = nil)
197
+ _ = self.new(i, :do_not_run_yet)
198
+ if optional_commandline_arguments
199
+ _.commandline_arguments = optional_commandline_arguments
200
+ end
201
+ _.run
202
+ end
203
+
204
+ # ========================================================================= #
205
+ # === check_commandline_options
206
+ #
207
+ # The convention is simply - if it is a valid file, we
208
+ # add it to the list of pdf files to open.
209
+ # ========================================================================= #
210
+ def check_commandline_options(i)
211
+ if i.is_a? Array
212
+ i.each {|entry| check_commandline_options(entry) }
213
+ else # We either add it to the list of pdf files to open, or to the commandline options
214
+ if File.exist? i
215
+ # =================================================================== #
216
+ # Open the .pdf file here, if it exists.
217
+ # =================================================================== #
218
+ add_to_open_these_pdf_files(i)
219
+ else
220
+ @commandline_options << i
221
+ end
222
+ end
223
+ end; alias commandline_arguments= check_commandline_options # === commandline_arguments=
224
+
225
+ # ========================================================================= #
226
+ # === process_commandline_options
227
+ #
228
+ # Use this method to process the commandline options given.
229
+ # ========================================================================= #
230
+ def process_commandline_options
231
+ _ = @commandline_options.first
232
+ case _ # case tag
233
+ # ======================================================================= #
234
+ # === --open-main-pdf
235
+ # ======================================================================= #
236
+ when /^-?-?open(-|_)?main(-|_)?pdf$/i
237
+ add_to_open_these_pdf_files(:the_main_pdf)
238
+ # ======================================================================= #
239
+ # === mpdf --open-last
240
+ # ======================================================================= #
241
+ when /^-?-?open(-|_)?last$/i,
242
+ 'OPENLATEST','LATEST',
243
+ 'LAST','last'
244
+ open_last_found_pdf
245
+ # ======================================================================= #
246
+ # === mpdf --query?
247
+ # ======================================================================= #
248
+ when /-?-?query\??/,'QUERY','QUERY?','?','PDF?',/-?-?current\??/
249
+ feedback_pdf_handler_in_use
250
+ exit
251
+ # ======================================================================= #
252
+ # === mpdf --file?
253
+ # ======================================================================= #
254
+ when /-?-?file\??/
255
+ show_yaml_file
256
+ exit
257
+ # ======================================================================= #
258
+ # === mpdf SAVE okular
259
+ # ======================================================================= #
260
+ when 'SAVE','SET','save','set','--save','--set'
261
+ save_new_pdf_handler
262
+ # ======================================================================= #
263
+ # === mpdf --help
264
+ # ======================================================================= #
265
+ when /-?-?help/,'HELP'
266
+ feedback_available_commandline_options
267
+ # ======================================================================= #
268
+ # === mpdf --restore
269
+ # ======================================================================= #
270
+ when /-?-?restore/,'RESTORE'
271
+ add( File.readlines(LAST_PDF_FILE_OPENED)[0].to_s.strip )
272
+ # ======================================================================= #
273
+ # === mpdf --edit
274
+ # ======================================================================= #
275
+ when 'EDIT','OPEN','OPEN_SELF','OPENSELF',/edit/
276
+ edit_this_file_here; exit
277
+ # ======================================================================= #
278
+ # === mpdf --okular
279
+ # ======================================================================= #
280
+ when 'USE_OKULAR','OKULAR',/^-?-?okular/
281
+ save_new_pdf_handler :okular
282
+ # ======================================================================= #
283
+ # === mpdf --use-evince
284
+ # ======================================================================= #
285
+ when 'USE_EVINCE','EVINCE','evince',
286
+ /^-?-?use(-|_)?evince$/i
287
+ save_new_pdf_handler :evince
288
+ # ======================================================================= #
289
+ # === mpdf --fullscreen
290
+ # ======================================================================= #
291
+ when 'FULLSCREEN','--fullscreen'
292
+ @pdf_viewer << ' --fullscreen'
293
+ # ======================================================================= #
294
+ # === mpdf LAST_DOWNLOAD
295
+ # ======================================================================= #
296
+ when 'LAST_DOWNLOAD','LASTDOWNLOAD'
297
+ last_downloaded_file = LAST_DOWNLOADED_FILE
298
+ if File.exist? last_downloaded_file
299
+ add(File.readlines(last_downloaded_file).first)
300
+ end
301
+ else # else step
302
+ unless File.exist? _
303
+ opn; e 'Unsure what to do with input `'+simp(_)+'`.'
304
+ end if _
305
+ end
306
+ end
307
+
308
+ # ========================================================================= #
309
+ # === run_sys_command
310
+ # ========================================================================= #
311
+ def run_sys_command
312
+ process_commandline_options
313
+ check_whether_we_have_found_any_pdf_file
314
+ open_all_pdf_files
315
+ end
316
+
317
+ # ========================================================================= #
318
+ # === open_all_pdf_files
319
+ # ========================================================================= #
320
+ def open_all_pdf_files
321
+ @open_these_pdf_files.each {|entry|
322
+ consider_opening_this_pdf_file(entry)
323
+ }
324
+ end
325
+
326
+ # ========================================================================= #
327
+ # === consider_opening_this_pdf_file
328
+ #
329
+ # This method will do the actual opening-part, by using system().
330
+ # ========================================================================= #
331
+ def consider_opening_this_pdf_file(i = @open_these_pdf_files)
332
+ if File.exist? i
333
+ set_full_file_location(i)
334
+ i = '"'+i+'"' if i.include? ' '
335
+ i = '"'+i+'"' if i.include? '('
336
+ i = '"'+i+'"' if i.include? "'"
337
+ i = @pdf_viewer+' '+i+' &'
338
+ do_log_this_pdf_file_was_opened_last
339
+ esystem i
340
+ else # Ok, at this point the file does not exist. Try a regex first.
341
+ results = Dir['*'+i+'*']
342
+ if results.empty?
343
+ opn; e 'No valid .pdf file was found at `'+sfile(i)+'`.'
344
+ opn; e 'Thus we can not open anything.'
345
+ else
346
+ consider_opening_this_pdf_file(results.first)
347
+ end
348
+ end
349
+ end
350
+
351
+ # ========================================================================= #
352
+ # === feedback_available_commandline_options (help tag)
353
+ #
354
+ # Show the available help options next.
355
+ # ========================================================================= #
356
+ def feedback_available_commandline_options(
357
+ shall_we_exit = true
358
+ )
359
+ cliner {
360
+ ecomment ' RESTORE - open the last opened .pdf file in general'
361
+ ecomment ' OPEN_LAST - open the "youngest" .pdf file in the current working directory'
362
+ ecomment ' EDIT - open this file here'
363
+ ecomment ' QUERY - query which is our current default pdf reader'
364
+ ecomment ' --current? - alias to the above'
365
+ ecomment ' --file? - show the location of the .yml file'
366
+ ecomment ' SAVE / SET - save a new mpdf handler to use (i.e. '\
367
+ '"okular", via "mpdf SAVE okular")'
368
+ ecomment ' LAST_DOWNLOAD - open the last downloaded file stored in '+
369
+ LAST_DOWNLOADED_FILE
370
+ }
371
+ exit if shall_we_exit
372
+ end
373
+
374
+ # ========================================================================= #
375
+ # === get_all_pdf_files
376
+ # ========================================================================= #
377
+ def get_all_pdf_files
378
+ _ = DirectoryParadise::Reprt.new('', :do_not_run_yetfalse)
379
+ _.menu(:latest)
380
+ _.gather_content
381
+ only_pdf_files = _.content.select {|entry|
382
+ entry.include? '.pdf'
383
+ }
384
+ return only_pdf_files
385
+ end
386
+
387
+ # ========================================================================= #
388
+ # === open_last_found_pdf
389
+ #
390
+ # This will open the last .pdf file in the current directory. Which
391
+ # one is that? We will act on the file information here.
392
+ # ========================================================================= #
393
+ def open_last_found_pdf
394
+ add :latest_pdf
395
+ end
396
+
397
+ # ========================================================================= #
398
+ # === add_to_open_these_pdf_files (add tag)
399
+ # ========================================================================= #
400
+ def add_to_open_these_pdf_files(i)
401
+ case i
402
+ # ======================================================================= #
403
+ # === :main_pdf
404
+ # ======================================================================= #
405
+ when :main_pdf,
406
+ :the_main_pdf
407
+ i = ENV['MAIN_BOOK'].to_s
408
+ # ======================================================================= #
409
+ # === :latest_pdf
410
+ # ======================================================================= #
411
+ when :latest_pdf
412
+ i = get_all_pdf_files.sort.first.to_s # Get the latest .pdf file. [0] Should be the properly sorted one.
413
+ end
414
+ @open_these_pdf_files << i
415
+ end; alias add add_to_open_these_pdf_files # === add
416
+
417
+ # ========================================================================= #
418
+ # === run (run tag)
419
+ # ========================================================================= #
420
+ def run
421
+ run_sys_command
422
+ end
423
+
424
+ end
425
+
426
+ # =========================================================================== #
427
+ # === PdfParadise.main_pdf
428
+ # =========================================================================== #
429
+ def self.main_pdf(i = ARGV)
430
+ ::PdfParadise::MainPdf.new(i)
431
+ end
432
+
433
+ end
434
+
435
+ if __FILE__ == $PROGRAM_NAME
436
+ PdfParadise.main_pdf(ARGV)
437
+ end # mpdf AUPC_Einheit_I_Einfuehrung_2013.pdf AUPC_Einheit_II_2013.pdf