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,428 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === PdfParadise::GUI::Gtk::DeleteTheFirstOrTheLastPageOfThisPdfFileModule
6
+ # =========================================================================== #
7
+ # require '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'
8
+ # include ::PdfParadise::GUI::Gtk::DeleteTheFirstOrTheLastPageOfThisPdfFileModule
9
+ # =========================================================================== #
10
+ module PdfParadise
11
+
12
+ module GUI
13
+
14
+ module Gtk
15
+
16
+ module DeleteTheFirstOrTheLastPageOfThisPdfFileModule
17
+
18
+ require 'pdf_paradise/utility_scripts/delete_first_page_of_this_pdf_file.rb'
19
+ require 'pdf_paradise/utility_scripts/delete_last_page_of_this_pdf_file.rb'
20
+ require 'pdf_paradise/utility_scripts/delete_this_page_of_this_pdf_file.rb'
21
+
22
+ require 'gtk_paradise/requires/require_the_base_module.rb'
23
+ include ::Gtk::BaseModule
24
+
25
+ require 'colours'
26
+ include Colours
27
+
28
+ # ========================================================================= #
29
+ # === NAMESPACE
30
+ # ========================================================================= #
31
+ NAMESPACE = inspect
32
+
33
+ # ========================================================================= #
34
+ # === ARRAY_ADD_THESE_SHORTCUT_FOLDERS
35
+ # ========================================================================= #
36
+ ARRAY_ADD_THESE_SHORTCUT_FOLDERS = [
37
+ "/",
38
+ '/Depot/PDF/'
39
+ ]
40
+
41
+ # ========================================================================= #
42
+ # === TITLE
43
+ # ========================================================================= #
44
+ TITLE = 'Remove a specific page from a .pdf file.'
45
+
46
+ # ========================================================================= #
47
+ # === WIDTH
48
+ # ========================================================================= #
49
+ WIDTH = 1600
50
+
51
+ # ========================================================================= #
52
+ # === HEIGHT
53
+ # ========================================================================= #
54
+ HEIGHT = 400
55
+
56
+ # ========================================================================= #
57
+ # === USE_THIS_FONT
58
+ # ========================================================================= #
59
+ USE_THIS_FONT = :dejavu_condensed_24
60
+
61
+ # ========================================================================= #
62
+ # === SMALLER_FONT
63
+ # ========================================================================= #
64
+ SMALLER_FONT = :dejavu_condensed_22
65
+
66
+ # ========================================================================= #
67
+ # === initialize
68
+ # ========================================================================= #
69
+ def initialize(
70
+ optional_file = nil,
71
+ run_already = true
72
+ )
73
+ super(:vertical)
74
+ reset
75
+ run if run_already
76
+ end
77
+
78
+ # ========================================================================= #
79
+ # === reset
80
+ # ========================================================================= #
81
+ def reset
82
+ reset_the_internal_variables
83
+ # ======================================================================= #
84
+ # === @configuration
85
+ # ======================================================================= #
86
+ @configuration = [true, __dir__, NAMESPACE]
87
+ # ======================================================================= #
88
+ # === @title
89
+ # ======================================================================= #
90
+ @title = TITLE
91
+ # ======================================================================= #
92
+ # === @width
93
+ # ======================================================================= #
94
+ @width = WIDTH
95
+ # ======================================================================= #
96
+ # === @height
97
+ # ======================================================================= #
98
+ @height = HEIGHT
99
+ set_use_this_font(USE_THIS_FONT)
100
+ use_gtk_paradise_project_css_file
101
+ infer_the_size_automatically
102
+ end
103
+
104
+ # ========================================================================= #
105
+ # === padding?
106
+ # ========================================================================= #
107
+ def padding?
108
+ 0
109
+ end
110
+
111
+ # ========================================================================= #
112
+ # === border_size?
113
+ # ========================================================================= #
114
+ def border_size?
115
+ 2
116
+ end
117
+
118
+ # ========================================================================= #
119
+ # === add_the_remove_the_first_page_and_remove_the_last_page_of_the_pdf_file_buttons
120
+ # ========================================================================= #
121
+ def add_the_remove_the_first_page_and_remove_the_last_page_of_the_pdf_file_buttons
122
+ @hbox1.minimal(@button_remove_the_first_page_of_the_pdf_file, 2)
123
+ @hbox1.minimal(@button_remove_the_last_page_of_the_pdf_file, 2)
124
+ end
125
+
126
+ # ========================================================================= #
127
+ # === create_skeleton
128
+ # ========================================================================= #
129
+ def create_skeleton
130
+ @hbox1 = gtk_vbox
131
+ create_buttons
132
+ create_entries
133
+ create_labels
134
+ @gtk_text_above_the_main_entry = gtk_bold_label(
135
+ 'Set the path to the .pdf file below this text here.'
136
+ ) {{
137
+ tooltip: 'You need to supply the path to the .pdf file '\
138
+ 'into the input field on the right side.'
139
+ }}
140
+ @gtk_text_for_notification = gtk_label
141
+ end
142
+
143
+ # ========================================================================= #
144
+ # === create_buttons (buttons tag)
145
+ #
146
+ # This method can be used to create all buttons in this small application.
147
+ # ========================================================================= #
148
+ def create_buttons
149
+ # ======================================================================= #
150
+ # === @button_remove_the_first_page_of_the_pdf_file
151
+ # ======================================================================= #
152
+ @button_remove_the_first_page_of_the_pdf_file = gtk_button('Remove the _first page')
153
+ @button_remove_the_first_page_of_the_pdf_file.skyblue
154
+ @button_remove_the_first_page_of_the_pdf_file.do_use_mnemonic
155
+ @button_remove_the_first_page_of_the_pdf_file.hint =
156
+ "<b>Click</b> on this button to remove the first page of the pdf file.\n\n"\
157
+ "Do not forget to make sure that the .pdf file exists at that location.\n"\
158
+ "Note that the program called qpdf has to be installed as well."
159
+ @button_remove_the_first_page_of_the_pdf_file.on_clicked {
160
+ do_remove_the_first_page_of_the_pdf_file
161
+ }
162
+ # ======================================================================= #
163
+ # === @button_remove_the_last_page_of_the_pdf_file
164
+ # ======================================================================= #
165
+ @button_remove_the_last_page_of_the_pdf_file = gtk_button('Remove the _last page')
166
+ @button_remove_the_last_page_of_the_pdf_file.skyblue
167
+ @button_remove_the_last_page_of_the_pdf_file.do_use_mnemonic
168
+ @button_remove_the_last_page_of_the_pdf_file.hint =
169
+ " <b>Click</b> on this button to remove the last page of the pdf file.\n"\
170
+ "Do not forget to make sure that the .pdf file exists at that location."
171
+ @button_remove_the_last_page_of_the_pdf_file.on_clicked {
172
+ do_remove_the_last_page_of_the_pdf_file
173
+ }
174
+ # ======================================================================= #
175
+ # === @button_file_chooser
176
+ # ======================================================================= #
177
+ @button_file_chooser = gtk_button('🗄️ Choose a file')
178
+ @button_file_chooser.hint = 'Click this button to '\
179
+ 'select a file.'
180
+ @button_file_chooser.skyblue
181
+ @button_file_chooser.on_clicked {
182
+ open_file_chooser_dialog
183
+ }
184
+ end
185
+
186
+ # ========================================================================= #
187
+ # === do_remove_the_last_page_of_the_pdf_file
188
+ # ========================================================================= #
189
+ def do_remove_the_last_page_of_the_pdf_file
190
+ e 'Now removing the last .pdf page.'
191
+ target_file = @entry_for_the_path_to_the_pdf_file.text.to_s
192
+ if File.exist?(target_file)
193
+ PdfParadise.remove_the_last_page_of_this_pdf_file(
194
+ target_file
195
+ )
196
+ # ===================================================================== #
197
+ # Notify the user that we finished here.
198
+ # ===================================================================== #
199
+ update_all_done_finished_at
200
+ else
201
+ no_file_was_found_at(target_file)
202
+ end
203
+ end
204
+
205
+ # ========================================================================= #
206
+ # === update_all_done_finished_at
207
+ # ========================================================================= #
208
+ def update_all_done_finished_at
209
+ @gtk_text_for_notification.set_text(
210
+ 'All done! Finished at <b>'+Time.now.to_s+'</b>'
211
+ )
212
+ @gtk_text_for_notification.do_markify
213
+ end
214
+
215
+ # ========================================================================= #
216
+ # === do_remove_the_first_page_of_the_pdf_file
217
+ #
218
+ # This is the main action of this class.
219
+ # ========================================================================= #
220
+ def do_remove_the_first_page_of_the_pdf_file
221
+ e 'Now removing the first .pdf page.'
222
+ target_file = @entry_for_the_path_to_the_pdf_file.text.to_s
223
+ if File.exist?(target_file)
224
+ PdfParadise.remove_the_first_page_of_this_pdf_file(
225
+ target_file
226
+ )
227
+ # ===================================================================== #
228
+ # Notify the user that we finished here.
229
+ # ===================================================================== #
230
+ update_all_done_finished_at
231
+ else
232
+ no_file_was_found_at(target_file)
233
+ end
234
+ end
235
+
236
+ # ========================================================================= #
237
+ # === no_file_was_found_at
238
+ # ========================================================================= #
239
+ def no_file_was_found_at(i)
240
+ e "No file was found at #{sfile(i)}."
241
+ end
242
+
243
+ # ========================================================================= #
244
+ # === add_the_remove_this_page_entry
245
+ # ========================================================================= #
246
+ def add_the_remove_this_page_entry
247
+ hbox = gtk_hbox
248
+ hbox.minimal(
249
+ left_aligned_text(
250
+ 'Denote which .pdf page (as a number) '\
251
+ 'is to be removed '
252
+ )
253
+ )
254
+ hbox.minimal(@entry_remove_this_pdf_page)
255
+ @button_remove_the_specified_page = gtk_button('🗙')
256
+ @button_remove_the_specified_page.hint = 'Click '\
257
+ 'this button in order to remove the specified page '\
258
+ 'from the .pdf document at hand.'
259
+ @button_remove_the_specified_page.on_clicked {
260
+ do_remove_this_page(
261
+ @entry_remove_this_pdf_page.text.to_s
262
+ )
263
+ }
264
+ @button_remove_the_specified_page.set_size_request(160, 48)
265
+ @button_remove_the_specified_page.disallow_resizing
266
+ hbox.minimal(@button_remove_the_specified_page)
267
+ @hbox1.minimal(hbox)
268
+ end
269
+
270
+ # ========================================================================= #
271
+ # === create_labels
272
+ # ========================================================================= #
273
+ def create_labels
274
+ @label_on_top = gtk_left_aligned_label(
275
+ 'Denote which .pdf file is to be manipulated, in the '\
276
+ 'following entry.'
277
+ )
278
+ @label_on_top.use_this_font(SMALLER_FONT)
279
+ end
280
+
281
+ # ========================================================================= #
282
+ # === connect_skeleton
283
+ # ========================================================================= #
284
+ def connect_skeleton
285
+ abort_on_exception
286
+ @hbox1.maximal(@label_on_top, 2)
287
+ @hbox1.minimal(horizontal_spacer, 2)
288
+ @hbox1.minimal(@gtk_text_above_the_main_entry, 2)
289
+ @hbox1.maximal(@entry_for_the_path_to_the_pdf_file, 2)
290
+ # ======================================================================= #
291
+ # And add the file-chooser button:
292
+ # ======================================================================= #
293
+ @hbox1.minimal(@button_file_chooser)
294
+ # ======================================================================= #
295
+ # Next add the remove-this-page entry.
296
+ # ======================================================================= #
297
+ add_the_remove_this_page_entry
298
+ # ======================================================================= #
299
+ # Next add the two "remove first page" and "remove last page"
300
+ # buttons.
301
+ # ======================================================================= #
302
+ add_the_remove_the_first_page_and_remove_the_last_page_of_the_pdf_file_buttons
303
+ @hbox1.minimal(@gtk_text_for_notification)
304
+ minimal(@hbox1, 1)
305
+ end
306
+
307
+ require 'gtk_paradise/toplevel_methods/select_file.rb'
308
+ # ========================================================================= #
309
+ # === open_file_chooser_dialog (open tag)
310
+ # ========================================================================= #
311
+ def open_file_chooser_dialog
312
+ current_folder = return_pwd
313
+ if is_on_roebe? and File.directory?('/Depot/j/')
314
+ current_folder = '/Depot/j/'
315
+ end
316
+ @extra_button = gtk_button('_Extra button')
317
+ @extra_button.on_clicked { e ' > Extra button was clicked' }
318
+
319
+ filename = ::Gtk.select_file(parent_widget?) {{
320
+ current_folder: current_folder,
321
+ show_hidden: true,
322
+ extra_widget: @extra_button,
323
+ add_these_shortcut_folders: ARRAY_ADD_THESE_SHORTCUT_FOLDERS,
324
+ use_this_file_filter: '*.pdf'
325
+ }}
326
+
327
+ @entry_for_the_path_to_the_pdf_file.set_text(filename)
328
+ end
329
+
330
+ # ========================================================================= #
331
+ # === parent_widget?
332
+ # ========================================================================= #
333
+ def parent_widget?
334
+ @parent_widget
335
+ end
336
+
337
+ # ========================================================================= #
338
+ # === set_parent_widget
339
+ # ========================================================================= #
340
+ def set_parent_widget(i)
341
+ @parent_widget = i
342
+ end
343
+
344
+ # ========================================================================= #
345
+ # === run
346
+ # ========================================================================= #
347
+ def run
348
+ create_skeleton_then_connect_skeleton
349
+ show_all
350
+ end
351
+
352
+ # ========================================================================= #
353
+ # === create_entries (entries tag)
354
+ # ========================================================================= #
355
+ def create_entries
356
+ @entry_for_the_path_to_the_pdf_file = gtk_entry('')
357
+ @entry_for_the_path_to_the_pdf_file.highlight_on_click_event
358
+ @entry_for_the_path_to_the_pdf_file.add_css_class(
359
+ 'BG_floralwhite'
360
+ )
361
+ # ======================================================================= #
362
+ # === @entry_remove_this_pdf_page
363
+ # ======================================================================= #
364
+ @entry_remove_this_pdf_page = gtk_entry
365
+ @entry_remove_this_pdf_page.highlight_on_click_event
366
+ @entry_remove_this_pdf_page.bblack1
367
+ @entry_remove_this_pdf_page.add_css_class(
368
+ 'BG_floralwhite'
369
+ )
370
+ @entry_remove_this_pdf_page.align_to_the_center
371
+ @entry_remove_this_pdf_page.set_size_request(160, 48)
372
+ end
373
+
374
+ # ========================================================================= #
375
+ # === do_remove_this_page
376
+ # ========================================================================= #
377
+ def do_remove_this_page(
378
+ i = @entry_remove_this_pdf_page.text.to_s,
379
+ target_file = @entry_for_the_path_to_the_pdf_file.text.to_s
380
+ )
381
+ if File.exist?(target_file)
382
+ PdfParadise.remove_this_page_of_that_pdf_file(
383
+ i, target_file
384
+ )
385
+ update_all_done_finished_at
386
+ else
387
+ no_file_was_found_at(target_file)
388
+ end
389
+ end
390
+
391
+ # ========================================================================= #
392
+ # === PdfParadise::GUI::Gtk::DeleteTheFirstOrTheLastPageOfThisPdfFileModule.run
393
+ # ========================================================================= #
394
+ def self.run
395
+ require 'gtk_paradise/run'
396
+ _ = ::PdfParadise::GUI::Gtk::DeleteTheFirstOrTheLastPageOfThisPdfFile.new
397
+ r = ::Gtk.run
398
+ r << _
399
+ r.set_size_request(
400
+ _.width?,
401
+ _.height?
402
+ )
403
+ r.top_left_then_run
404
+ end
405
+
406
+ end; end; end
407
+
408
+ # =========================================================================== #
409
+ # === PdfParadise.return_widget_remove_first_page_of_pdf_file
410
+ # =========================================================================== #
411
+ def self.return_widget_remove_first_page_of_pdf_file
412
+ ::PdfParadise::GUI::Gtk::DeleteTheFirstOrTheLastPageOfThisPdfFile.new
413
+ end
414
+
415
+ # =========================================================================== #
416
+ # === PdfParadise.start_gtk_gui_remove_first_page_of_pdf_file
417
+ # =========================================================================== #
418
+ def self.start_gtk_gui_remove_first_page_of_pdf_file
419
+ require 'gtk_paradise/run'
420
+ _ = PdfParadise::GUI::Gtk::DeleteTheFirstOrTheLastPageOfThisPdfFile.new
421
+ r = ::Gtk.run
422
+ _.set_parent_widget(r)
423
+ r.easy_exit
424
+ r << _
425
+ r.top_left_then_run
426
+ end
427
+
428
+ end
@@ -0,0 +1,5 @@
1
+ #button1 {
2
+ border: 3px solid darkblue;
3
+ color: teal;
4
+ background: oldlace;
5
+ }
@@ -0,0 +1,284 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === PdfParadise::GUI::Gtk::PdfViewerModule
6
+ #
7
+ # This widget can be used to "view" a .pdf file. Right now we will
8
+ # convert it to a .pdf file, then simply display the text.
9
+ # =========================================================================== #
10
+ # require 'pdf_paradise/gui/shared_code/pdf_viewer/pdf_viewer_module.rb'
11
+ # include ::PdfParadise::GUI::Gtk::PdfViewerModule
12
+ # =========================================================================== #
13
+ module PdfParadise
14
+
15
+ module GUI
16
+
17
+ module Gtk
18
+
19
+ module PdfViewerModule
20
+
21
+ require 'gtk_paradise/requires/require_the_base_module.rb'
22
+ include ::Gtk::BaseModule
23
+
24
+ # ========================================================================= #
25
+ # === NAMESPACE
26
+ # ========================================================================= #
27
+ NAMESPACE = inspect
28
+
29
+ # ========================================================================= #
30
+ # === TITLE
31
+ # ========================================================================= #
32
+ TITLE = 'View .pdf files'
33
+
34
+ # ========================================================================= #
35
+ # === WIDTH
36
+ # ========================================================================= #
37
+ WIDTH = 1600
38
+
39
+ # ========================================================================= #
40
+ # === HEIGHT
41
+ # ========================================================================= #
42
+ HEIGHT = 600
43
+
44
+ # ========================================================================= #
45
+ # === initialize
46
+ # ========================================================================= #
47
+ def initialize(
48
+ commandline_arguments = ARGV,
49
+ run_already = true
50
+ )
51
+ super(:vertical)
52
+ reset
53
+ set_commandline_arguments(
54
+ commandline_arguments
55
+ )
56
+ run if run_already
57
+ end
58
+
59
+ # ========================================================================= #
60
+ # === reset
61
+ # ========================================================================= #
62
+ def reset
63
+ reset_the_internal_variables
64
+ # ======================================================================= #
65
+ # === @configuration
66
+ # ======================================================================= #
67
+ @configuration = [true, __dir__, NAMESPACE]
68
+ # ======================================================================= #
69
+ # === @parent_widget
70
+ # ======================================================================= #
71
+ @parent_widget = nil
72
+ # ======================================================================= #
73
+ # === @title
74
+ # ======================================================================= #
75
+ @title = TITLE
76
+ # ======================================================================= #
77
+ # === @width
78
+ # ======================================================================= #
79
+ @width = WIDTH
80
+ # ======================================================================= #
81
+ # === @height
82
+ # ======================================================================= #
83
+ @height = HEIGHT
84
+ set_use_this_font(:dejavu_condensed_23)
85
+ use_project_css_file
86
+ infer_the_size_automatically
87
+ end
88
+
89
+ # ========================================================================= #
90
+ # === padding?
91
+ # ========================================================================= #
92
+ def padding?
93
+ 2
94
+ end
95
+
96
+ # ========================================================================= #
97
+ # === border_size?
98
+ # ========================================================================= #
99
+ def border_size?
100
+ 2
101
+ end
102
+
103
+ # ========================================================================= #
104
+ # === create_skeleton
105
+ # ========================================================================= #
106
+ def create_skeleton
107
+ @text_buffer = gtk_text_buffer
108
+ create_the_text_view
109
+ create_the_buttons
110
+ create_the_scrolled_window
111
+ end
112
+
113
+ # ========================================================================= #
114
+ # === create_the_scrolled_window
115
+ # ========================================================================= #
116
+ def create_the_scrolled_window
117
+ @scrolled_window = gtk_scrolled_window(@text_view) { :always_show_the_scrollbars }
118
+ @scrolled_window.css_class('bblack1')
119
+ end
120
+
121
+ # ========================================================================= #
122
+ # === create_the_text_view
123
+ # ========================================================================= #
124
+ def create_the_text_view
125
+ @text_view = gtk_text_view(@text_buffer)
126
+ end
127
+
128
+ # ========================================================================= #
129
+ # === do_the_conversion
130
+ #
131
+ # This method will do the actual file-conversion.
132
+ # ========================================================================= #
133
+ def do_the_conversion(
134
+ i = @entry_this_is_the_pdf_file.text.to_s
135
+ )
136
+ if File.exist? i
137
+ location_of_the_newly_generated_file = '/Depot/j/converted_pdf_file.md'
138
+ # ===================================================================== #
139
+ # Next, do the conversion.
140
+ # ===================================================================== #
141
+ `pdftotext #{i} #{location_of_the_newly_generated_file}`
142
+ if File.exist? location_of_the_newly_generated_file
143
+ dataset = File.read(location_of_the_newly_generated_file).to_s
144
+ set_text_in_the_main_buffer(dataset)
145
+ else
146
+ e 'No file exists at '+location_of_the_newly_generated_file+'.'
147
+ end
148
+ else
149
+ e 'No file exists at '+::Colours.sfile(i)+'.'
150
+ end
151
+ end; alias trigger_the_conversion do_the_conversion # === trigger_the_conversion
152
+
153
+ # ========================================================================= #
154
+ # === create_the_buttons
155
+ # ========================================================================= #
156
+ def create_the_buttons
157
+ @button_view_this_pdf_file = gtk_button('View this .pdf file')
158
+ @button_view_this_pdf_file.set_name('button1')
159
+ @button_view_this_pdf_file.hint = 'Click on '\
160
+ 'this button to view the content of the .pdf file.'
161
+ @button_view_this_pdf_file.on_clicked {
162
+ do_the_conversion(@entry_this_is_the_pdf_file.text.to_s)
163
+ }
164
+ @button_clear = gtk_button('Clear')
165
+ @button_clear.hint = 'Click this button '\
166
+ 'to clear the buffer shown below.'
167
+ @button_clear.on_clicked {
168
+ @text_buffer.clear
169
+ }
170
+ @button_file_picker = gtk_button('_Pick a file')
171
+ @button_file_picker.hint = 'Pick a local .pdf file.'
172
+ @button_file_picker.on_clicked {
173
+ do_pick_a_file
174
+ }
175
+ end
176
+
177
+ # ========================================================================= #
178
+ # === connect_skeleton (connect tag)
179
+ # ========================================================================= #
180
+ def connect_skeleton
181
+ abort_on_exception
182
+ # ======================================================================= #
183
+ # === @entry_this_is_the_pdf_file
184
+ # ======================================================================= #
185
+ @entry_this_is_the_pdf_file = gtk_entry(
186
+ '/Depot/j/test.pdf'
187
+ )
188
+ @entry_this_is_the_pdf_file.yellow_background
189
+ top_hbox = gtk_hbox
190
+ top_hbox.maximal(@entry_this_is_the_pdf_file, 3)
191
+ top_hbox.maximal(@button_view_this_pdf_file, 3)
192
+ top_hbox.minimal(@button_file_picker, 3)
193
+ top_hbox.minimal(@button_clear, 3)
194
+ minimal(top_hbox)
195
+ maximal(@scrolled_window)
196
+ end
197
+
198
+ # ========================================================================= #
199
+ # === set_parent_widget
200
+ # ========================================================================= #
201
+ def set_parent_widget(i)
202
+ @parent_widget = i
203
+ end
204
+
205
+ # ========================================================================= #
206
+ # === set_text_in_the_main_buffer
207
+ # ========================================================================= #
208
+ def set_text_in_the_main_buffer(i)
209
+ i = i.to_s.dup.strip
210
+ i.delete!('® ') # Do a bit ad-hoc deletion.
211
+ @text_buffer.set_text(i.to_s.dup)
212
+ GC.start
213
+ end
214
+
215
+ # ========================================================================= #
216
+ # === set_this_as_the_active_pdf_file
217
+ # ========================================================================= #
218
+ def set_this_as_the_active_pdf_file(i)
219
+ i = i.to_s.dup
220
+ @entry_this_is_the_pdf_file.set_text(i)
221
+ end
222
+
223
+ # ========================================================================= #
224
+ # === do_pick_a_file
225
+ # ========================================================================= #
226
+ def do_pick_a_file
227
+ filename = ::Gtk.select_file(@parent_widget) {{
228
+ current_folder: '/Depot/j/',
229
+ show_hidden: true,
230
+ add_these_shortcut_folders: ['/Depot/j/'],
231
+ use_this_file_filter: '*.pdf'
232
+ }}
233
+ if File.exist? filename
234
+ set_this_as_the_active_pdf_file_then_trigger_the_conversion(filename)
235
+ end
236
+ end
237
+
238
+ # ========================================================================= #
239
+ # === set_this_as_the_active_pdf_file_then_trigger_the_conversion
240
+ # ========================================================================= #
241
+ def set_this_as_the_active_pdf_file_then_trigger_the_conversion(
242
+ filename
243
+ )
244
+ set_this_as_the_active_pdf_file(filename)
245
+ trigger_the_conversion
246
+ end
247
+
248
+ # ========================================================================= #
249
+ # === run
250
+ # ========================================================================= #
251
+ def run
252
+ create_skeleton_then_connect_skeleton
253
+ menu
254
+ end
255
+
256
+ # ========================================================================= #
257
+ # === menu (menu tag)
258
+ # ========================================================================= #
259
+ def menu(
260
+ i = commandline_arguments?
261
+ )
262
+ if i.is_a? Array
263
+ i.each {|entry| menu(entry) }
264
+ else
265
+ if File.exist? i
266
+ set_this_as_the_active_pdf_file_then_trigger_the_conversion(i)
267
+ end
268
+ end
269
+ end
270
+
271
+ # ========================================================================= #
272
+ # === PdfParadise::GUI::Gtk::PdfViewerModule.run
273
+ # ========================================================================= #
274
+ def self.run
275
+ require 'gtk_paradise/run'
276
+ _ = ::PdfParadise::GUI::Gtk::PdfViewer.new
277
+ r = ::Gtk.run
278
+ _.set_parent_widget(r)
279
+ r << _
280
+ r.automatic_title_and_size
281
+ r.top_left_then_run
282
+ end
283
+
284
+ end; end; end; end