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,103 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === PdfParadise::GUI::Jruby::RemoveTheFirstPageOfThisPdfFile
6
+ #
7
+ # This may have to be rewritten eventually.
8
+ #
9
+ # Usage example:
10
+ #
11
+ # PdfParadise::GUI::Jruby::RemoveTheFirstPageOfThisPdfFile.new(ARGV)
12
+ #
13
+ # =========================================================================== #
14
+ # require 'pdf_paradise/gui/jruby/remove_the_first_page_of_this_pdf_file/remove_the_first_page_of_this_pdf_file.rb'
15
+ # =========================================================================== #
16
+ include Java
17
+
18
+ java_import javax.swing.JButton
19
+ java_import javax.swing.JFrame
20
+ java_import javax.swing.JLabel
21
+ java_import javax.swing.JPanel
22
+ java_import javax.swing.JTextArea
23
+ java_import javax.swing.JScrollBar
24
+ java_import javax.swing.JTextField
25
+ java_import javax.swing.JSpinner
26
+ java_import javax.swing.SpinnerNumberModel
27
+ java_import java.lang.System
28
+ java_import java.awt.Font
29
+ java_import java.awt.BorderLayout
30
+
31
+ module PdfParadise
32
+
33
+ module GUI
34
+
35
+ module Jruby # === PdfParadise::GUI::Jruby
36
+
37
+ class RemoveTheFirstPageOfThisPdfFile < JFrame # === Foo::RemoveTheFirstPageOfThisPdfFile
38
+
39
+ require 'swing_paradise/base_module/base_module.rb'
40
+ include SwingParadise::BaseModule
41
+
42
+ # ========================================================================= #
43
+ # === NAMESPACE
44
+ # ========================================================================= #
45
+ NAMESPACE = inspect
46
+
47
+ # ========================================================================= #
48
+ # === initialize
49
+ # ========================================================================= #
50
+ def initialize(
51
+ commandline_arguments = nil,
52
+ run_already = true
53
+ )
54
+ super()
55
+ reset
56
+ set_commandline_arguments(
57
+ commandline_arguments
58
+ )
59
+ run if run_already
60
+ end
61
+
62
+ # ========================================================================= #
63
+ # === reset (reset tag)
64
+ # ========================================================================= #
65
+ def reset
66
+ super() if respond_to?(:super)
67
+ # ======================================================================= #
68
+ # === @namespace
69
+ # ======================================================================= #
70
+ @namespace = NAMESPACE
71
+ end
72
+
73
+ # ========================================================================= #
74
+ # === run (run tag)
75
+ # ========================================================================= #
76
+ def run
77
+ #text1 = text('Denote which .pdf file is to manipulated, in the following entry')
78
+ b1 = button('NORTH')
79
+ b1.on_clicked {
80
+ e 'HEY THERE'
81
+ }
82
+ #add(text1, BorderLayout::NORTH)
83
+ add(b1, BorderLayout::SOUTH)
84
+ add(button('EAST'), BorderLayout::EAST)
85
+ add(button('WEST'), BorderLayout::WEST)
86
+ add(button('CENTER'), BorderLayout::CENTER)
87
+ set_size(WIDTH, HEIGHT)
88
+ setVisible(true)
89
+ #show_all
90
+ end
91
+
92
+ # ========================================================================= #
93
+ # === PdfParadise::GUI::Jruby::RemoveTheFirstPageOfThisPdfFile[]
94
+ # ========================================================================= #
95
+ def self.[](i = ARGV)
96
+ new(i)
97
+ end
98
+
99
+ end; end; end; end
100
+
101
+ if __FILE__ == $PROGRAM_NAME
102
+ PdfParadise::GUI::Jruby::RemoveTheFirstPageOfThisPdfFile.new(ARGV)
103
+ end # remove_the_first_page_of_this_pdf_file.rb
@@ -0,0 +1,223 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === PdfParadise::GUI::LibUI::ExtractAllImagesFromThisPdfFile
6
+ # =========================================================================== #
7
+ # require 'pdf_paradise/gui/libui/extract_all_images_from_this_pdf_file/extract_all_images_from_this_pdf_file.rb'
8
+ # PdfParadise::GUI::LibUI::ExtractAllImagesFromThisPdfFile.new
9
+ # =========================================================================== #
10
+ module PdfParadise
11
+
12
+ module GUI
13
+
14
+ module LibUI
15
+
16
+ class ExtractAllImagesFromThisPdfFile # === PdfParadise::GUI::LibUI::ExtractAllImagesFromThisPdfFile
17
+
18
+ require 'fileutils'
19
+ require 'pdf_paradise/toplevel_methods/misc.rb'
20
+ require 'pdf_paradise/utility_scripts/extract_all_images_from_this_pdf_file.rb'
21
+
22
+ alias e puts
23
+
24
+ require 'libui_paradise'
25
+ include LibuiParadise::Extensions
26
+
27
+ # ========================================================================= #
28
+ # === TITLE
29
+ # ========================================================================= #
30
+ TITLE = 'Extract all images from this .pdf file'
31
+
32
+ # ========================================================================= #
33
+ # === WIDTH
34
+ # ========================================================================= #
35
+ WIDTH = 800
36
+
37
+ # ========================================================================= #
38
+ # === HEIGHT
39
+ # ========================================================================= #
40
+ HEIGHT = 680
41
+
42
+ # ========================================================================= #
43
+ # === initialize
44
+ #
45
+ # This class will not make use of ARGV by default, so you have to
46
+ # pass it in on your own.
47
+ # ========================================================================= #
48
+ def initialize(
49
+ optional_commandline_arguments = [],
50
+ run_already = true
51
+ )
52
+ reset
53
+ @commandline_arguments = [optional_commandline_arguments].flatten.compact
54
+ run if run_already
55
+ end
56
+
57
+ # ========================================================================= #
58
+ # === reset (reset tag)
59
+ # ========================================================================= #
60
+ def reset
61
+ title_width_height(TITLE, WIDTH, HEIGHT)
62
+ # ======================================================================= #
63
+ # === @_
64
+ # ======================================================================= #
65
+ @_ = PdfParadise::ExtractAllImagesFromThisPdfFile.new(:do_not_run_yet)
66
+ end
67
+
68
+ # ========================================================================= #
69
+ # === create_skeleton (create tag, skeleton tag)
70
+ # ========================================================================= #
71
+ def create_skeleton
72
+ # ======================================================================= #
73
+ # === @window
74
+ # ======================================================================= #
75
+ @window = ui_padded_main_window(title?, width?, height?, 0)
76
+ create_the_entries
77
+ end
78
+
79
+ # ========================================================================= #
80
+ # === create_the_entries
81
+ # ========================================================================= #
82
+ def create_the_entries
83
+ # ======================================================================= #
84
+ # === @entry_work_on_this_pdf_file
85
+ # ======================================================================= #
86
+ @entry_work_on_this_pdf_file = entry
87
+ end
88
+
89
+ # ========================================================================= #
90
+ # === main_entry?
91
+ # ========================================================================= #
92
+ def main_entry?
93
+ @entry_work_on_this_pdf_file
94
+ end
95
+
96
+ # ========================================================================= #
97
+ # === return_the_file_open_button
98
+ # ========================================================================= #
99
+ def return_the_file_open_button
100
+ button_open_file = button('Open file')
101
+ button_open_file.on_clicked {
102
+ begin
103
+ filename = ui_open_file(@window).to_s # This is the part that will open a local file.
104
+ if filename and !filename.empty?
105
+ filename = File.absolute_path(filename)
106
+ main_entry?.set_text(filename)
107
+ end
108
+ rescue Exception
109
+ end
110
+ }
111
+ return button_open_file
112
+ end
113
+
114
+ # ========================================================================= #
115
+ # === run
116
+ # ========================================================================= #
117
+ def run
118
+ log_dir = PdfParadise.log_dir?
119
+ unless File.directory? log_dir
120
+ begin
121
+ FileUtils.mkdir_p(log_dir)
122
+ rescue LoadError; end
123
+ end
124
+ PdfParadise.cd_to_the_log_directory
125
+ create_skeleton_then_connect_skeleton
126
+ outer_vbox = padded_vbox
127
+ # ======================================================================= #
128
+ # First add the two buttons on top:
129
+ # ======================================================================= #
130
+ button_do_extract = ui_button('Extract the images')
131
+ button_do_extract.on_clicked {
132
+ do_extract_the_pdf_file
133
+ }
134
+ outer_vbox.add_hsep
135
+
136
+ grid = ui_padded_grid
137
+ # widget, left, top, xspan, yspan, hexpand, halign, vexpand, valign
138
+ grid.ui_grid_append(text('Work on this .pdf file → '), 0, 0, 1, 1, 0, 0.5, 0, 0)
139
+ grid.ui_grid_append(main_entry?, 1, 0, 2, 1, 1, 0.5, 0, 0)
140
+
141
+ grid.hash_grid(
142
+ button_do_extract,
143
+ left: 0,
144
+ top: 1,
145
+ xspan: 1,
146
+ yspan: 1,
147
+ hexpand: 0,
148
+ halign: 0.5,
149
+ vexpand: 0,
150
+ valign: 0
151
+ )
152
+ grid.hash_grid(
153
+ return_the_file_open_button,
154
+ left: 1,
155
+ top: 1,
156
+ xspan: 1,
157
+ yspan: 1,
158
+ hexpand: 0,
159
+ halign: 0.5,
160
+ vexpand: 0,
161
+ valign: 0
162
+ )
163
+ grid.hash_grid(
164
+ text('Current working directory: '+return_pwd),
165
+ left: 2,
166
+ top: 1,
167
+ xspan: 1,
168
+ yspan: 1,
169
+ hexpand: 0,
170
+ halign: 0.5,
171
+ vexpand: 0,
172
+ valign: 0
173
+ )
174
+ outer_vbox.minimal(grid, 0)
175
+ outer_vbox.add_hsep
176
+ outer_vbox.minimal(quit_button)
177
+ outer_vbox.add_hsep
178
+ ::LibuiParadise.set_main_window(@window)
179
+ do_parse_the_commandline_arguments
180
+ @window.add(outer_vbox)
181
+ @window.intelligent_exit
182
+ end
183
+
184
+ # ========================================================================= #
185
+ # === do_parse_the_commandline_arguments
186
+ # ========================================================================= #
187
+ def do_parse_the_commandline_arguments
188
+ _ = @commandline_arguments
189
+ if _ and _.is_a?(Array) and !_.empty?
190
+ _.each {|entry|
191
+ if File.exist? entry
192
+ set_work_on_this_file(entry)
193
+ end
194
+ }
195
+ end
196
+ end
197
+
198
+ # ========================================================================= #
199
+ # === set_work_on_this_file
200
+ # ========================================================================= #
201
+ def set_work_on_this_file(i)
202
+ @entry_work_on_this_pdf_file.set_text(i)
203
+ end
204
+
205
+ # ========================================================================= #
206
+ # === do_extract_the_pdf_file
207
+ # ========================================================================= #
208
+ def do_extract_the_pdf_file(
209
+ this_pdf_file = @entry_work_on_this_pdf_file.text?
210
+ )
211
+ @_.do_extract_the_pdf_file(this_pdf_file)
212
+ LibuiParadise.message_box(
213
+ 'If everything went fine then you should now be able '\
214
+ 'to see all extracted images in the '\
215
+ 'directory `'+return_pwd+'`.'
216
+ )
217
+ end
218
+
219
+ end; end; end; end
220
+
221
+ if __FILE__ == $PROGRAM_NAME
222
+ PdfParadise::GUI::LibUI::ExtractAllImagesFromThisPdfFile.new
223
+ end
@@ -0,0 +1,267 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === PdfParadise::GUI::LibUI::RemoveTheFirstPageOfThisPdfFile
6
+ # =========================================================================== #
7
+ # require 'pdf_paradise/gui/libui/remove_the_first_page_of_this_pdf_file/remove_the_first_page_of_this_pdf_file.rb'
8
+ # PdfParadise::GUI::LibUI::RemoveTheFirstPageOfThisPdfFile.new
9
+ # =========================================================================== #
10
+ module PdfParadise
11
+
12
+ module GUI
13
+
14
+ module LibUI
15
+
16
+ class RemoveTheFirstPageOfThisPdfFile # === PdfParadise::GUI::LibUI::RemoveTheFirstPageOfThisPdfFile
17
+
18
+ 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'
19
+ include PdfParadise::GUI::RemoveTheFirstPageOfThisPdfFileModule
20
+
21
+ require 'fileutils'
22
+ require 'pdf_paradise/toplevel_methods/misc.rb'
23
+ require 'pdf_paradise/utility_scripts/delete_the_first_page_of_this_pdf_file/delete_the_first_page_of_this_pdf_file.rb'
24
+ require 'pdf_paradise/utility_scripts/rotate_pdf_file.rb'
25
+
26
+ alias e puts
27
+
28
+ require 'libui_paradise/extensions/extensions.rb'
29
+ include LibuiParadise::Extensions
30
+
31
+ # ========================================================================= #
32
+ # === FILE_LAST_MODIFIED_PDF_FILE
33
+ #
34
+ # This is hardcoded for now. At a later time we may have to query for
35
+ # the primary log-directory in use.
36
+ # ========================================================================= #
37
+ FILE_LAST_MODIFIED_PDF_FILE =
38
+ '/tmp/pdf_paradise/last_modified_pdf_file.yml'
39
+
40
+ # ========================================================================= #
41
+ # === DEFAULT_PDF_FILE_TO_WORK_ON_WINDOWS
42
+ #
43
+ # This is also hardcoded.
44
+ # ========================================================================= #
45
+ DEFAULT_PDF_FILE_TO_WORK_ON_WINDOWS =
46
+ '/home/x/books/Basiswissen_Humangenetik_3rd_edition_by_Christian_Schaaf_2018/'\
47
+ 'Basiswissen_Humangenetik_3rd_edition_by_Christian_Schaaf_2018.pdf'
48
+
49
+ # ========================================================================= #
50
+ # === WIDTH
51
+ # ========================================================================= #
52
+ WIDTH = 1280
53
+
54
+ # ========================================================================= #
55
+ # === HEIGHT
56
+ # ========================================================================= #
57
+ HEIGHT = 380
58
+
59
+ # ========================================================================= #
60
+ # === initialize
61
+ # ========================================================================= #
62
+ def initialize(
63
+ optional_commandline_arguments = [],
64
+ run_already = true
65
+ )
66
+ reset
67
+ @commandline_arguments = [optional_commandline_arguments].flatten.compact
68
+ sanitize_the_commandline_arguments
69
+ run if run_already
70
+ end
71
+
72
+ # ========================================================================= #
73
+ # === sanitize_the_commandline_arguments
74
+ # ========================================================================= #
75
+ def sanitize_the_commandline_arguments
76
+ if @commandline_arguments and !@commandline_arguments.empty?
77
+ @commandline_arguments.map! {|entry|
78
+ File.absolute_path(entry) unless entry.start_with?('--')
79
+ }
80
+ end
81
+ end
82
+
83
+ # ========================================================================= #
84
+ # === reset (reset tag)
85
+ # ========================================================================= #
86
+ def reset
87
+ title_width_height(TITLE, WIDTH, HEIGHT)
88
+ end
89
+
90
+ # ========================================================================= #
91
+ # === create_skeleton (create tag, skeleton tag)
92
+ # ========================================================================= #
93
+ def create_skeleton
94
+ # ======================================================================= #
95
+ # === @window
96
+ # ======================================================================= #
97
+ @window = ui_padded_main_window(title?, width?, height?, 0)
98
+ create_the_main_entry
99
+ end
100
+
101
+ # ========================================================================= #
102
+ # === create_the_main_entry
103
+ # ========================================================================= #
104
+ def create_the_main_entry
105
+ @entry1 = ui_entry
106
+ _ = PdfParadise.use_which_file?
107
+ unless @commandline_arguments.empty?
108
+ _ = @commandline_arguments.first
109
+ end
110
+ _ = File.absolute_path(_) if _
111
+ if _ # In this case we first assume that the file exists.
112
+ @entry1.set_text(_)
113
+ elsif File.exist? FILE_LAST_MODIFIED_PDF_FILE
114
+ @entry1.set_text(YAML.load_file(FILE_LAST_MODIFIED_PDF_FILE))
115
+ elsif PdfParadise.is_on_windows?
116
+ @entry1.set_text(DEFAULT_PDF_FILE_TO_WORK_ON_WINDOWS)
117
+ end
118
+ end
119
+
120
+ # ========================================================================= #
121
+ # === main_entry?
122
+ # ========================================================================= #
123
+ def main_entry?
124
+ @entry1
125
+ end
126
+
127
+ # ========================================================================= #
128
+ # === return_open_the_pdf_file_button
129
+ # ========================================================================= #
130
+ def return_open_the_pdf_file_button
131
+ button = ui_button('Open the .pdf file via okular')
132
+ button.on_clicked {
133
+ esystem "okular #{main_entry?.text?.to_s}"
134
+ }
135
+ return button
136
+ end
137
+
138
+ # ========================================================================= #
139
+ # === do_remove_the_first_page_of_this_pdf_file (remove tag)
140
+ #
141
+ # This is the method that will do the remove-the-first-page action.
142
+ #
143
+ # It will delegate towards the method called
144
+ # PdfParadise.delete_the_first_page_of_this_pdf_file.
145
+ # ========================================================================= #
146
+ def do_remove_the_first_page_of_this_pdf_file(
147
+ i = main_entry?
148
+ )
149
+ if i and i.respond_to?(:text?)
150
+ i = i.text?
151
+ end
152
+ i = i.to_s
153
+ if File.exist?(i) and i.end_with?('.pdf')
154
+ e "#{rev}Working on the file `#{i}#{rev}` next:"
155
+ _result = PdfParadise.delete_the_first_page_of_this_pdf_file(i)
156
+ else
157
+ e 'No file was found at `'+i+'`.'
158
+ end
159
+ end
160
+
161
+ # ========================================================================= #
162
+ # === return_button_open_file
163
+ # ========================================================================= #
164
+ def return_button_open_file
165
+ button_open_file = button('Open file')
166
+ button_open_file.on_clicked {
167
+ filename = ui_open_file(window).to_s # This is the part that will open a local file.
168
+ main_entry?.set_text(filename)
169
+ }
170
+ return button_open_file
171
+ end
172
+
173
+ # ========================================================================= #
174
+ # === create_a_clean_state
175
+ # ========================================================================= #
176
+ def create_a_clean_state
177
+ PdfParadise.ensure_that_the_log_directory_exists
178
+ PdfParadise.cd_to_the_log_directory
179
+ end
180
+
181
+ # ========================================================================= #
182
+ # === run
183
+ # ========================================================================= #
184
+ def run
185
+ # Create a clean state here.
186
+ create_a_clean_state
187
+ create_skeleton_then_connect_skeleton
188
+ outer_vbox = padded_vbox
189
+ # ======================================================================= #
190
+ # First add the two buttons on top:
191
+ # ======================================================================= #
192
+ button_do_remove_the_first_page_of_this_pdf_file = ui_button(
193
+ 'Do remove the first page of this .pdf file'
194
+ )
195
+ button_do_remove_the_first_page_of_this_pdf_file.on_clicked {
196
+ do_remove_the_first_page_of_this_pdf_file
197
+ }
198
+ outer_vbox.add_hsep
199
+
200
+ grid = ui_padded_grid
201
+ # widget, left, top, xspan, yspan, hexpand, halign, vexpand, valign
202
+ grid.ui_grid_append(text('Work on this .pdf file → '), 0, 0, 1, 1, 0, 0.5, 0, 0)
203
+ grid.ui_grid_append(main_entry?, 1, 0, 1, 1, 1, 0.5, 0, 0)
204
+ grid.ui_grid_append(return_button_open_file, 2, 0, 1, 1, 0, 0.5, 0, 0)
205
+
206
+ # ======================================================================= #
207
+ # Add the button that allows the user to remove the first page of
208
+ # the .pdf file next:
209
+ # ======================================================================= #
210
+ grid.hash_grid(
211
+ button_do_remove_the_first_page_of_this_pdf_file,
212
+ left: 0,
213
+ top: 1,
214
+ xspan: 1,
215
+ yspan: 1,
216
+ hexpand: 0,
217
+ halign: 0.5,
218
+ vexpand: 0,
219
+ valign: 0
220
+ )
221
+ # ======================================================================= #
222
+ # === Add a text that shows the current working directory in use:
223
+ # ======================================================================= #
224
+ grid.hash_grid(
225
+ text('Current working directory: '+return_pwd),
226
+ left: 1,
227
+ top: 1,
228
+ xspan: 2,
229
+ yspan: 1,
230
+ hexpand: 0,
231
+ halign: 0.5,
232
+ vexpand: 0,
233
+ valign: 0
234
+ )
235
+ outer_vbox.minimal(grid, 5)
236
+ outer_vbox.add_hsep
237
+ outer_vbox.minimal(
238
+ return_the_default_open_file_button(main_entry?),
239
+ 5
240
+ )
241
+ outer_vbox.add_hsep
242
+ outer_vbox.minimal(
243
+ return_open_the_pdf_file_button,
244
+ 5
245
+ )
246
+ outer_vbox.add_hsep
247
+ # Add the quit button next
248
+ outer_vbox.minimal(quit_button, 2)
249
+ outer_vbox.add_hsep
250
+ outer_vbox.minimal(
251
+ text('The application that will be used for removing pages from the '\
252
+ 'pdf file is: '+
253
+ PdfParadise.use_which_pdf_application_for_deleting_the_first_page_of_a_pdf_file?.to_s
254
+ ),
255
+ 2
256
+ )
257
+ outer_vbox.add_hsep
258
+ ::LibuiParadise.set_main_window(@window)
259
+ @window.add(outer_vbox)
260
+ @window.intelligent_exit
261
+ end
262
+
263
+ end; end; end; end
264
+
265
+ if __FILE__ == $PROGRAM_NAME
266
+ PdfParadise::GUI::LibUI::RemoveTheFirstPageOfThisPdfFile.new(ARGV)
267
+ end # libui_remove_page