pdf_paradise 0.1.43

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

Potentially problematic release.


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

Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +376 -0
  3. data/bin/automatic_pdf_title +7 -0
  4. data/bin/convert_markdown_to_pdf +7 -0
  5. data/bin/convert_pdf_to_text +7 -0
  6. data/bin/merge_then_open +7 -0
  7. data/bin/n_pages +10 -0
  8. data/bin/open_main_pdf +7 -0
  9. data/bin/pdf_paradise +7 -0
  10. data/bin/set_main_book +7 -0
  11. data/bin/set_title_of_this_pdf_file +15 -0
  12. data/doc/README.gen +348 -0
  13. data/doc/todo/todo.md +2 -0
  14. data/lib/pdf_paradise.rb +5 -0
  15. data/lib/pdf_paradise/base/base.rb +173 -0
  16. data/lib/pdf_paradise/commandline/help.rb +69 -0
  17. data/lib/pdf_paradise/commandline/menu.rb +160 -0
  18. data/lib/pdf_paradise/compress_this_pdf_file.rb +82 -0
  19. data/lib/pdf_paradise/constants/constants.rb +59 -0
  20. data/lib/pdf_paradise/convert_text_to_pdf.rb +94 -0
  21. data/lib/pdf_paradise/css/project.css +17 -0
  22. data/lib/pdf_paradise/djvu_to_pdf.rb +85 -0
  23. data/lib/pdf_paradise/gui/README.md +6 -0
  24. data/lib/pdf_paradise/gui/fox/split_pdf_file.rb +77 -0
  25. data/lib/pdf_paradise/gui/gtk2/delete_the_first_or_the_last_page_of_this_pdf_file/delete_the_first_or_the_last_page_of_this_pdf_file.rb +39 -0
  26. data/lib/pdf_paradise/gui/gtk2/pdf_viewer/pdf_viewer.rb +34 -0
  27. data/lib/pdf_paradise/gui/gtk2/split_pdf_file/split_pdf_file.rb +34 -0
  28. data/lib/pdf_paradise/gui/gtk2/statistics_widget/statistics_widget.rb +34 -0
  29. data/lib/pdf_paradise/gui/gtk2/to_pdf/to_pdf.rb +32 -0
  30. data/lib/pdf_paradise/gui/gtk3/controller/controller.rb +197 -0
  31. data/lib/pdf_paradise/gui/gtk3/convert_pdf_to_text/convert_pdf_to_text.rb +34 -0
  32. data/lib/pdf_paradise/gui/gtk3/delete_the_first_or_the_last_page_of_this_pdf_file/delete_the_first_or_the_last_page_of_this_pdf_file.rb +39 -0
  33. data/lib/pdf_paradise/gui/gtk3/pdf_viewer/pdf_viewer.rb +34 -0
  34. data/lib/pdf_paradise/gui/gtk3/split_pdf_file/split_pdf_file.rb +34 -0
  35. data/lib/pdf_paradise/gui/gtk3/statistics_widget/statistics_widget.rb +34 -0
  36. data/lib/pdf_paradise/gui/gtk3/to_pdf/to_pdf.rb +32 -0
  37. data/lib/pdf_paradise/gui/shared_code/convert_pdf_to_text/convert_pdf_to_text_module.rb +277 -0
  38. data/lib/pdf_paradise/gui/shared_code/delete_the_first_or_the_last_page_of_this_pdf_file/delete_the_first_or_the_last_page_of_this_pdf_file_module.rb +428 -0
  39. data/lib/pdf_paradise/gui/shared_code/pdf_viewer/pdf_viewer.css +5 -0
  40. data/lib/pdf_paradise/gui/shared_code/pdf_viewer/pdf_viewer_module.rb +284 -0
  41. data/lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file.css +0 -0
  42. data/lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb +294 -0
  43. data/lib/pdf_paradise/gui/shared_code/statistics_widget/statistics_widget_module.rb +333 -0
  44. data/lib/pdf_paradise/gui/shared_code/to_pdf/to_pdf_module.rb +273 -0
  45. data/lib/pdf_paradise/main_pdf/main_pdf.rb +437 -0
  46. data/lib/pdf_paradise/merge_pdf/menu.rb +63 -0
  47. data/lib/pdf_paradise/merge_pdf/merge_pdf.rb +292 -0
  48. data/lib/pdf_paradise/merge_pdf_namespace.rb +9 -0
  49. data/lib/pdf_paradise/merge_then_open/merge_then_open.rb +105 -0
  50. data/lib/pdf_paradise/pdf_file_n_total_pages.rb +227 -0
  51. data/lib/pdf_paradise/project/project_base_directory.rb +22 -0
  52. data/lib/pdf_paradise/remove_pdf_password.rb +392 -0
  53. data/lib/pdf_paradise/requires/batch_require_toplevel_files.rb +22 -0
  54. data/lib/pdf_paradise/requires/colours.rb +7 -0
  55. data/lib/pdf_paradise/requires/colours_and_esystem_and_save_file_and_fileutils_and_opn.rb +11 -0
  56. data/lib/pdf_paradise/requires/esystem_and_colours.rb +10 -0
  57. data/lib/pdf_paradise/requires/esystem_and_opn_and_colours.rb +8 -0
  58. data/lib/pdf_paradise/requires/require_the_whole_project.rb +25 -0
  59. data/lib/pdf_paradise/requires/require_utility_scripts.rb +7 -0
  60. data/lib/pdf_paradise/rotate_pdf_file.rb +144 -0
  61. data/lib/pdf_paradise/set_main_book.rb +156 -0
  62. data/lib/pdf_paradise/set_pdf_title.rb +218 -0
  63. data/lib/pdf_paradise/sinatra/embeddable_interface.rb +315 -0
  64. data/lib/pdf_paradise/toplevel_methods/automatic_pdf_title.rb +55 -0
  65. data/lib/pdf_paradise/toplevel_methods/convert_epub_to_pdf.rb +27 -0
  66. data/lib/pdf_paradise/toplevel_methods/convert_markdown_to_pdf.rb +43 -0
  67. data/lib/pdf_paradise/toplevel_methods/convert_ppt_to_pdf.rb +35 -0
  68. data/lib/pdf_paradise/toplevel_methods/e.rb +16 -0
  69. data/lib/pdf_paradise/toplevel_methods/esystem.rb +19 -0
  70. data/lib/pdf_paradise/toplevel_methods/misc.rb +52 -0
  71. data/lib/pdf_paradise/toplevel_methods/number_pages.rb +38 -0
  72. data/lib/pdf_paradise/toplevel_methods/opened_pdf_files.rb +191 -0
  73. data/lib/pdf_paradise/toplevel_methods/query_pdf_title.rb +182 -0
  74. data/lib/pdf_paradise/toplevel_methods/reduce_size_of_this_pdf_file.rb +43 -0
  75. data/lib/pdf_paradise/toplevel_methods/roebe.rb +17 -0
  76. data/lib/pdf_paradise/toplevel_methods/to_pdf.rb +38 -0
  77. data/lib/pdf_paradise/utility_scripts/README.md +3 -0
  78. data/lib/pdf_paradise/utility_scripts/convert_pdf_to_text.rb +166 -0
  79. data/lib/pdf_paradise/utility_scripts/delete_first_page_of_this_pdf_file.rb +185 -0
  80. data/lib/pdf_paradise/utility_scripts/delete_last_page_of_this_pdf_file.rb +180 -0
  81. data/lib/pdf_paradise/utility_scripts/delete_this_page_of_this_pdf_file.rb +310 -0
  82. data/lib/pdf_paradise/utility_scripts/extract_pdf_page.rb +280 -0
  83. data/lib/pdf_paradise/utility_scripts/pdf_optimizer.rb +113 -0
  84. data/lib/pdf_paradise/utility_scripts/pdf_statistics.rb +150 -0
  85. data/lib/pdf_paradise/utility_scripts/remove_images.rb +110 -0
  86. data/lib/pdf_paradise/utility_scripts/split_pdf.rb +294 -0
  87. data/lib/pdf_paradise/utility_scripts/to_qdf.rb +82 -0
  88. data/lib/pdf_paradise/version/version.rb +19 -0
  89. data/lib/pdf_paradise/www/README.md +2 -0
  90. data/lib/pdf_paradise/www/sinatra/app.rb +276 -0
  91. data/pdf_paradise.gemspec +64 -0
  92. data/test/testing_pdf_paradise.rb +9 -0
  93. metadata +216 -0
data/bin/set_main_book ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'pdf_paradise/set_main_book.rb'
6
+
7
+ PdfParadise::SetMainBook.new(ARGV)
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # Remember that the first argument is the name of the .pdf file
6
+ # in question and that the second argument is the title that you
7
+ # wish to assign to it.
8
+ # =========================================================================== #
9
+ require 'pdf_paradise'
10
+
11
+ if ARGV.size < 2
12
+ PdfParadise.show_correct_pdf_title_usage
13
+ else
14
+ PdfParadise.set_title_of_this_pdf_file(ARGV.first, ARGV[1])
15
+ end # Usage example: pdf_title foo.pdf "This is the new title"
data/doc/README.gen ADDED
@@ -0,0 +1,348 @@
1
+ ADD_RUBY_HEADER
2
+ ADD_TIME_STAMP
3
+
4
+ This project can help with pdf-related activities, such as extracting
5
+ a .pdf page, converting .pdf page, merging .pdf files, splitting
6
+ .pdf files, setting the title of a .pdf page and similar actions.
7
+
8
+ The project has to remain quite flexible. We may use external
9
+ programs such as **ghoscript** or **qpdf*, or we may use pure
10
+ ruby solutions, such as via the gem called **combine_pdf**,
11
+ **prawn** or **hexapdf**.
12
+
13
+ The file here (README.gen, respectively the generated file called
14
+ **README.md**), will describe some of the components that make
15
+ up this gem.
16
+
17
+ ## Rationale for making use of separate pdf-related projects
18
+
19
+ There are many pdf-related tools if you look on the www. For
20
+ example, we have prawn, we have qpdf, we have calibre, we
21
+ have hexapdf, we have ghostscript, and many more applications.
22
+
23
+ Some of these have unique features; and some of them have overlapping
24
+ functionality, such as reading the content of .pdf files in a
25
+ simplified manner (number of pages, title, author and so forth).
26
+
27
+ The PdfParadise project attempts to support as many different
28
+ (open-source) projects as possible. It is also permissive to
29
+ support closed source projects, provided that the code retains
30
+ simple (and simple to change). The primary focus is on
31
+ open-source projects though.
32
+
33
+ Why does the PdfParadise project attempt to support many different
34
+ pdf-related projects?
35
+
36
+ The main answer is quite simple. On Linux I have a lot of flexibility
37
+ and can use literally any pdf-related project just fine. On Windows,
38
+ however had, I am more restricted in what I can use. Not all programs
39
+ are available on windows or can be easily compiled there. Thus, in
40
+ order to allow the pdf_paradise .gem to work on windows, we need
41
+ this flexibility.
42
+
43
+ The reason why I added this subsection here in June 2021 was that
44
+ I am slowly changing the sinatra-related part of the PdfParadise
45
+ project, in order to embed the functionality into my main controller
46
+ which is handled by the **Roebe** namespace. In that controller
47
+ I wanted to easily offer pdf-related functionality "out of the
48
+ box" when I start the sinatra-application on windows. Because I
49
+ want to be able to offer pdf-related modifications on windows
50
+ as well, the PdfParadise project had to become more flexible,
51
+ so that a simple toplevel route, such as **/pdf**, will work
52
+ properly, and lead to entry points (subroutes) that allow
53
+ us to tap into the features offered by the PdfParadise project.
54
+
55
+ So, the summary is: the PdfParadise project must remain
56
+ flexible in order to support a proper workflow on windows
57
+ systems as well. (We could use WSL on windows, but not every
58
+ computer has this available, so I am targeting "vanilla"
59
+ windows really.)
60
+
61
+ Note that one slight drawback is that the sinatra prat of
62
+ the PdfParadise project now has a dependency on the
63
+ **cyberweb** project. This is a trade-off - for me the
64
+ more important part is long-term maintainability of
65
+ the pdf_paradise project in the long run, so a unified
66
+ code base had to be used in this regard.
67
+
68
+ ## Converting a .pdf file to text
69
+
70
+ Sometimes you may wish to have a text-file describing the content
71
+ of a .pdf file, rather than the .pdf file itself.
72
+
73
+ Via class **PdfParadise::ConvertPdfToText**, residing in the file
74
+ at **pdf_paradise/convert_pdf_to_text.rb**, you can convert a
75
+ .pdf file to a text file.
76
+
77
+ Usage example from ruby, for the file called **foobar.pdf**:
78
+
79
+ PdfParadise::ConvertPdfToText.new(ARGV)
80
+ PdfParadise::ConvertPdfToText.new('foobar.pdf')
81
+
82
+ You can also use the bin/ file from the commandline:
83
+
84
+ convert_pdf_to_text
85
+ convert_pdf_to_text foobar.pdf
86
+
87
+ There is also a ruby-gtk3 widget that offers the functionality
88
+ from class **PdfParadise::ConvertPdfToText**, if the user
89
+ has gtk3 installed and the ruby-bindings to it as well.
90
+
91
+ You can start that ruby-gtk3 widget via:
92
+
93
+ convert_pdf_to_text --gui
94
+
95
+ ## Commandline usage
96
+
97
+ You can use the **pdf_paradise** gem from the commandline, as
98
+ the example above shows.
99
+
100
+ For instance, say that you wish to modify **the title of a .pdf
101
+ file**, you can use a commandline invocation such as via
102
+ this way:
103
+
104
+ pdf_paradise --use-this-pdf-file=location_to_your_pdf_file.pdf --set_title="The title you want to use goes in here."
105
+
106
+ You can also **shrink** a .pdf file, by using the commandline
107
+ switch <b>--shrink-pdf-size-of=foobar.pdf</b> or just
108
+ <b>--shrink</b>, such as:
109
+
110
+ pdf_paradise --shrink-pdf-size-of=foobar.pdf
111
+ pdf_paradise --shrink=foobar.pdf
112
+
113
+ The <b>shrink</b> functionality is contained in the module-method
114
+ <b>PdfParadise.reduce_size_of_this_pdf_file()</b>.
115
+
116
+ ## Storing the .pdf pages that are currently open
117
+
118
+ If you need to store the .pdf files that are currently open,
119
+ you can use the following commandline to do so:
120
+
121
+ pdfparadise --store-open-pdf-files
122
+
123
+ This will attempt to store the full path to the .pdf files
124
+ into a local file. That way you may also be able to batch-open
125
+ these .pdf files at a later time, e. g. when you switch your
126
+ window manager or after a reboot.
127
+
128
+ ## Deleting the last or the first page of a .pdf file
129
+
130
+ You can use **class DeleteLastPageOfThisPdfFile**, more
131
+ accurately called **class PdfParadise::DeleteLastPageOfThisPdfFile**,
132
+ to ***delete the last page in a .pdf file***.
133
+
134
+ In ruby code, you can invoke this like so:
135
+
136
+ require 'pdf_paradise'
137
+
138
+ PdfParadise::DeleteLastPageOfThisPdfFile.new('path_to_the_pdf_file/goes_in_here.pdf')
139
+
140
+ or shorter:
141
+
142
+ require 'pdf_paradise'
143
+
144
+ PdfParadise.delete_last_page_of_this_pdf_file('foobar.pdf')
145
+
146
+ A very similar API exists for deleting the first page of a given .pdf
147
+ file, too.
148
+
149
+ See:
150
+
151
+ In ruby code, you can invoke this like so:
152
+
153
+ require 'pdf_paradise'
154
+
155
+ PdfParadise::DeleteFirstPageOfThisPdfFile.new('path_to_the_pdf_file/goes_in_here.pdf')
156
+
157
+ or shorter:
158
+
159
+ require 'pdf_paradise'
160
+
161
+ PdfParadise.delete_first_page_of_this_pdf_file('foobar.pdf')
162
+
163
+ ## Converting markdown .md files to .pdf files
164
+
165
+ If you use kramdown, prawn and kramdown-pdf-converter, then you
166
+ can convert .md files on the commandline, via:
167
+
168
+ convert_markdown_to_pdf path_to_pdf_file_goes_here.pdf
169
+
170
+ Install the necessary gems prior to using this commandline
171
+ functionality.
172
+
173
+ ## sinatra interface
174
+
175
+ Since as of April 2019 there is a minimal sinatra interface to the
176
+ PdfParadise project. Consider this incomplete <b>work-in-progress</b>.
177
+
178
+ To start it, try:
179
+
180
+ pdf_paradise --sinatra
181
+
182
+ ## Querying the title of a .pdf file
183
+
184
+ <b>class PdfParadise::QueryPdfTitle</b> will report the title of
185
+ any .pdf file that is passed into it, on the commandline.
186
+
187
+ This currently depends on <b>exiftool</b> but at a later time,
188
+ this may change to also allow a query via prawn or other tools.
189
+
190
+ If you need to determine whether a given .pdf file has a title
191
+ or whether it does not, you can use
192
+ <b>PdfParadise.does_this_pdf_file_have_a_title?</b>, such
193
+ as in:
194
+
195
+ PdfParadise.does_this_pdf_file_have_a_title? "foobar.pdf" # => true
196
+
197
+ This method will return **true** if the .pdf file at hand has a
198
+ title; and **false** otherwise.
199
+
200
+ ## Determining how many pages a given .pdf file has
201
+
202
+ class **PdfParadise::PdfFileNTotalPages** can be used to query
203
+ how many pages a given .pdf file has.
204
+
205
+ The executable called **bin/n_pages** (thus, **n_pages**) can
206
+ be used to query this, on the commandline.
207
+
208
+ Example:
209
+
210
+ n_pages foobar.pdf
211
+
212
+ Do note that the class requires the external program
213
+ called **pdfinfo**.
214
+
215
+ It is possible to query the number of pages in a given .pdf
216
+ file without **pdfinfo**, but some .pdf files are a bit buggy,
217
+ and **pdfinfo** is simply more reliable than the regex that
218
+ was used until March 2020. So, past March 2020, the program
219
+ **pdfinfo** is now used by default. Note that pdfinfo is
220
+ part of the poppler software suite.
221
+
222
+ You can also use the following toplevel API for this:
223
+
224
+ PdfParadise.n_pages? 'THE_PATH_TO_THE_PDF_FILE_GOES_IN_HERE.pdf'
225
+ PdfParadise.n_pages? 'foobar.pdf'
226
+
227
+ ## Splitting a single pdf file into individual several .pdf files
228
+
229
+ You can use the following toplevel API to split up a single
230
+ .pdf file into several .pdf files:
231
+
232
+ PdfParadise.burst(ARGV)
233
+ PdfParadise.burst('foobar.pdf')
234
+
235
+ ## Adding page numbers to .pdf files
236
+
237
+ Via the combine_pdf gem it is now possible to add page numbers
238
+ to .pdf files. This has a few limitations for complex .pdf files,
239
+ due to combine_pdf having limitations in turn - but for simple
240
+ .pdf files this should work really well.
241
+
242
+ How to use that functionality?
243
+
244
+ Consider using the following toplevel API:
245
+
246
+ PdfParadise.number_pages('this_file.pdf')
247
+
248
+ The file called **this_file.pdf** has to exist in order for
249
+ this to work, of course.
250
+
251
+ The current default is to display the page numbers on the bottom
252
+ right side. This is hardcoded, but you could modify the code
253
+ to adapt to your needs; see also how combine_pdf does this.
254
+ (You have to pass an option-hash.)
255
+
256
+ ## Compressing a .pdf file (optizime the size of a .pdf file)
257
+
258
+ Sometimes you may have to reduce the filesize of a .pdf file,
259
+ such as when you need to upload a .pdf file, and there is
260
+ some file size limit otherwise.
261
+
262
+ So, let us now assume that you **do** have a use case - you
263
+ want to reduce the file size of a given .pdf file at hand.
264
+
265
+ How can this be done?
266
+
267
+ Well, there are several ways, but for the time being, only
268
+ one way will be documented here - which is the one that
269
+ requires **ghostscript**.
270
+
271
+ The important parameter is the **dPDFSETTINGS** one. This
272
+ one will determine the compression level, which ultimately
273
+ will affect the quality of the compressed .pdf file.
274
+
275
+ class **PdfParadise::CompressThisPdfFile** can be of
276
+ help here. Simply pass, as argument to .new(), the path
277
+ of the local .pdf to that class.
278
+
279
+ You can also use a toplevel method if you'd like to:
280
+
281
+ require 'pdf_paradise'
282
+ PdfParadise.compress_this_pdf_file
283
+ PdfParadise.compress_this_pdf_file('/foobar.pdf')
284
+
285
+ ## Merging pdf files
286
+
287
+ class PdfParadise::MergePdf.new(ARGV) can be used for
288
+ merging .pdf files.
289
+
290
+ Currently <b>ghostscript</b> and <b>hexapdf</b> can be used for the
291
+ merging step.
292
+
293
+ Examples for both variants:
294
+
295
+ mergepdf one.pdf two.pdf --use-ghostscript
296
+ mergepdf one.pdf two.pdf --use-hexapdf
297
+
298
+ (The two -- hyphen are mandatory for commandline arguments;
299
+ otherwise it is assumed to be a locally existing .pdf file.)
300
+
301
+ ## GUI component of the PdfParadise project
302
+
303
+ The PdfParadise project comes with some ruby-gtk3 specific
304
+ GUIs, but a few ruby-gtk2 and ruby-tk bindings may exist
305
+ as well. The gtk3 parts are the main GUI parts of this
306
+ project though.
307
+
308
+ You can start, from the commandline, the gtk-wrapper
309
+ over the **split_pdf_file** functionality.
310
+
311
+ In order to do this, do either one of the following:
312
+
313
+ pdf_paradise --gui
314
+ pdf_paradise --gtk
315
+
316
+ This will require the **gtk_paradise** project and the gtk
317
+ bindings, so quite a lot. **gem install gtk3** and
318
+ **gem install gtk_paradise** should help.
319
+
320
+ The GUI for class SplitPdfFile is called **PdfParadise::Gtk::SplitPdfFile**.
321
+ The idea behind it is to allow you to determine some of the parameters
322
+ in a graphical fashion.
323
+
324
+ Since as of **September 2019**, there is also a mini-widget for quickly
325
+ removing the first page of a .pdf file. This is really minimal right
326
+ now and not very elegant; it may be improved in the future, but for
327
+ the time being it is what it is. It is more a proof-of-concept that
328
+ it can work.
329
+
330
+ You can start this via:
331
+
332
+ require 'pdf_paradise/gui/gtk2/remove_first_page_of_pdf_file.rb'
333
+
334
+ PdfParadise.start_gtk_gui_remove_first_page_of_pdf_file
335
+
336
+ Note that as of **January 2021** the gtk bindings will default to
337
+ **ruby-gtk3**. Support for ruby-gtk2 will be retained, though,
338
+ but new code may not necessarily be written for ruby-gtk2 in
339
+ mind. ruby-gtk3 is now the main GUI target for this project.
340
+
341
+ I am slowly porting the individual widgets.
342
+
343
+ The following widgets have been ported so far:
344
+
345
+ PdfParadise::GUI::Gtk::StatisticsWidget # can be found under pdf_paradise/gui/gtk3/statistics_widget/statistics_widget.rb
346
+
347
+
348
+ ADD_CONTACT_INFORMATION
data/doc/todo/todo.md ADDED
@@ -0,0 +1,2 @@
1
+ - Add a converter-GUI.
2
+ From .docx to .pdf via libreoffice.
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'pdf_paradise/requires/require_the_whole_project.rb'
@@ -0,0 +1,173 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'pdf_paradise/base/base.rb'; < ::PdfParadise::Base
6
+ # =========================================================================== #
7
+ require 'pdf_paradise/requires/colours_and_esystem_and_save_file_and_fileutils_and_opn.rb'
8
+
9
+ module PdfParadise
10
+
11
+ class Base # === PdfParadise::Base
12
+
13
+ require 'pdf_paradise/toplevel_methods/roebe.rb'
14
+ require 'pdf_paradise/constants/constants.rb'
15
+
16
+ include Colours
17
+
18
+ begin
19
+ require 'cliner'
20
+ rescue LoadError; end
21
+
22
+ begin
23
+ require 'save_file/module'
24
+ rescue LoadError; end
25
+
26
+ # ========================================================================= #
27
+ # === NAMESPACE
28
+ # ========================================================================= #
29
+ NAMESPACE = inspect
30
+
31
+ # ========================================================================= #
32
+ # === initialize
33
+ # ========================================================================= #
34
+ def initialize
35
+ reset
36
+ end
37
+
38
+ # ========================================================================= #
39
+ # === opnn
40
+ # ========================================================================= #
41
+ def opnn(i = @namespace)
42
+ if i.is_a? String
43
+ i = { namespace: i}
44
+ end
45
+ Opn.opn(i)
46
+ end
47
+
48
+ # ========================================================================= #
49
+ # === reset
50
+ # ========================================================================= #
51
+ def reset
52
+ end
53
+
54
+ # ========================================================================= #
55
+ # === write_what_into
56
+ # ========================================================================= #
57
+ def write_what_into(what, into)
58
+ SaveFile.write_what_into(what, into)
59
+ end; alias save_what_into write_what_into # === save_what_into
60
+
61
+ # ========================================================================= #
62
+ # === no_file_at
63
+ #
64
+ # This method (or its alias) can be used to notify the user that the
65
+ # given file does not exist at that given location (denoted by the
66
+ # argument called i).
67
+ # ========================================================================= #
68
+ def no_file_at(i)
69
+ e "No file called `#{sfile(i)}` exists at that target."
70
+ end; alias no_file_exists_at no_file_at # === no_file_exists_at
71
+
72
+ # ========================================================================= #
73
+ # === orange
74
+ # ========================================================================= #
75
+ def orange(i)
76
+ ::Colours.orange(i)
77
+ end
78
+
79
+ # ========================================================================= #
80
+ # === esystem
81
+ #
82
+ # Wrapper over Esystem.esystem().
83
+ # ========================================================================= #
84
+ def esystem(i)
85
+ Esystem.esystem(i)
86
+ end
87
+
88
+ # ========================================================================= #
89
+ # === is_on_roebe?
90
+ # ========================================================================= #
91
+ def is_on_roebe?
92
+ ::PdfParadise.is_on_roebe?
93
+ end
94
+
95
+ # ========================================================================= #
96
+ # === set_commandline_arguments
97
+ # ========================================================================= #
98
+ def set_commandline_arguments(i)
99
+ i = [i].flatten.compact
100
+ @commandline_arguments = i
101
+ end
102
+
103
+ # ========================================================================= #
104
+ # === return_files_from_the_commandline_arguments
105
+ #
106
+ # This method will return all existing files from the commandline
107
+ # arguments.
108
+ # ========================================================================= #
109
+ def return_files_from_the_commandline_arguments
110
+ @commandline_arguments.select {|entry|
111
+ File.file?(entry.to_s)
112
+ }
113
+ end
114
+
115
+ # ========================================================================= #
116
+ # === mv (mv tag, move tag, rename tag)
117
+ # ========================================================================= #
118
+ def mv(old, new)
119
+ # ======================================================================= #
120
+ # We must check that both files exist, before we delete the new file,
121
+ # as we may otherwise end up without any .pdf file. This has happened
122
+ # to me in August 2019 when qpdf failed to do a conversion.
123
+ # ======================================================================= #
124
+ if File.file?(new) and File.file?(old)
125
+ File.delete(new)
126
+ end
127
+ if File.exist? old
128
+ FileUtils.mv(old, new)
129
+ else
130
+ e 'No file exists at '+sfile(old)+'.'
131
+ end
132
+ end; alias move_file mv # === move_file
133
+
134
+ # ========================================================================= #
135
+ # === return_pwd
136
+ # ========================================================================= #
137
+ def return_pwd
138
+ "#{Dir.pwd}/".squeeze('/')
139
+ end
140
+
141
+ # ========================================================================= #
142
+ # === commandline_arguments?
143
+ # ========================================================================= #
144
+ def commandline_arguments?
145
+ @commandline_arguments
146
+ end; alias input? commandline_arguments? # === input?
147
+
148
+ # ========================================================================= #
149
+ # === first_argument?
150
+ # ========================================================================= #
151
+ def first_argument?
152
+ @commandline_arguments.first
153
+ end
154
+
155
+ # ========================================================================= #
156
+ # === input_without_leading_hyphens?
157
+ #
158
+ # This method will return the input that will not begin with --.
159
+ # ========================================================================= #
160
+ def input_without_leading_hyphens?
161
+ @commandline_arguments.reject {|entry| entry.start_with? '--' }
162
+ end
163
+
164
+ # ========================================================================= #
165
+ # === return_commandline_arguments_starting_with_hyphens
166
+ # ========================================================================= #
167
+ def return_commandline_arguments_starting_with_hyphens(
168
+ i = @commandline_arguments
169
+ )
170
+ i.select {|entry| entry.start_with? '--' }
171
+ end; alias return_hyphen_arguments return_commandline_arguments_starting_with_hyphens # === return_hyphen_arguments
172
+
173
+ end; end