pdf_paradise 0.1.66

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of pdf_paradise might be problematic. Click here for more details.

Files changed (110) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +705 -0
  3. data/bin/automatic_pdf_title +7 -0
  4. data/bin/combine_these_pdf_pages +7 -0
  5. data/bin/compress_via_hexapdf +7 -0
  6. data/bin/convert_markdown_to_pdf +7 -0
  7. data/bin/convert_pdf_to_text +7 -0
  8. data/bin/delete_first_page_of_this_pdf_file +7 -0
  9. data/bin/merge_then_open +7 -0
  10. data/bin/n_pages +10 -0
  11. data/bin/open_main_pdf +7 -0
  12. data/bin/pdf_paradise +9 -0
  13. data/bin/set_main_book +7 -0
  14. data/bin/set_title_of_this_pdf_file +15 -0
  15. data/doc/README.gen +662 -0
  16. data/doc/todo/todo.md +7 -0
  17. data/lib/pdf_paradise/base/base.rb +239 -0
  18. data/lib/pdf_paradise/base/colours.rb +36 -0
  19. data/lib/pdf_paradise/commandline/commandline.rb +101 -0
  20. data/lib/pdf_paradise/commandline/help.rb +73 -0
  21. data/lib/pdf_paradise/commandline/menu.rb +142 -0
  22. data/lib/pdf_paradise/compress/compress_via_hexapdf.rb +27 -0
  23. data/lib/pdf_paradise/compress_this_pdf_file.rb +87 -0
  24. data/lib/pdf_paradise/constants/constants.rb +76 -0
  25. data/lib/pdf_paradise/convert_text_to_pdf.rb +94 -0
  26. data/lib/pdf_paradise/css/project.css +17 -0
  27. data/lib/pdf_paradise/djvu_to_pdf.rb +85 -0
  28. data/lib/pdf_paradise/gui/README.md +6 -0
  29. data/lib/pdf_paradise/gui/fox/split_pdf_file.rb +77 -0
  30. 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
  31. data/lib/pdf_paradise/gui/gtk2/pdf_viewer/pdf_viewer.rb +34 -0
  32. data/lib/pdf_paradise/gui/gtk2/split_pdf_file/split_pdf_file.rb +34 -0
  33. data/lib/pdf_paradise/gui/gtk2/statistics_widget/statistics_widget.rb +34 -0
  34. data/lib/pdf_paradise/gui/gtk2/to_pdf/to_pdf.rb +32 -0
  35. data/lib/pdf_paradise/gui/gtk3/controller/controller.rb +212 -0
  36. data/lib/pdf_paradise/gui/gtk3/convert_pdf_to_text/convert_pdf_to_text.rb +34 -0
  37. 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
  38. data/lib/pdf_paradise/gui/gtk3/pdf_viewer/pdf_viewer.rb +34 -0
  39. data/lib/pdf_paradise/gui/gtk3/split_pdf_file/split_pdf_file.rb +34 -0
  40. data/lib/pdf_paradise/gui/gtk3/statistics_widget/statistics_widget.rb +34 -0
  41. data/lib/pdf_paradise/gui/gtk3/to_pdf/to_pdf.rb +32 -0
  42. data/lib/pdf_paradise/gui/libui/extract_all_images_from_this_pdf_file/extract_all_images_from_this_pdf_file.rb +223 -0
  43. data/lib/pdf_paradise/gui/libui/statistics_widget/statistics_widget.rb +233 -0
  44. data/lib/pdf_paradise/gui/shared_code/convert_pdf_to_text/convert_pdf_to_text_module.rb +277 -0
  45. data/lib/pdf_paradise/gui/shared_code/delete_the_first_or_the_last_page_of_this_pdf_file/delete_the_first_or_the_last_page_of_this_pdf_file_module.rb +443 -0
  46. data/lib/pdf_paradise/gui/shared_code/pdf_viewer/pdf_viewer.css +5 -0
  47. data/lib/pdf_paradise/gui/shared_code/pdf_viewer/pdf_viewer_module.rb +284 -0
  48. data/lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file.css +0 -0
  49. data/lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb +294 -0
  50. data/lib/pdf_paradise/gui/shared_code/statistics_widget/statistics_widget_module.rb +349 -0
  51. data/lib/pdf_paradise/gui/shared_code/to_pdf/to_pdf_module.rb +281 -0
  52. data/lib/pdf_paradise/hexapdf/001_rainbow_pattern_example.rb +0 -0
  53. data/lib/pdf_paradise/hexapdf/hexapdf.rb +123 -0
  54. data/lib/pdf_paradise/images/PDF_PARADISE_LOGO.png +0 -0
  55. data/lib/pdf_paradise/main_pdf/main_pdf.rb +444 -0
  56. data/lib/pdf_paradise/merge_pdf/menu.rb +63 -0
  57. data/lib/pdf_paradise/merge_pdf/merge_pdf.rb +306 -0
  58. data/lib/pdf_paradise/merge_pdf_namespace.rb +9 -0
  59. data/lib/pdf_paradise/merge_then_open/merge_then_open.rb +105 -0
  60. data/lib/pdf_paradise/pdf_file_n_total_pages.rb +249 -0
  61. data/lib/pdf_paradise/prawn_addons/README.md +2 -0
  62. data/lib/pdf_paradise/prawn_addons/prawn_addons.rb +17 -0
  63. data/lib/pdf_paradise/project/project.rb +22 -0
  64. data/lib/pdf_paradise/remove_pdf_password.rb +391 -0
  65. data/lib/pdf_paradise/requires/batch_require_toplevel_files.rb +22 -0
  66. data/lib/pdf_paradise/requires/colours.rb +7 -0
  67. data/lib/pdf_paradise/requires/colours_and_esystem_and_save_file_and_fileutils_and_opn.rb +11 -0
  68. data/lib/pdf_paradise/requires/esystem_and_colours.rb +10 -0
  69. data/lib/pdf_paradise/requires/esystem_and_opn_and_colours.rb +8 -0
  70. data/lib/pdf_paradise/requires/require_the_whole_project.rb +28 -0
  71. data/lib/pdf_paradise/requires/require_utility_scripts.rb +9 -0
  72. data/lib/pdf_paradise/set_main_book.rb +156 -0
  73. data/lib/pdf_paradise/set_pdf_title.rb +220 -0
  74. data/lib/pdf_paradise/sinatra/embeddable_interface.rb +318 -0
  75. data/lib/pdf_paradise/toplevel_methods/automatic_pdf_title.rb +55 -0
  76. data/lib/pdf_paradise/toplevel_methods/convert_epub_to_pdf.rb +27 -0
  77. data/lib/pdf_paradise/toplevel_methods/convert_markdown_to_pdf.rb +45 -0
  78. data/lib/pdf_paradise/toplevel_methods/convert_ppt_to_pdf.rb +35 -0
  79. data/lib/pdf_paradise/toplevel_methods/e.rb +16 -0
  80. data/lib/pdf_paradise/toplevel_methods/esystem.rb +19 -0
  81. data/lib/pdf_paradise/toplevel_methods/misc.rb +76 -0
  82. data/lib/pdf_paradise/toplevel_methods/number_pages.rb +38 -0
  83. data/lib/pdf_paradise/toplevel_methods/opened_pdf_files.rb +221 -0
  84. data/lib/pdf_paradise/toplevel_methods/query_pdf_title.rb +191 -0
  85. data/lib/pdf_paradise/toplevel_methods/reduce_size_of_this_pdf_file.rb +46 -0
  86. data/lib/pdf_paradise/toplevel_methods/roebe.rb +17 -0
  87. data/lib/pdf_paradise/toplevel_methods/rotate_pdf_file.rb +143 -0
  88. data/lib/pdf_paradise/toplevel_methods/to_pdf.rb +38 -0
  89. data/lib/pdf_paradise/utility_scripts/README.md +3 -0
  90. data/lib/pdf_paradise/utility_scripts/combine_these_pdf_pages.rb +118 -0
  91. data/lib/pdf_paradise/utility_scripts/convert_pdf_to_text.rb +175 -0
  92. data/lib/pdf_paradise/utility_scripts/delete_first_page_of_this_pdf_file.rb +221 -0
  93. data/lib/pdf_paradise/utility_scripts/delete_last_page_of_this_pdf_file.rb +180 -0
  94. data/lib/pdf_paradise/utility_scripts/delete_this_page_of_this_pdf_file.rb +329 -0
  95. data/lib/pdf_paradise/utility_scripts/extract_all_images_from_this_pdf_file.rb +129 -0
  96. data/lib/pdf_paradise/utility_scripts/extract_pdf_page.rb +283 -0
  97. data/lib/pdf_paradise/utility_scripts/pdf_optimizer.rb +111 -0
  98. data/lib/pdf_paradise/utility_scripts/pdf_statistics.rb +148 -0
  99. data/lib/pdf_paradise/utility_scripts/pdf_to_html.rb +75 -0
  100. data/lib/pdf_paradise/utility_scripts/remove_images.rb +110 -0
  101. data/lib/pdf_paradise/utility_scripts/split_pdf.rb +340 -0
  102. data/lib/pdf_paradise/utility_scripts/to_qdf.rb +82 -0
  103. data/lib/pdf_paradise/version/version.rb +19 -0
  104. data/lib/pdf_paradise/www/README.md +2 -0
  105. data/lib/pdf_paradise/www/sinatra/app.rb +276 -0
  106. data/lib/pdf_paradise/yaml/working_on_these_pdf_files.yml +4 -0
  107. data/lib/pdf_paradise.rb +5 -0
  108. data/pdf_paradise.gemspec +61 -0
  109. data/test/testing_pdf_paradise.rb +9 -0
  110. metadata +219 -0
@@ -0,0 +1,349 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === PdfParadise::GUI::Gtk::StatisticsWidgetModule
6
+ # =========================================================================== #
7
+ # require 'pdf_paradise/gui/shared_code/statistics_widget/statistics_widget_module.rb'
8
+ # include ::PdfParadise::GUI::Gtk::StatisticsWidgetModule
9
+ # =========================================================================== #
10
+ module PdfParadise
11
+
12
+ module GUI
13
+
14
+ module Gtk
15
+
16
+ module StatisticsWidgetModule
17
+
18
+ require 'gtk_paradise/requires/require_the_base_module.rb'
19
+ include ::Gtk::BaseModule
20
+
21
+ require 'pdf_paradise/pdf_file_n_total_pages.rb'
22
+ require 'pdf_paradise/toplevel_methods/automatic_pdf_title.rb'
23
+ require 'pdf_paradise/toplevel_methods/query_pdf_title.rb'
24
+
25
+ # ========================================================================= #
26
+ # === NAMESPACE
27
+ # ========================================================================= #
28
+ NAMESPACE = inspect
29
+
30
+ # ========================================================================= #
31
+ # === TITLE
32
+ # ========================================================================= #
33
+ TITLE = 'Show statistics about the .pdf file at hand'
34
+
35
+ # ========================================================================= #
36
+ # === FONT_SIZE
37
+ # ========================================================================= #
38
+ FONT_SIZE = 18
39
+
40
+ # ========================================================================= #
41
+ # === USE_THIS_FONT
42
+ # ========================================================================= #
43
+ USE_THIS_FONT = "Liberation serif #{FONT_SIZE}"
44
+
45
+ # ========================================================================= #
46
+ # === USE_THIS_FONT_FOR_THE_DISPLAY_AREA
47
+ # ========================================================================= #
48
+ USE_THIS_FONT_FOR_THE_DISPLAY_AREA = 'DejaVu Sans Mono 18' # :hack_18
49
+
50
+ # ========================================================================= #
51
+ # === WIDTH
52
+ # ========================================================================= #
53
+ WIDTH = 1820
54
+
55
+ # ========================================================================= #
56
+ # === HEIGHT
57
+ # ========================================================================= #
58
+ HEIGHT = 840
59
+
60
+ # ========================================================================= #
61
+ # === initialize
62
+ #
63
+ # The first argument is assumed to be the parent-widget.
64
+ # ========================================================================= #
65
+ def initialize(
66
+ commandline_arguments = nil,
67
+ run_already = true
68
+ )
69
+ super(:vertical) # Vertical box in style.
70
+ reset
71
+ set_commandline_arguments(
72
+ commandline_arguments
73
+ )
74
+ run if run_already
75
+ end
76
+
77
+ # ========================================================================= #
78
+ # === reset (reset tag)
79
+ # ========================================================================= #
80
+ def reset
81
+ abort_on_exception
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
+ set_width(WIDTH)
95
+ set_height(HEIGHT)
96
+ set_use_this_font(USE_THIS_FONT)
97
+ use_gtk_paradise_project_css_file
98
+ end
99
+
100
+ # ========================================================================= #
101
+ # === padding?
102
+ # ========================================================================= #
103
+ def padding?
104
+ 0
105
+ end
106
+
107
+ # ========================================================================= #
108
+ # === parent_widget?
109
+ # ========================================================================= #
110
+ def parent_widget?
111
+ @commandline_arguments.first
112
+ end
113
+
114
+ # ========================================================================= #
115
+ # === main_entry?
116
+ # ========================================================================= #
117
+ def main_entry?
118
+ @gtk_entry
119
+ end
120
+
121
+ # ========================================================================= #
122
+ # === create_the_buttons (buttons tag, button tag)
123
+ # ========================================================================= #
124
+ def create_the_buttons
125
+ # ======================================================================= #
126
+ # === @button_choose_file
127
+ # ======================================================================= #
128
+ @button_choose_file = gtk_file_chooser_button
129
+ @button_choose_file.hint = 'Click on this button to open a '\
130
+ 'local <b>.pdf</b> file.'
131
+ @button_choose_file.lightgreen
132
+ @button_choose_file.on_clicked {
133
+ do_create_a_new_file_chooser_dialog_and_then_set_the_main_entry_to(main_file?)
134
+ }
135
+ # ======================================================================= #
136
+ # === @button_analyse
137
+ # ======================================================================= #
138
+ @button_analyse = gtk_button('_Analyse the .pdf file')
139
+ @button_analyse.lightgreen
140
+ @button_analyse.hint =
141
+ 'Click this button to obtain some information about '\
142
+ 'the .pdf file at hand.'
143
+ @button_analyse.on_clicked {
144
+ do_analyse_the_pdf_file
145
+ }
146
+ # ======================================================================= #
147
+ # === @button_auto_title
148
+ # ======================================================================= #
149
+ @button_auto_title = gtk_button('Automatic Title')
150
+ @button_auto_title.hint = 'Click on this button to automatically '\
151
+ 'determine the title for this .pdf file, based on the filename.'
152
+ @button_auto_title.on_clicked {
153
+ do_automatically_determine_the_title_for_the_pdf_file_at_hand
154
+ }
155
+ # ======================================================================= #
156
+ # === @button_open_via_a_pdf_reader
157
+ # ======================================================================= #
158
+ @button_open_via_a_pdf_reader = gtk_button('Open via a pdf-reader')
159
+ @button_open_via_a_pdf_reader.hint = 'This will open the .pdf '\
160
+ 'file in a pdf-reader.'
161
+ @button_open_via_a_pdf_reader.on_clicked {
162
+ do_open_the_local_pdf_file_in_the_pdf_reader
163
+ }
164
+ return_all_buttons.each {|this_button|
165
+ this_button.bblack1
166
+ }
167
+ @button_auto_title.bblack3
168
+ end
169
+
170
+ # ========================================================================= #
171
+ # === create_skeleton (create tag)
172
+ # ========================================================================= #
173
+ def create_skeleton
174
+ create_the_entries
175
+ create_the_buttons
176
+ # ======================================================================= #
177
+ # === @label
178
+ #
179
+ # This label-widget resides on the bottom of the application.
180
+ # ======================================================================= #
181
+ @label = gtk_left_aligned_label
182
+ @label.set_font(USE_THIS_FONT_FOR_THE_DISPLAY_AREA)
183
+
184
+ @label.make_selectable
185
+ @hbox_containing_the_entry = gtk_hbox
186
+
187
+ @arrow_right = emoji(:arrow_right)
188
+ @event_box_arrow_right = gtk_eventbox(@arrow_right)
189
+ @event_box_arrow_right.on_clicked {
190
+ do_create_a_new_file_chooser_dialog_and_then_set_the_main_entry_to(main_file?)
191
+ }
192
+ @hbox_containing_the_entry.minimal(
193
+ @event_box_arrow_right
194
+ )
195
+ @hbox_containing_the_entry.maximal(@gtk_entry)
196
+ end
197
+
198
+ # ========================================================================= #
199
+ # === do_create_a_new_file_chooser_dialog_and_then_set_the_main_entry_to
200
+ # ========================================================================= #
201
+ def do_create_a_new_file_chooser_dialog_and_then_set_the_main_entry_to(
202
+ i = main_file?.to_s
203
+ )
204
+ create_a_new_file_chooser_dialog(parent_widget?) {{
205
+ filter: '.pdf',
206
+ additional_folders: '/Depot/j/',
207
+ start_directory: '/Depot/'
208
+ }}
209
+ _ = assigned_main_file?.to_s
210
+ if _ and !_.empty?
211
+ main_entry?.set_text(_)
212
+ do_analyse_the_pdf_file
213
+ end
214
+ end
215
+
216
+ # ========================================================================= #
217
+ # === run (run tag)
218
+ # ========================================================================= #
219
+ def run
220
+ create_skeleton_then_connect_skeleton
221
+ show_all
222
+ Thread.new {
223
+ sleep 0.001
224
+ main_entry?.do_focus
225
+ }
226
+ end
227
+
228
+ # ========================================================================= #
229
+ # === do_analyse_the_pdf_file
230
+ #
231
+ # This is the method that will analyse the .pdf file at hand.
232
+ # ========================================================================= #
233
+ def do_analyse_the_pdf_file
234
+ this_pdf_file = main_entry?.text.to_s
235
+ _ = ''.dup
236
+ _ << "This .pdf file has the following characteristics:\n\n"
237
+ _ << ' <b>n pages</b>: '+::PdfParadise.n_pages?(this_pdf_file).to_s
238
+ _ << "\n"
239
+ use_this_title = ::PdfParadise.title?(this_pdf_file).to_s
240
+ if use_this_title.empty?
241
+ use_this_title = '(This .pdf file has no title)'
242
+ end
243
+ _ << " <b>title</b>: #{use_this_title}"
244
+ _ << "\n"
245
+ @label.set_text(_)
246
+ @label.do_markify
247
+ end
248
+
249
+ # ========================================================================= #
250
+ # === do_automatically_determine_the_title_for_the_pdf_file_at_hand
251
+ # ========================================================================= #
252
+ def do_automatically_determine_the_title_for_the_pdf_file_at_hand
253
+ this_pdf_file = main_entry?.text.to_s
254
+ if this_pdf_file and !this_pdf_file.empty?
255
+ ::PdfParadise.automatic_pdf_title(this_pdf_file)
256
+ do_analyse_the_pdf_file
257
+ else
258
+ popup_over_this_widget(
259
+ main_entry?,
260
+ 'Please first assign a .pdf file, before '\
261
+ 'this functionality can be used.'
262
+ )
263
+ end
264
+ end
265
+
266
+ # ========================================================================= #
267
+ # === do_open_the_local_pdf_file_in_the_pdf_reader
268
+ # ========================================================================= #
269
+ def do_open_the_local_pdf_file_in_the_pdf_reader
270
+ this_pdf_file = main_entry?.text.to_s
271
+ if this_pdf_file and !this_pdf_file.empty?
272
+ Thread.new {
273
+ esystem("evince #{this_pdf_file}")
274
+ }
275
+ else
276
+ popup_over_this_widget(
277
+ main_entry?,
278
+ 'Please first assign a .pdf file, before '\
279
+ 'this functionality can be used.'
280
+ )
281
+ end
282
+ end
283
+
284
+ # ========================================================================= #
285
+ # === connect_skeleton (connect skeleton, connect tag)
286
+ # ========================================================================= #
287
+ def connect_skeleton
288
+ _ = top_bar
289
+ _.add(@button_auto_title)
290
+ _.add(@button_open_via_a_pdf_reader)
291
+ minimal(_)
292
+ minimal(
293
+ gtk_left_aligned_label(
294
+ 'This small widget will show some information about '\
295
+ 'the .pdf file at hand.'
296
+ ), 8
297
+ )
298
+ minimal(@hbox_containing_the_entry, 8)
299
+ button_box = gtk_button_box(
300
+ @button_choose_file,
301
+ @button_analyse
302
+ ) {{ layout: :horizontal,
303
+ padding: 2 }}
304
+ button_box.spacing = 2
305
+ button_box.layout = :expand
306
+ minimal(button_box, 4)
307
+ minimal(@label, 4)
308
+ end
309
+
310
+ # ========================================================================= #
311
+ # === create_the_entries
312
+ # ========================================================================= #
313
+ def create_the_entries
314
+ # ======================================================================= #
315
+ # === @gtk_entry
316
+ # ======================================================================= #
317
+ @gtk_entry = gtk_entry
318
+ @gtk_entry.yellow_background
319
+ @gtk_entry.bblack1
320
+ @gtk_entry.css_class('pad4px')
321
+ @gtk_entry.enable_all_events
322
+ @gtk_entry.on_the_enter_key_was_pressed {
323
+ do_analyse_the_pdf_file
324
+ }
325
+ end
326
+
327
+ end; end; end
328
+
329
+ # =========================================================================== #
330
+ # === PdfParadise.start_gtk_gui_statistics_widget
331
+ # =========================================================================== #
332
+ def self.start_gtk_gui_statistics_widget
333
+ require 'gtk_paradise/run'
334
+ r = ::Gtk.run
335
+ _ = PdfParadise::GUI::Gtk::StatisticsWidget.new(r)
336
+ r << _
337
+ r.automatic_size
338
+ r.automatic_title
339
+ r.top_left_then_run
340
+ end
341
+
342
+ # =========================================================================== #
343
+ # === PdfParadise.return_widget_about_this_pdf_file
344
+ # =========================================================================== #
345
+ def self.return_widget_about_this_pdf_file
346
+ ::PdfParadise::GUI::Gtk::StatisticsWidget.new
347
+ end
348
+
349
+ end
@@ -0,0 +1,281 @@
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
+ set_width(WIDTH)
83
+ # ======================================================================= #
84
+ # === @height
85
+ # ======================================================================= #
86
+ set_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
+ # === run
109
+ # ========================================================================= #
110
+ def run
111
+ create_skeleton
112
+ chdir('/Depot/j/') if File.directory? '/Depot/j/'
113
+ vbox = gtk_vbox
114
+ vbox.minimal(
115
+ gtk_label('Input the filename that you wish to convert here:'), 1
116
+ )
117
+ create_the_entry_filename
118
+ vbox.minimal(@entry_filename, 1)
119
+ minimal(vbox, 1)
120
+ pack_without_expand(@button_choose_file, 1)
121
+ pack_without_expand(@button_do_convert, 1)
122
+ hbox = gtk_hbox
123
+ hbox.maximal(@statusbar, 1)
124
+ hbox.minimal(@button_open_the_converted_file, 1)
125
+ add(hbox)
126
+ @text_buffer = gtk_text_buffer
127
+ @text_view = gtk_text_view(@text_buffer)
128
+ @scrolled_window = gtk_scrolled_window(@text_view) { :top_to_bottom }
129
+ @scrolled_window.bblack1
130
+ @scrolled_window.css_class('pad4px')
131
+ @scrolled_window.width_height(500, 400)
132
+ minimal(@scrolled_window)
133
+ do_style_all_buttons_in_a_uniform_manner
134
+ end
135
+
136
+ # ========================================================================= #
137
+ # === do_style_all_buttons_in_a_uniform_manner
138
+ # ========================================================================= #
139
+ def do_style_all_buttons_in_a_uniform_manner
140
+ return_all_buttons.each {|entry|
141
+ entry.bblack1
142
+ entry.css_class('pad2px')
143
+ }
144
+ end
145
+
146
+ # ========================================================================= #
147
+ # === padding?
148
+ # ========================================================================= #
149
+ def padding?
150
+ 0
151
+ end
152
+
153
+ # ========================================================================= #
154
+ # === favicon?
155
+ # ========================================================================= #
156
+ def favicon?
157
+ :tabble
158
+ end
159
+
160
+ # ========================================================================= #
161
+ # === do_open_the_converted_file_via_a_pdf_reader
162
+ # ========================================================================= #
163
+ def do_open_the_converted_file_via_a_pdf_reader
164
+ stored_here = stored_where?
165
+ if File.exist? stored_here
166
+ system 'evince '+stored_here
167
+ else
168
+ e 'No file exists at '+sfile(stored_here)+'.'
169
+ end
170
+ end
171
+
172
+ # ========================================================================= #
173
+ # === stored_where?
174
+ # ========================================================================= #
175
+ def stored_where?(
176
+ i = @entry_filename.text?
177
+ )
178
+ _ = PdfParadise.to_pdf(i)
179
+ _ = _.dup
180
+ _ = _.join(' ').strip if _.is_a? Array
181
+ _.delete_suffix!(File.extname(i))
182
+ _ << '.pdf' unless _.end_with? '.pdf'
183
+ return _.to_s
184
+ end
185
+
186
+ # ========================================================================= #
187
+ # === do_convert_the_given_file
188
+ #
189
+ # This is the method that will convert the target file into the
190
+ # .pdf file, usually by using "soffice".
191
+ # ========================================================================= #
192
+ def do_convert_the_given_file
193
+ _ = stored_where?
194
+ @statusbar.display(
195
+ 'Stored the file at: '+_, :default, @status_bar_context_id
196
+ ) if File.exist? _
197
+ # ======================================================================= #
198
+ # Read in the .pdf file if it exists and if the PDF::Reader namespace
199
+ # exists.
200
+ # ======================================================================= #
201
+ if File.exist?(_) and
202
+ Object.const_defined?(:PDF) and PDF.const_defined?(:Reader)
203
+ reader = PDF::Reader.new(_)
204
+ page = reader.page(1)
205
+ use_this_text = page.text.to_s
206
+ @scrolled_window.set_text(use_this_text.to_s)
207
+ end
208
+ end
209
+
210
+ # ========================================================================= #
211
+ # === PdfParadise::GUI::Gtk::ToPdfModule.run
212
+ # ========================================================================= #
213
+ def self.run(i = ARGV)
214
+ require 'gtk_paradise/run'
215
+ r = ::Gtk.run
216
+ _ = PdfParadise::GUI::Gtk::ToPdf.new(r)
217
+ r << _
218
+ r.automatic
219
+ r.easy_exit_top_left_then_run
220
+ end
221
+
222
+ # ========================================================================= #
223
+ # === entry_filename?
224
+ # ========================================================================= #
225
+ def entry_filename?
226
+ @entry_filename
227
+ end; alias main_entry? entry_filename? # === main_entry?
228
+
229
+ # ========================================================================= #
230
+ # === create_the_entry_filename
231
+ # ========================================================================= #
232
+ def create_the_entry_filename
233
+ @entry_filename = gtk_entry
234
+ @entry_filename.clear_background
235
+ @entry_filename.bblack1
236
+ @entry_filename.yellow_background
237
+ end
238
+
239
+ # ========================================================================= #
240
+ # === create_buttons (buttons tag, button tag)
241
+ # ========================================================================= #
242
+ def create_buttons
243
+ # ======================================================================= #
244
+ # === @button_do_convert
245
+ # ======================================================================= #
246
+ @button_do_convert = gtk_button('_Convert it to .pdf format')
247
+ #@button_do_convert.disallow_resizing
248
+ @button_do_convert.css_class('clear_background')
249
+ @button_do_convert.steelblue
250
+ @button_do_convert.css_class('BG_lightblue')
251
+ @button_do_convert.hint = 'This will use libreoffice '\
252
+ 'to convert the file at hand into a <b>.pdf file</b>.'
253
+ @button_do_convert.on_clicked {
254
+ do_convert_the_given_file
255
+ }
256
+ # ======================================================================= #
257
+ # === @button_choose_file (open tag)
258
+ #
259
+ # This is the "Open File" button.
260
+ # ======================================================================= #
261
+ @button_choose_file = gtk_file_chooser_button
262
+ @button_choose_file.on_clicked {
263
+ create_a_new_file_chooser_dialog
264
+ main_entry?.set_text(main_file?.to_s)
265
+ }
266
+ # ======================================================================= #
267
+ # === @button_open_the_converted_file
268
+ # ======================================================================= #
269
+ @button_open_the_converted_file = gtk_button('_Open the converted file')
270
+ @button_open_the_converted_file.hint = 'Click to open the '\
271
+ 'converted file via main .pdf reader.'
272
+ @button_open_the_converted_file.on_clicked {
273
+ do_open_the_converted_file_via_a_pdf_reader
274
+ }
275
+ end
276
+
277
+ end; end; end; end
278
+
279
+ if __FILE__ == $PROGRAM_NAME
280
+ PdfParadise::GUI::Gtk::ToPdfModule.run
281
+ end