pdf_paradise 0.3.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +933 -0
  3. data/bin/automatic_pdf_title +7 -0
  4. data/bin/burst_this_pdf_file +7 -0
  5. data/bin/combine_these_pdf_pages +7 -0
  6. data/bin/compress_via_hexapdf +7 -0
  7. data/bin/convert_markdown_to_pdf +7 -0
  8. data/bin/convert_pdf_to_text +7 -0
  9. data/bin/delete_first_page_of_this_pdf_file +7 -0
  10. data/bin/djvu_to_pdf +7 -0
  11. data/bin/merge_then_open +7 -0
  12. data/bin/n_pages +10 -0
  13. data/bin/open_main_pdf +7 -0
  14. data/bin/pdf_paradise +9 -0
  15. data/bin/rotate_pdf +7 -0
  16. data/bin/set_main_book +7 -0
  17. data/bin/set_title_of_this_pdf_file +15 -0
  18. data/doc/README.gen +871 -0
  19. data/doc/todo/todo.md +13 -0
  20. data/images/Logo_for_the_pdf_paradise_project.avif +0 -0
  21. data/lib/pdf_paradise/base/base.rb +344 -0
  22. data/lib/pdf_paradise/base/colours.rb +67 -0
  23. data/lib/pdf_paradise/colours/colours.rb +27 -0
  24. data/lib/pdf_paradise/commandline/commandline.rb +109 -0
  25. data/lib/pdf_paradise/commandline/help.rb +77 -0
  26. data/lib/pdf_paradise/commandline/menu.rb +173 -0
  27. data/lib/pdf_paradise/compress/compress_this_pdf_file.rb +108 -0
  28. data/lib/pdf_paradise/compress/compress_via_hexapdf.rb +27 -0
  29. data/lib/pdf_paradise/compress/compress_via_qpdf.rb +32 -0
  30. data/lib/pdf_paradise/constants/constants.rb +76 -0
  31. data/lib/pdf_paradise/convert_text_to_pdf.rb +94 -0
  32. data/lib/pdf_paradise/css/project.css +17 -0
  33. data/lib/pdf_paradise/fpdf/README.md +2 -0
  34. data/lib/pdf_paradise/fpdf/bookmark.rb +129 -0
  35. data/lib/pdf_paradise/fpdf/chinese.rb +454 -0
  36. data/lib/pdf_paradise/fpdf/fpdf.rb +1902 -0
  37. data/lib/pdf_paradise/fpdf/fpdf_eps.rb +138 -0
  38. data/lib/pdf_paradise/fpdf/makefont.rb +1794 -0
  39. data/lib/pdf_paradise/gui/README.md +6 -0
  40. data/lib/pdf_paradise/gui/fox/split_pdf_file.rb +77 -0
  41. data/lib/pdf_paradise/gui/gtk2/pdf_viewer/pdf_viewer.rb +34 -0
  42. data/lib/pdf_paradise/gui/gtk2/split_pdf_file/split_pdf_file.rb +34 -0
  43. data/lib/pdf_paradise/gui/gtk2/statistics_widget/statistics_widget.rb +34 -0
  44. data/lib/pdf_paradise/gui/gtk3/controller/controller.rb +214 -0
  45. data/lib/pdf_paradise/gui/gtk3/pdf_viewer/pdf_viewer.rb +34 -0
  46. data/lib/pdf_paradise/gui/gtk3/split_pdf_file/split_pdf_file.rb +34 -0
  47. data/lib/pdf_paradise/gui/jruby/delete_the_first_or_the_last_page_of_this_pdf_file/delete_the_first_or_the_last_page_of_this_pdf_file.rb +167 -0
  48. data/lib/pdf_paradise/gui/jruby/remove_the_first_page_of_this_pdf_file/remove_the_first_page_of_this_pdf_file.rb +103 -0
  49. data/lib/pdf_paradise/gui/libui/extract_all_images_from_this_pdf_file/extract_all_images_from_this_pdf_file.rb +223 -0
  50. data/lib/pdf_paradise/gui/libui/remove_the_first_page_of_this_pdf_file/remove_the_first_page_of_this_pdf_file.rb +267 -0
  51. data/lib/pdf_paradise/gui/libui/rotate_pdf_file/rotate_pdf_file.rb +219 -0
  52. data/lib/pdf_paradise/gui/libui/statistics_widget/statistics_widget.rb +233 -0
  53. data/lib/pdf_paradise/gui/shared_code/pdf_viewer/pdf_viewer.css +5 -0
  54. data/lib/pdf_paradise/gui/shared_code/pdf_viewer/pdf_viewer_module.rb +287 -0
  55. data/lib/pdf_paradise/gui/shared_code/remove_the_first_page_of_this_pdf_file_module/remove_the_first_page_of_this_pdf_file_module.rb +31 -0
  56. data/lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb +295 -0
  57. data/lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb +366 -0
  58. data/lib/pdf_paradise/gui/universal_widgets/delete_the_first_or_the_last_page_of_this_pdf_file/delete_the_first_or_the_last_page_of_this_pdf_file.rb +776 -0
  59. data/lib/pdf_paradise/gui/universal_widgets/statistics_widget/statistics_widget.rb +407 -0
  60. data/lib/pdf_paradise/gui/universal_widgets/to_pdf/to_pdf.rb +351 -0
  61. data/lib/pdf_paradise/hexapdf/001_rainbow_pattern_example.rb +0 -0
  62. data/lib/pdf_paradise/hexapdf/hexapdf.rb +123 -0
  63. data/lib/pdf_paradise/images/PDF_PARADISE_LOGO.png +0 -0
  64. data/lib/pdf_paradise/main_pdf/main_pdf.rb +474 -0
  65. data/lib/pdf_paradise/merge_pdf/menu.rb +63 -0
  66. data/lib/pdf_paradise/merge_pdf/merge_pdf.rb +307 -0
  67. data/lib/pdf_paradise/merge_pdf_namespace.rb +9 -0
  68. data/lib/pdf_paradise/merge_then_open/merge_then_open.rb +105 -0
  69. data/lib/pdf_paradise/prawn_addons/README.md +2 -0
  70. data/lib/pdf_paradise/prawn_addons/prawn_addons.rb +17 -0
  71. data/lib/pdf_paradise/project/project.rb +22 -0
  72. data/lib/pdf_paradise/remove_pdf_password.rb +391 -0
  73. data/lib/pdf_paradise/requires/batch_require_toplevel_files.rb +22 -0
  74. data/lib/pdf_paradise/requires/colours.rb +11 -0
  75. data/lib/pdf_paradise/requires/colours_and_esystem_and_save_file_and_fileutils_and_opn.rb +13 -0
  76. data/lib/pdf_paradise/requires/esystem_and_colours.rb +11 -0
  77. data/lib/pdf_paradise/requires/esystem_and_opn_and_colours.rb +10 -0
  78. data/lib/pdf_paradise/requires/require_the_whole_project.rb +30 -0
  79. data/lib/pdf_paradise/requires/require_utility_scripts.rb +9 -0
  80. data/lib/pdf_paradise/set_main_book.rb +156 -0
  81. data/lib/pdf_paradise/set_pdf_title.rb +220 -0
  82. data/lib/pdf_paradise/sinatra/embeddable_interface.rb +389 -0
  83. data/lib/pdf_paradise/toplevel_methods/convert_epub_to_pdf.rb +27 -0
  84. data/lib/pdf_paradise/toplevel_methods/convert_markdown_to_pdf.rb +45 -0
  85. data/lib/pdf_paradise/toplevel_methods/convert_ppt_to_pdf.rb +35 -0
  86. data/lib/pdf_paradise/toplevel_methods/e.rb +16 -0
  87. data/lib/pdf_paradise/toplevel_methods/esystem.rb +20 -0
  88. data/lib/pdf_paradise/toplevel_methods/misc.rb +228 -0
  89. data/lib/pdf_paradise/toplevel_methods/number_pages.rb +38 -0
  90. data/lib/pdf_paradise/toplevel_methods/opened_pdf_files.rb +221 -0
  91. data/lib/pdf_paradise/toplevel_methods/query_pdf_title.rb +201 -0
  92. data/lib/pdf_paradise/toplevel_methods/reduce_size_of_this_pdf_file.rb +46 -0
  93. data/lib/pdf_paradise/toplevel_methods/roebe.rb +17 -0
  94. data/lib/pdf_paradise/toplevel_methods/to_pdf.rb +12 -0
  95. data/lib/pdf_paradise/utility_scripts/README.md +3 -0
  96. data/lib/pdf_paradise/utility_scripts/automatic_pdf_title.rb +104 -0
  97. data/lib/pdf_paradise/utility_scripts/check_syntax_of_pdf_files.rb +106 -0
  98. data/lib/pdf_paradise/utility_scripts/combine_these_pdf_pages.rb +118 -0
  99. data/lib/pdf_paradise/utility_scripts/convert_pdf_to_text.rb +179 -0
  100. data/lib/pdf_paradise/utility_scripts/delete_last_page_of_this_pdf_file.rb +180 -0
  101. data/lib/pdf_paradise/utility_scripts/delete_the_first_page_of_this_pdf_file/delete_the_first_page_of_this_pdf_file.rb +429 -0
  102. data/lib/pdf_paradise/utility_scripts/delete_this_page_of_this_pdf_file.rb +356 -0
  103. data/lib/pdf_paradise/utility_scripts/djvu_to_pdf.rb +87 -0
  104. data/lib/pdf_paradise/utility_scripts/extract_all_images_from_this_pdf_file.rb +129 -0
  105. data/lib/pdf_paradise/utility_scripts/extract_pdf_page.rb +283 -0
  106. data/lib/pdf_paradise/utility_scripts/pdf_file_n_total_pages.rb +348 -0
  107. data/lib/pdf_paradise/utility_scripts/pdf_optimizer.rb +111 -0
  108. data/lib/pdf_paradise/utility_scripts/pdf_statistics.rb +148 -0
  109. data/lib/pdf_paradise/utility_scripts/pdf_to_html.rb +75 -0
  110. data/lib/pdf_paradise/utility_scripts/remove_images.rb +110 -0
  111. data/lib/pdf_paradise/utility_scripts/rotate_pdf_file.rb +303 -0
  112. data/lib/pdf_paradise/utility_scripts/split_pdf.rb +364 -0
  113. data/lib/pdf_paradise/utility_scripts/to_pdf.rb +130 -0
  114. data/lib/pdf_paradise/utility_scripts/to_qdf.rb +66 -0
  115. data/lib/pdf_paradise/version/version.rb +19 -0
  116. data/lib/pdf_paradise/www/README.md +2 -0
  117. data/lib/pdf_paradise/www/sinatra/app.rb +304 -0
  118. data/lib/pdf_paradise/yaml/working_on_these_pdf_files.yml +4 -0
  119. data/lib/pdf_paradise.rb +5 -0
  120. data/pdf_paradise.gemspec +61 -0
  121. data/test/fpdf/001_minimal_example.rb +12 -0
  122. data/test/fpdf/002.pdf +0 -0
  123. data/test/fpdf/002_header_and_footer_example.rb +64 -0
  124. data/test/fpdf/003.pdf +98 -0
  125. data/test/fpdf/003_justified_paragraphs.rb +96 -0
  126. data/test/fpdf/file1.md +3 -0
  127. data/test/fpdf/file2.md +3 -0
  128. data/test/fpdf/test.pdf +0 -0
  129. data/test/testing_pdf_paradise.rb +12 -0
  130. metadata +239 -0
@@ -0,0 +1,287 @@
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
+ set_width(WIDTH)
80
+ # ======================================================================= #
81
+ # === @height
82
+ # ======================================================================= #
83
+ set_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
+ begin
228
+ require 'gtk_paradise/toplevel_methods/toplevel_methods.rb'
229
+ rescue LoadError; end
230
+ filename = ::Gtk.select_file(@parent_widget) {{
231
+ current_folder: '/Depot/j/',
232
+ show_hidden: true,
233
+ add_these_shortcut_folders: ['/Depot/j/'],
234
+ use_this_file_filter: '*.pdf'
235
+ }}
236
+ if File.exist? filename
237
+ set_this_as_the_active_pdf_file_then_trigger_the_conversion(filename)
238
+ end
239
+ end
240
+
241
+ # ========================================================================= #
242
+ # === set_this_as_the_active_pdf_file_then_trigger_the_conversion
243
+ # ========================================================================= #
244
+ def set_this_as_the_active_pdf_file_then_trigger_the_conversion(
245
+ filename
246
+ )
247
+ set_this_as_the_active_pdf_file(filename)
248
+ trigger_the_conversion
249
+ end
250
+
251
+ # ========================================================================= #
252
+ # === run
253
+ # ========================================================================= #
254
+ def run
255
+ create_skeleton_then_connect_skeleton
256
+ menu
257
+ end
258
+
259
+ # ========================================================================= #
260
+ # === menu (menu tag)
261
+ # ========================================================================= #
262
+ def menu(
263
+ i = commandline_arguments?
264
+ )
265
+ if i.is_a? Array
266
+ i.each {|entry| menu(entry) }
267
+ else
268
+ if File.exist? i
269
+ set_this_as_the_active_pdf_file_then_trigger_the_conversion(i)
270
+ end
271
+ end
272
+ end
273
+
274
+ # ========================================================================= #
275
+ # === PdfParadise::GUI::Gtk::PdfViewerModule.run
276
+ # ========================================================================= #
277
+ def self.run
278
+ require 'gtk_paradise/run'
279
+ _ = ::PdfParadise::GUI::Gtk::PdfViewer.new
280
+ r = ::Gtk.run
281
+ _.set_parent_widget(r)
282
+ r << _
283
+ r.automatic_title_and_size
284
+ r.top_left_then_run
285
+ end
286
+
287
+ end; end; end; end
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === PdfParadise::GUI::RemoveTheFirstPageOfThisPdfFileModule
6
+ # =========================================================================== #
7
+ # require 'pdf_paradise/gui/shared_code/remove_the_first_page_of_this_pdf_file_module/remove_the_first_page_of_this_pdf_file_module.rb'
8
+ # include PdfParadise::GUI::RemoveTheFirstPageOfThisPdfFileModule
9
+ # =========================================================================== #
10
+ module PdfParadise
11
+
12
+ module GUI
13
+
14
+ module RemoveTheFirstPageOfThisPdfFileModule # === PdfParadise::GUI::RemoveTheFirstPageOfThisPdfFileModule
15
+
16
+ # ========================================================================= #
17
+ # === PdfParadise::GUI::RemoveTheFirstPageOfThisPdfFileModule::TITLE
18
+ # ========================================================================= #
19
+ TITLE = 'Remove the first page of this .pdf file'
20
+
21
+ # ========================================================================= #
22
+ # === WIDTH
23
+ # ========================================================================= #
24
+ WIDTH = 1400
25
+
26
+ # ========================================================================= #
27
+ # === HEIGHT
28
+ # ========================================================================= #
29
+ HEIGHT = 800
30
+
31
+ end; end; end
@@ -0,0 +1,295 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === PdfParadise::GUI::Gtk::SplitPdfFileModule
6
+ #
7
+ # This is a simple gtk-GUI wrapper over the split-pdf functionality
8
+ # of the PdfParadise project. The main box is a VBox (vertical box).
9
+ # =========================================================================== #
10
+ # require 'pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb'
11
+ # include ::PdfParadise::GUI::Gtk::SplitPdfFileModule
12
+ # =========================================================================== #
13
+ module PdfParadise
14
+
15
+ module GUI
16
+
17
+ module Gtk
18
+
19
+ module SplitPdfFileModule
20
+
21
+ require 'gtk_paradise/requires/require_the_base_module.rb'
22
+ include ::Gtk::BaseModule
23
+
24
+ require 'pdf_paradise/utility_scripts/split_pdf.rb'
25
+
26
+ begin
27
+ require 'colours'
28
+ include Colours
29
+ rescue LoadError; end
30
+
31
+ # ========================================================================= #
32
+ # === NAMESPACE
33
+ # ========================================================================= #
34
+ NAMESPACE = inspect
35
+
36
+ # ========================================================================= #
37
+ # === TITLE
38
+ # ========================================================================= #
39
+ TITLE = 'Split .pdf files'
40
+
41
+ # ========================================================================= #
42
+ # === WIDTH
43
+ # ========================================================================= #
44
+ WIDTH = 1400
45
+
46
+ # ========================================================================= #
47
+ # === HEIGHT
48
+ # ========================================================================= #
49
+ HEIGHT = 700
50
+
51
+ # ========================================================================= #
52
+ # === ARRAY_ADD_THESE_SHORTCUT_FOLDERS
53
+ # ========================================================================= #
54
+ ARRAY_ADD_THESE_SHORTCUT_FOLDERS = [
55
+ # "C:\\",
56
+ # "C:\\ingrid",
57
+ # '/ingrid'
58
+ ]
59
+
60
+ # ========================================================================= #
61
+ # === initialize
62
+ # ========================================================================= #
63
+ def initialize(
64
+ optional_file = nil,
65
+ run_already = true
66
+ )
67
+ super(:vertical)
68
+ reset
69
+ run if run_already
70
+ end
71
+
72
+ # ========================================================================= #
73
+ # === reset
74
+ # ========================================================================= #
75
+ def reset
76
+ reset_the_internal_variables
77
+ # ======================================================================= #
78
+ # === @configuration
79
+ # ======================================================================= #
80
+ @configuration = [true, __dir__, NAMESPACE]
81
+ set_use_this_font(:dejavu_condensed_24)
82
+ # ======================================================================= #
83
+ # === @title
84
+ # ======================================================================= #
85
+ @title = TITLE
86
+ # ======================================================================= #
87
+ # === @width
88
+ # ======================================================================= #
89
+ set_width(WIDTH)
90
+ # ======================================================================= #
91
+ # === @height
92
+ # ======================================================================= #
93
+ set_height(HEIGHT)
94
+ use_project_css_file
95
+ end
96
+
97
+ # ========================================================================= #
98
+ # === add_the_split_pdf_file_button
99
+ # ========================================================================= #
100
+ def add_the_split_pdf_file_button
101
+ minimal(
102
+ @button_split_the_pdf_file, 2
103
+ )
104
+ end
105
+
106
+ # ========================================================================= #
107
+ # === padding?
108
+ # ========================================================================= #
109
+ def padding?
110
+ 2
111
+ end
112
+
113
+ # ========================================================================= #
114
+ # === border_size?
115
+ # ========================================================================= #
116
+ def border_size?
117
+ 2
118
+ end
119
+
120
+ # ========================================================================= #
121
+ # === create_skeleton
122
+ # ========================================================================= #
123
+ def create_skeleton
124
+ @hbox1 = create_vbox
125
+ create_buttons
126
+ create_the_entries
127
+ end
128
+
129
+ # ========================================================================= #
130
+ # === create_the_entries (entries tag)
131
+ # ========================================================================= #
132
+ def create_the_entries
133
+ @entry_for_the_path_to_the_pdf_file = create_entry('')
134
+ @entry_for_the_path_to_the_pdf_file.on_click_event {
135
+ :highlight_text
136
+ }
137
+ # ======================================================================= #
138
+ # Determine where the individual .pdf files are to be kept:
139
+ # ======================================================================= #
140
+ _ = return_pwd
141
+ _ = '/Depot/j/'.dup if File.directory? '/Depot/j/'
142
+ @entry_for_the_directory_where_we_will_generate_the_individual_pdf_files_into = gtk_entry(
143
+ _
144
+ )
145
+ end
146
+
147
+ # ========================================================================= #
148
+ # === create_buttons (buttons tag)
149
+ #
150
+ # This method can be used to create all buttons in this small application.
151
+ # ========================================================================= #
152
+ def create_buttons
153
+ @button_file_chooser = create_button('Choose a file')
154
+ @button_file_chooser.on_hover(:lightgreen)
155
+ @button_file_chooser.on_clicked {
156
+ open_file_chooser_dialog
157
+ }
158
+ @button_file_chooser.fancy_tooltip = 'Select this to <b>choose</b> '\
159
+ ' a local .pdf file.'
160
+ @button_split_the_pdf_file = create_button('_Split the pdf file')
161
+ @button_split_the_pdf_file.clear_background
162
+ @button_split_the_pdf_file.on_hover(:lightgreen)
163
+ @button_split_the_pdf_file.hint =
164
+ 'Click on this button to actually <b>split the .pdf file</b> at hand.'
165
+ @button_split_the_pdf_file.on_clicked {
166
+ do_split_the_pdf_file
167
+ }
168
+ end
169
+
170
+ # ========================================================================= #
171
+ # === do_split_the_pdf_file (split tag)
172
+ #
173
+ # This is the main action of this class.
174
+ # ========================================================================= #
175
+ def do_split_the_pdf_file
176
+ target_file = @entry_for_the_path_to_the_pdf_file.text?
177
+ if File.exist?(target_file)
178
+ e 'Now splitting the .pdf file'
179
+ PdfParadise.split_this_pdf_file(
180
+ target_file, :default, store_in_which_directory?
181
+ )
182
+ else
183
+ e 'No file was found at the location '+target_file+'.'
184
+ end
185
+ end
186
+
187
+ # ========================================================================= #
188
+ # === store_in_which_directory?
189
+ #
190
+ # This method must return a String, hence why the method .text is used.
191
+ # ========================================================================= #
192
+ def store_in_which_directory?
193
+ @entry_for_the_directory_where_we_will_generate_the_individual_pdf_files_into.text
194
+ end
195
+
196
+ # ========================================================================= #
197
+ # === open_file_chooser_dialog
198
+ # ========================================================================= #
199
+ def open_file_chooser_dialog
200
+ @file_chooser_dialog = create_file_chooser_dialog('Open File',
201
+ self,
202
+ ::Gtk::FileChooser::ACTION_OPEN, nil,
203
+ [::Gtk::Stock::CANCEL, ::Gtk::Dialog::RESPONSE_CANCEL],
204
+ [::Gtk::Stock::OPEN, ::Gtk::Dialog::RESPONSE_ACCEPT]
205
+ )
206
+ if File.directory? '/Depot/j/'
207
+ @file_chooser_dialog.current_folder = '/Depot/j/'
208
+ else
209
+ @file_chooser_dialog.current_folder = return_pwd
210
+ end
211
+ # @file_chooser_dialog.add_shortcut_folder(return_pwd)
212
+ # ^^^ already exists as shortcut.
213
+ begin
214
+ ARRAY_ADD_THESE_SHORTCUT_FOLDERS.each {|this_directory|
215
+ @file_chooser_dialog.add_shortcut_folder(this_directory)
216
+ }
217
+ rescue; end
218
+ if File.directory? '/home/Temp/'
219
+ @file_chooser_dialog.add_directory('/home/Temp/')
220
+ end
221
+ @file_chooser_dialog.show_hidden = true # Do show hidden files.
222
+ @extra_button = create_button('_Extra button')
223
+ @extra_button.signal_connect(:clicked) { e ' > Extra button was clicked' }
224
+ @file_chooser_dialog.extra_widget = @extra_button
225
+ case @file_chooser_dialog.run
226
+ when ::Gtk::Dialog::RESPONSE_ACCEPT
227
+ filename = @file_chooser_dialog.filename.to_s
228
+ @entry_for_the_path_to_the_pdf_file.set_text(filename)
229
+ end
230
+ @file_chooser_dialog.destroy
231
+ end
232
+
233
+ # ========================================================================= #
234
+ # === connect_skeleton
235
+ # ========================================================================= #
236
+ def connect_skeleton
237
+ abort_on_exception
238
+ end
239
+
240
+ # ========================================================================= #
241
+ # === run
242
+ # ========================================================================= #
243
+ def run
244
+ create_skeleton
245
+ connect_skeleton
246
+ gtk_text_for_the_gtk_entry_denoting_into_which_directory_we_will_generate_the_pdf_files = gtk_label(
247
+ 'Set the path to the directory where these .pdf files will be kept below:'
248
+ )
249
+ gtk_text = create_label(
250
+ 'Set the path to the .pdf file below this text.'
251
+ ) {{
252
+ tooltip: 'You need to supply the path to the .pdf file '\
253
+ 'into the input field on the right side.'
254
+ }}
255
+ @hbox1.minimal(gtk_text)
256
+ @hbox1.maximal(@entry_for_the_path_to_the_pdf_file)
257
+ # ======================================================================= #
258
+ # And add the file-chooser button:
259
+ # ======================================================================= #
260
+ @hbox1.minimal(@button_file_chooser)
261
+ maximal(@hbox1, 1)
262
+
263
+ @vbox_denoting_where_the_individual_pdf_files_are_kept = gtk_vbox
264
+ @vbox_denoting_where_the_individual_pdf_files_are_kept.minimal(
265
+ gtk_text_for_the_gtk_entry_denoting_into_which_directory_we_will_generate_the_pdf_files,
266
+ 1
267
+ )
268
+ @vbox_denoting_where_the_individual_pdf_files_are_kept.minimal(
269
+ @entry_for_the_directory_where_we_will_generate_the_individual_pdf_files_into,
270
+ 1
271
+ )
272
+ minimal(
273
+ @vbox_denoting_where_the_individual_pdf_files_are_kept, 0
274
+ )
275
+ add_the_split_pdf_file_button
276
+ show_all
277
+ end
278
+
279
+ # ========================================================================= #
280
+ # === PdfParadise::GUI::Gtk::SplitPdfFileModule.run
281
+ # ========================================================================= #
282
+ def self.run
283
+ require 'gtk_paradise/run'
284
+ _ = ::PdfParadise::GUI::Gtk::SplitPdfFile.new
285
+ r = ::Gtk.run
286
+ r << _
287
+ r.set_size_request(
288
+ _.width?,
289
+ _.height?
290
+ )
291
+ r.enable_quick_exit
292
+ r.top_left_then_run
293
+ end
294
+
295
+ end; end; end; end