pdf_paradise 0.1.20

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 (96) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +295 -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 +278 -0
  13. data/lib/pdf_paradise.rb +5 -0
  14. data/lib/pdf_paradise/base/base.rb +173 -0
  15. data/lib/pdf_paradise/commandline/help.rb +69 -0
  16. data/lib/pdf_paradise/commandline/menu.rb +154 -0
  17. data/lib/pdf_paradise/compress_this_pdf_file.rb +82 -0
  18. data/lib/pdf_paradise/constants/constants.rb +58 -0
  19. data/lib/pdf_paradise/convert_pdf_to_text.rb +124 -0
  20. data/lib/pdf_paradise/convert_text_to_pdf.rb +94 -0
  21. data/lib/pdf_paradise/djvu_to_pdf.rb +85 -0
  22. data/lib/pdf_paradise/extract_pdf_page.rb +278 -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/notebook_panel.rb +125 -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/delete_the_first_or_the_last_page_of_this_pdf_file/delete_the_first_or_the_last_page_of_this_pdf_file.rb +39 -0
  31. data/lib/pdf_paradise/gui/gtk3/pdf_viewer/pdf_viewer.rb +34 -0
  32. data/lib/pdf_paradise/gui/gtk3/split_pdf_file/split_pdf_file.rb +34 -0
  33. data/lib/pdf_paradise/gui/gtk3/statistics_widget/statistics_widget.rb +34 -0
  34. data/lib/pdf_paradise/gui/gtk3/to_pdf/to_pdf.rb +32 -0
  35. 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.css +0 -0
  36. 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 +339 -0
  37. data/lib/pdf_paradise/gui/shared_code/pdf_viewer/pdf_viewer.css +5 -0
  38. data/lib/pdf_paradise/gui/shared_code/pdf_viewer/pdf_viewer_module.rb +219 -0
  39. data/lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file.css +0 -0
  40. data/lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb +297 -0
  41. data/lib/pdf_paradise/gui/shared_code/statistics_widget/statistics_widget.css +0 -0
  42. data/lib/pdf_paradise/gui/shared_code/statistics_widget/statistics_widget_module.rb +205 -0
  43. data/lib/pdf_paradise/gui/shared_code/to_pdf/to_pdf.css +0 -0
  44. data/lib/pdf_paradise/gui/shared_code/to_pdf/to_pdf_module.rb +148 -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/pdf_optimizer.rb +112 -0
  52. data/lib/pdf_paradise/pdf_statistics.rb +148 -0
  53. data/lib/pdf_paradise/project/project_base_directory.rb +22 -0
  54. data/lib/pdf_paradise/remove_images.rb +105 -0
  55. data/lib/pdf_paradise/remove_pdf_password.rb +392 -0
  56. data/lib/pdf_paradise/requires/batch_require_toplevel_files.rb +22 -0
  57. data/lib/pdf_paradise/requires/colours.rb +7 -0
  58. data/lib/pdf_paradise/requires/colours_and_esystem_and_save_file_and_fileutils_and_opn.rb +11 -0
  59. data/lib/pdf_paradise/requires/esystem_and_colours.rb +10 -0
  60. data/lib/pdf_paradise/requires/esystem_and_opn_and_colours.rb +8 -0
  61. data/lib/pdf_paradise/requires/require_the_whole_project.rb +24 -0
  62. data/lib/pdf_paradise/requires/require_utility_scripts.rb +7 -0
  63. data/lib/pdf_paradise/rotate_pdf_file.rb +144 -0
  64. data/lib/pdf_paradise/set_main_book.rb +156 -0
  65. data/lib/pdf_paradise/set_pdf_title.rb +218 -0
  66. data/lib/pdf_paradise/split_pdf.rb +294 -0
  67. data/lib/pdf_paradise/toplevel_methods/automatic_pdf_title.rb +55 -0
  68. data/lib/pdf_paradise/toplevel_methods/convert_epub_to_pdf.rb +27 -0
  69. data/lib/pdf_paradise/toplevel_methods/convert_markdown_to_pdf.rb +43 -0
  70. data/lib/pdf_paradise/toplevel_methods/convert_ppt_to_pdf.rb +35 -0
  71. data/lib/pdf_paradise/toplevel_methods/e.rb +16 -0
  72. data/lib/pdf_paradise/toplevel_methods/esystem.rb +19 -0
  73. data/lib/pdf_paradise/toplevel_methods/misc.rb +52 -0
  74. data/lib/pdf_paradise/toplevel_methods/number_pages.rb +38 -0
  75. data/lib/pdf_paradise/toplevel_methods/opened_pdf_files.rb +191 -0
  76. data/lib/pdf_paradise/toplevel_methods/query_pdf_title.rb +182 -0
  77. data/lib/pdf_paradise/toplevel_methods/reduce_size_of_this_pdf_file.rb +43 -0
  78. data/lib/pdf_paradise/toplevel_methods/roebe.rb +17 -0
  79. data/lib/pdf_paradise/toplevel_methods/to_pdf.rb +38 -0
  80. data/lib/pdf_paradise/utility_scripts/README.md +3 -0
  81. data/lib/pdf_paradise/utility_scripts/delete_first_page_of_this_pdf_file.rb +185 -0
  82. data/lib/pdf_paradise/utility_scripts/delete_last_page_of_this_pdf_file.rb +180 -0
  83. data/lib/pdf_paradise/utility_scripts/delete_this_page_of_this_pdf_file.rb +269 -0
  84. data/lib/pdf_paradise/utility_scripts/to_qdf.rb +82 -0
  85. data/lib/pdf_paradise/version/version.rb +19 -0
  86. data/lib/pdf_paradise/www/README.md +2 -0
  87. data/lib/pdf_paradise/www/sinatra/app.rb +254 -0
  88. data/lib/pdf_paradise/www/sinatra/autoconvert.rb +30 -0
  89. data/lib/pdf_paradise/www/sinatra/base.rb +33 -0
  90. data/lib/pdf_paradise/www/sinatra/convert_single_pdf_file.rb +44 -0
  91. data/lib/pdf_paradise/www/sinatra/n_pdf_pages.rb +50 -0
  92. data/lib/pdf_paradise/www/sinatra/title.rb +56 -0
  93. data/lib/pdf_paradise/www/sinatra/view.rb +78 -0
  94. data/pdf_paradise.gemspec +70 -0
  95. data/test/testing_pdf_paradise.rb +9 -0
  96. metadata +220 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 26fa34ecee3a5b73b46f3452482dbd7cfaa2d4eba5b9d97b510d5a7996e80ffc
4
+ data.tar.gz: e9e58910ea1b4641f74472f5c5df1a017f7d412e462e1dc599dafb18e669e503
5
+ SHA512:
6
+ metadata.gz: 176c5591ce45e2830ebaa12def4dbb665b53ab71e0645bb1b6e694592398d53e54eb116b3e443d0ddf32e697443c4be1c13bc7e3a6ddc145b4f27a8d7468d518
7
+ data.tar.gz: 6000c8bf3cd65f3c863e9ebe7ea37063aa54de779e445b2d8487e7eb101ebd3537b9d29fea95602696b35b436a466377f42495dfb66a3ff477eb0a4ca7963285
data/README.md ADDED
@@ -0,0 +1,295 @@
1
+ [![forthebadge](http://forthebadge.com/images/badges/built-with-love.svg)](https://www.gobolinux.org/)
2
+ [![forthebadge](http://forthebadge.com/images/badges/made-with-ruby.svg)](https://www.ruby-lang.org/en/)
3
+ [![Gem Version](https://badge.fury.io/rb/pdf_paradise.svg)](https://badge.fury.io/rb/pdf_paradise)
4
+
5
+ This project can help with pdf-related functions. For example, merging
6
+ .pdf files, splitting .pdf files, setting the title and similar
7
+ activities.
8
+
9
+ The project has to remain flexible. We may use external programs
10
+ such as **ghoscript**, or we may use pure ruby solutions, such
11
+ as via the gem called **combine_pdf**.
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
+ ## Converting a .pdf file to text
18
+
19
+ Sometimes you may wish to have a text-file describing the content
20
+ of a .pdf file, rather than the .pdf file itself.
21
+
22
+ Via the class **ConvertPdfToText**, residing in the file at
23
+ **pdf_paradise/convert_pdf_to_text.rb**, you can convert a .pdf
24
+ file to a text file.
25
+
26
+ Usage example from ruby, for the file called **foobar.pdf**:
27
+
28
+ PdfParadise::ConvertPdfToText.new(ARGV)
29
+ PdfParadise::ConvertPdfToText.new('foobar.pdf')
30
+
31
+ You can also use the bin/ file from the commandline:
32
+
33
+ convert_pdf_to_text
34
+ convert_pdf_to_text foobar.pdf
35
+
36
+ ## Commandline usage
37
+
38
+ You can use the **pdf_paradise** gem from the commandline, as
39
+ the example above shows.
40
+
41
+ For instance, say that you wish to modify **the title of a .pdf
42
+ file**, you can use a commandline invocation such as via
43
+ this way:
44
+
45
+ pdf_paradise --use-this-pdf-file=location_to_your_pdf_file.pdf --set_title="The title you want to use goes in here."
46
+
47
+ You can also **shrink** a .pdf file, by using the commandline
48
+ switch <b>--shrink-pdf-size-of=foobar.pdf</b> or just
49
+ <b>--shrink</b>, such as:
50
+
51
+ pdf_paradise --shrink-pdf-size-of=foobar.pdf
52
+ pdf_paradise --shrink=foobar.pdf
53
+
54
+ The <b>shrink</b> functionality is contained in the module-method
55
+ <b>PdfParadise.reduce_size_of_this_pdf_file()</b>.
56
+
57
+ ## Storing the .pdf pages that are currently open
58
+
59
+ If you need to store the .pdf files that are currently open,
60
+ you can use the following commandline to do so:
61
+
62
+ pdfparadise --store-open-pdf-files
63
+
64
+ This will attempt to store the full path to the .pdf files
65
+ into a local file. That way you may also be able to batch-open
66
+ these .pdf files at a later time, e. g. when you switch your
67
+ window manager or after a reboot.
68
+
69
+ ## Deleting the last or the first page of a .pdf file
70
+
71
+ You can use **class DeleteLastPageOfThisPdfFile**, more
72
+ accurately called **class PdfParadise::DeleteLastPageOfThisPdfFile**,
73
+ to ***delete the last page in a .pdf file***.
74
+
75
+ In ruby code, you can invoke this like so:
76
+
77
+ require 'pdf_paradise'
78
+
79
+ PdfParadise::DeleteLastPageOfThisPdfFile.new('path_to_the_pdf_file/goes_in_here.pdf')
80
+
81
+ or shorter:
82
+
83
+ require 'pdf_paradise'
84
+
85
+ PdfParadise.delete_last_page_of_this_pdf_file('foobar.pdf')
86
+
87
+ A very similar API exists for deleting the first page of a given .pdf
88
+ file, too.
89
+
90
+ See:
91
+
92
+ In ruby code, you can invoke this like so:
93
+
94
+ require 'pdf_paradise'
95
+
96
+ PdfParadise::DeleteFirstPageOfThisPdfFile.new('path_to_the_pdf_file/goes_in_here.pdf')
97
+
98
+ or shorter:
99
+
100
+ require 'pdf_paradise'
101
+
102
+ PdfParadise.delete_first_page_of_this_pdf_file('foobar.pdf')
103
+
104
+ ## Converting markdown .md files to .pdf files
105
+
106
+ If you use kramdown, prawn and kramdown-pdf-converter, then you
107
+ can convert .md files on the commandline, via:
108
+
109
+ convert_markdown_to_pdf path_to_pdf_file_goes_here.pdf
110
+
111
+ Install the necessary gems prior to using this commandline
112
+ functionality.
113
+
114
+ ## sinatra interface
115
+
116
+ Since as of April 2019 there is a minimal sinatra interface to the
117
+ PdfParadise project. Consider this incomplete <b>work-in-progress</b>.
118
+
119
+ To start it, try:
120
+
121
+ pdf_paradise --sinatra
122
+
123
+ ## Querying the title of a .pdf file
124
+
125
+ <b>class PdfParadise::QueryPdfTitle</b> will report the title of
126
+ any .pdf file that is passed into it, on the commandline.
127
+
128
+ This currently depends on <b>exiftool</b> but at a later time,
129
+ this may change to also allow a query via prawn or other tools.
130
+
131
+ If you need to determine whether a given .pdf file has a title
132
+ or whether it does not, you can use
133
+ <b>PdfParadise.does_this_pdf_file_have_a_title?</b>, such
134
+ as in:
135
+
136
+ PdfParadise.does_this_pdf_file_have_a_title? "foobar.pdf" # => true
137
+
138
+ This method will return **true** if the .pdf file at hand has a
139
+ title; and **false** otherwise.
140
+
141
+ ## Determining how many pages a given .pdf file has
142
+
143
+ class **PdfParadise::PdfFileNTotalPages** can be used to query
144
+ how many pages a given .pdf file has.
145
+
146
+ The executable called **bin/n_pages** (thus, **n_pages**) can
147
+ be used to query this, on the commandline.
148
+
149
+ Example:
150
+
151
+ n_pages foobar.pdf
152
+
153
+ Do note that the class requires the external program
154
+ called **pdfinfo**.
155
+
156
+ It is possible to query the number of pages in a given .pdf
157
+ file without **pdfinfo**, but some .pdf files are a bit buggy,
158
+ and **pdfinfo** is simply more reliable than the regex that
159
+ was used until March 2020. So, past March 2020, the program
160
+ **pdfinfo** is now used by default. Note that pdfinfo is
161
+ part of the poppler software suite.
162
+
163
+ You can also use the following toplevel API for this:
164
+
165
+ PdfParadise.n_pages? 'THE_PATH_TO_THE_PDF_FILE_GOES_IN_HERE.pdf'
166
+ PdfParadise.n_pages? 'foobar.pdf'
167
+
168
+ ## Splitting a single pdf file into individual several .pdf files
169
+
170
+ You can use the following toplevel API to split up a single
171
+ .pdf file into several .pdf files:
172
+
173
+ PdfParadise.burst(ARGV)
174
+ PdfParadise.burst('foobar.pdf')
175
+
176
+ ## Adding page numbers to .pdf files
177
+
178
+ Via the combine_pdf gem it is now possible to add page numbers
179
+ to .pdf files. This has a few limitations for complex .pdf files,
180
+ due to combine_pdf having limitations in turn - but for simple
181
+ .pdf files this should work really well.
182
+
183
+ How to use that functionality?
184
+
185
+ Consider using the following toplevel API:
186
+
187
+ PdfParadise.number_pages('this_file.pdf')
188
+
189
+ The file called **this_file.pdf** has to exist in order for
190
+ this to work, of course.
191
+
192
+ The current default is to display the page numbers on the bottom
193
+ right side. This is hardcoded, but you could modify the code
194
+ to adapt to your needs; see also how combine_pdf does this.
195
+ (You have to pass an option-hash.)
196
+
197
+ ## Compressing a .pdf file (optizime the size of a .pdf file)
198
+
199
+ Sometimes you may have to reduce the filesize of a .pdf file,
200
+ such as when you need to upload a .pdf file, and there is
201
+ some file size limit otherwise.
202
+
203
+ So, let us now assume that you **do** have a use case - you
204
+ want to reduce the file size of a given .pdf file at hand.
205
+
206
+ How can this be done?
207
+
208
+ Well, there are several ways, but for the time being, only
209
+ one way will be documented here - which is the one that
210
+ requires **ghostscript**.
211
+
212
+ The important parameter is the **dPDFSETTINGS** one. This
213
+ one will determine the compression level, which ultimately
214
+ will affect the quality of the compressed .pdf file.
215
+
216
+ class **PdfParadise::CompressThisPdfFile** can be of
217
+ help here. Simply pass, as argument to .new(), the path
218
+ of the local .pdf to that class.
219
+
220
+ You can also use a toplevel method if you'd like to:
221
+
222
+ require 'pdf_paradise'
223
+ PdfParadise.compress_this_pdf_file
224
+ PdfParadise.compress_this_pdf_file('/foobar.pdf')
225
+
226
+ ## Merging pdf files
227
+
228
+ class PdfParadise::MergePdf.new(ARGV) can be used for
229
+ merging .pdf files.
230
+
231
+ Currently ghostscript and hexapdf can be used for the merging.
232
+
233
+ Example:
234
+
235
+ mergepdf one.pdf two.pdf --use-ghostscript
236
+ mergepdf one.pdf two.pdf --use-hexapdf
237
+
238
+ (The two -- hyphen are mandatory for commandline arguments;
239
+ otherwise it is assumed to be a locally existing .pdf file.)
240
+
241
+ ## GUI component of the PdfParadise project
242
+
243
+ You can start, from the commandline, a gtk2-wrapper over
244
+ the split_pdf_file functionality.
245
+
246
+ In order to do this, do either one of the following:
247
+
248
+ pdf_paradise --gui
249
+ pdf_paradise --gtk
250
+
251
+ This will require the **gtk_module** and the gtk2 bindings, so quite
252
+ a lot. **gem install gtk2** and **gem install gtk_module** should
253
+ help.
254
+
255
+ The GUI for class SplitPdfFile is called **PdfParadise::Gtk::SplitPdfFile**.
256
+ The idea behind it is to allow you to determine some of the parameters
257
+ in a graphical fashion.
258
+
259
+ Since as of September 2019, there is also a mini-widget for quickly
260
+ removing the first page of a .pdf file. This is really minimal right
261
+ now and not very elegant; it may be improved in the future, but for
262
+ the time being it is what it is. It is more a proof-of-concept that
263
+ it can work.
264
+
265
+ You can start this via:
266
+
267
+ require 'pdf_paradise/gui/gtk2/remove_first_page_of_pdf_file.rb'
268
+
269
+ PdfParadise.start_gtk_gui_remove_first_page_of_pdf_file
270
+
271
+ Note that as of **January 2021** the gtk bindings will default to
272
+ ruby-gtk3. Support for ruby-gtk2 will be retained, though.
273
+
274
+ I am slowly porting the individual widgets.
275
+
276
+ The following widgets have been ported so far:
277
+
278
+ PdfParadise::GUI::Gtk::StatisticsWidget # can be found under pdf_paradise/gui/gtk3/statistics_widget/statistics_widget.rb
279
+
280
+
281
+ ## Contact information
282
+
283
+ If your creative mind has ideas and specific suggestions to make this
284
+ gem more useful in general, feel free to drop me an email at any
285
+ time, via:
286
+
287
+ shevegen@gmail.com
288
+
289
+ (Do keep in mind that responding to emails may take some time, depending
290
+ on the amount of work I may have at that moment, due to reallife. I will,
291
+ however had, read feedback. Patches and code changes are welcome too
292
+ of course, as long as they are in the spirit of the project at
293
+ hand, e. g. fitting to the general theme.)
294
+
295
+ Thank you.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'pdf_paradise/toplevel_methods/automatic_pdf_title.rb'
6
+
7
+ PdfParadise.automatic_pdf_title(ARGV)
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'pdf_paradise/toplevel_methods/convert_markdown_to_pdf.rb'
6
+
7
+ PdfParadise.convert_markdown_to_pdf(ARGV)
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'pdf_paradise/convert_pdf_to_text.rb'
6
+
7
+ PdfParadise::ConvertPdfToText.new(ARGV)
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'pdf_paradise/merge_then_open/merge_then_open.rb'
6
+
7
+ PdfParadise::MergeThenOpen.new(ARGV)
data/bin/n_pages ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # This file can be used to determine the number of pages in a given
6
+ # .pdf file.
7
+ # =========================================================================== #
8
+ require 'pdf_paradise/pdf_file_n_total_pages.rb'
9
+
10
+ PdfParadise::PdfFileNTotalPages.new(ARGV)
data/bin/open_main_pdf ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'pdf_paradise/main_pdf/main_pdf.rb'
6
+
7
+ PdfParadise::MainPdf.new('--open-main-pdf')
data/bin/pdf_paradise ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'pdf_paradise/commandline/menu.rb'
6
+
7
+ PdfParadise.menu(ARGV)
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,278 @@
1
+ ADD_RUBY_HEADER
2
+
3
+ This project can help with pdf-related functions. For example, merging
4
+ .pdf files, splitting .pdf files, setting the title and similar
5
+ activities.
6
+
7
+ The project has to remain flexible. We may use external programs
8
+ such as **ghoscript**, or we may use pure ruby solutions, such
9
+ as via the gem called **combine_pdf**.
10
+
11
+ The file here (README.gen, respectively the generated file called
12
+ **README.md**), will describe some of the components that make
13
+ up this gem.
14
+
15
+ ## Converting a .pdf file to text
16
+
17
+ Sometimes you may wish to have a text-file describing the content
18
+ of a .pdf file, rather than the .pdf file itself.
19
+
20
+ Via the class **ConvertPdfToText**, residing in the file at
21
+ **pdf_paradise/convert_pdf_to_text.rb**, you can convert a .pdf
22
+ file to a text file.
23
+
24
+ Usage example from ruby, for the file called **foobar.pdf**:
25
+
26
+ PdfParadise::ConvertPdfToText.new(ARGV)
27
+ PdfParadise::ConvertPdfToText.new('foobar.pdf')
28
+
29
+ You can also use the bin/ file from the commandline:
30
+
31
+ convert_pdf_to_text
32
+ convert_pdf_to_text foobar.pdf
33
+
34
+ ## Commandline usage
35
+
36
+ You can use the **pdf_paradise** gem from the commandline, as
37
+ the example above shows.
38
+
39
+ For instance, say that you wish to modify **the title of a .pdf
40
+ file**, you can use a commandline invocation such as via
41
+ this way:
42
+
43
+ pdf_paradise --use-this-pdf-file=location_to_your_pdf_file.pdf --set_title="The title you want to use goes in here."
44
+
45
+ You can also **shrink** a .pdf file, by using the commandline
46
+ switch <b>--shrink-pdf-size-of=foobar.pdf</b> or just
47
+ <b>--shrink</b>, such as:
48
+
49
+ pdf_paradise --shrink-pdf-size-of=foobar.pdf
50
+ pdf_paradise --shrink=foobar.pdf
51
+
52
+ The <b>shrink</b> functionality is contained in the module-method
53
+ <b>PdfParadise.reduce_size_of_this_pdf_file()</b>.
54
+
55
+ ## Storing the .pdf pages that are currently open
56
+
57
+ If you need to store the .pdf files that are currently open,
58
+ you can use the following commandline to do so:
59
+
60
+ pdfparadise --store-open-pdf-files
61
+
62
+ This will attempt to store the full path to the .pdf files
63
+ into a local file. That way you may also be able to batch-open
64
+ these .pdf files at a later time, e. g. when you switch your
65
+ window manager or after a reboot.
66
+
67
+ ## Deleting the last or the first page of a .pdf file
68
+
69
+ You can use **class DeleteLastPageOfThisPdfFile**, more
70
+ accurately called **class PdfParadise::DeleteLastPageOfThisPdfFile**,
71
+ to ***delete the last page in a .pdf file***.
72
+
73
+ In ruby code, you can invoke this like so:
74
+
75
+ require 'pdf_paradise'
76
+
77
+ PdfParadise::DeleteLastPageOfThisPdfFile.new('path_to_the_pdf_file/goes_in_here.pdf')
78
+
79
+ or shorter:
80
+
81
+ require 'pdf_paradise'
82
+
83
+ PdfParadise.delete_last_page_of_this_pdf_file('foobar.pdf')
84
+
85
+ A very similar API exists for deleting the first page of a given .pdf
86
+ file, too.
87
+
88
+ See:
89
+
90
+ In ruby code, you can invoke this like so:
91
+
92
+ require 'pdf_paradise'
93
+
94
+ PdfParadise::DeleteFirstPageOfThisPdfFile.new('path_to_the_pdf_file/goes_in_here.pdf')
95
+
96
+ or shorter:
97
+
98
+ require 'pdf_paradise'
99
+
100
+ PdfParadise.delete_first_page_of_this_pdf_file('foobar.pdf')
101
+
102
+ ## Converting markdown .md files to .pdf files
103
+
104
+ If you use kramdown, prawn and kramdown-pdf-converter, then you
105
+ can convert .md files on the commandline, via:
106
+
107
+ convert_markdown_to_pdf path_to_pdf_file_goes_here.pdf
108
+
109
+ Install the necessary gems prior to using this commandline
110
+ functionality.
111
+
112
+ ## sinatra interface
113
+
114
+ Since as of April 2019 there is a minimal sinatra interface to the
115
+ PdfParadise project. Consider this incomplete <b>work-in-progress</b>.
116
+
117
+ To start it, try:
118
+
119
+ pdf_paradise --sinatra
120
+
121
+ ## Querying the title of a .pdf file
122
+
123
+ <b>class PdfParadise::QueryPdfTitle</b> will report the title of
124
+ any .pdf file that is passed into it, on the commandline.
125
+
126
+ This currently depends on <b>exiftool</b> but at a later time,
127
+ this may change to also allow a query via prawn or other tools.
128
+
129
+ If you need to determine whether a given .pdf file has a title
130
+ or whether it does not, you can use
131
+ <b>PdfParadise.does_this_pdf_file_have_a_title?</b>, such
132
+ as in:
133
+
134
+ PdfParadise.does_this_pdf_file_have_a_title? "foobar.pdf" # => true
135
+
136
+ This method will return **true** if the .pdf file at hand has a
137
+ title; and **false** otherwise.
138
+
139
+ ## Determining how many pages a given .pdf file has
140
+
141
+ class **PdfParadise::PdfFileNTotalPages** can be used to query
142
+ how many pages a given .pdf file has.
143
+
144
+ The executable called **bin/n_pages** (thus, **n_pages**) can
145
+ be used to query this, on the commandline.
146
+
147
+ Example:
148
+
149
+ n_pages foobar.pdf
150
+
151
+ Do note that the class requires the external program
152
+ called **pdfinfo**.
153
+
154
+ It is possible to query the number of pages in a given .pdf
155
+ file without **pdfinfo**, but some .pdf files are a bit buggy,
156
+ and **pdfinfo** is simply more reliable than the regex that
157
+ was used until March 2020. So, past March 2020, the program
158
+ **pdfinfo** is now used by default. Note that pdfinfo is
159
+ part of the poppler software suite.
160
+
161
+ You can also use the following toplevel API for this:
162
+
163
+ PdfParadise.n_pages? 'THE_PATH_TO_THE_PDF_FILE_GOES_IN_HERE.pdf'
164
+ PdfParadise.n_pages? 'foobar.pdf'
165
+
166
+ ## Splitting a single pdf file into individual several .pdf files
167
+
168
+ You can use the following toplevel API to split up a single
169
+ .pdf file into several .pdf files:
170
+
171
+ PdfParadise.burst(ARGV)
172
+ PdfParadise.burst('foobar.pdf')
173
+
174
+ ## Adding page numbers to .pdf files
175
+
176
+ Via the combine_pdf gem it is now possible to add page numbers
177
+ to .pdf files. This has a few limitations for complex .pdf files,
178
+ due to combine_pdf having limitations in turn - but for simple
179
+ .pdf files this should work really well.
180
+
181
+ How to use that functionality?
182
+
183
+ Consider using the following toplevel API:
184
+
185
+ PdfParadise.number_pages('this_file.pdf')
186
+
187
+ The file called **this_file.pdf** has to exist in order for
188
+ this to work, of course.
189
+
190
+ The current default is to display the page numbers on the bottom
191
+ right side. This is hardcoded, but you could modify the code
192
+ to adapt to your needs; see also how combine_pdf does this.
193
+ (You have to pass an option-hash.)
194
+
195
+ ## Compressing a .pdf file (optizime the size of a .pdf file)
196
+
197
+ Sometimes you may have to reduce the filesize of a .pdf file,
198
+ such as when you need to upload a .pdf file, and there is
199
+ some file size limit otherwise.
200
+
201
+ So, let us now assume that you **do** have a use case - you
202
+ want to reduce the file size of a given .pdf file at hand.
203
+
204
+ How can this be done?
205
+
206
+ Well, there are several ways, but for the time being, only
207
+ one way will be documented here - which is the one that
208
+ requires **ghostscript**.
209
+
210
+ The important parameter is the **dPDFSETTINGS** one. This
211
+ one will determine the compression level, which ultimately
212
+ will affect the quality of the compressed .pdf file.
213
+
214
+ class **PdfParadise::CompressThisPdfFile** can be of
215
+ help here. Simply pass, as argument to .new(), the path
216
+ of the local .pdf to that class.
217
+
218
+ You can also use a toplevel method if you'd like to:
219
+
220
+ require 'pdf_paradise'
221
+ PdfParadise.compress_this_pdf_file
222
+ PdfParadise.compress_this_pdf_file('/foobar.pdf')
223
+
224
+ ## Merging pdf files
225
+
226
+ class PdfParadise::MergePdf.new(ARGV) can be used for
227
+ merging .pdf files.
228
+
229
+ Currently ghostscript and hexapdf can be used for the merging.
230
+
231
+ Example:
232
+
233
+ mergepdf one.pdf two.pdf --use-ghostscript
234
+ mergepdf one.pdf two.pdf --use-hexapdf
235
+
236
+ (The two -- hyphen are mandatory for commandline arguments;
237
+ otherwise it is assumed to be a locally existing .pdf file.)
238
+
239
+ ## GUI component of the PdfParadise project
240
+
241
+ You can start, from the commandline, a gtk2-wrapper over
242
+ the split_pdf_file functionality.
243
+
244
+ In order to do this, do either one of the following:
245
+
246
+ pdf_paradise --gui
247
+ pdf_paradise --gtk
248
+
249
+ This will require the **gtk_module** and the gtk2 bindings, so quite
250
+ a lot. **gem install gtk2** and **gem install gtk_module** should
251
+ help.
252
+
253
+ The GUI for class SplitPdfFile is called **PdfParadise::Gtk::SplitPdfFile**.
254
+ The idea behind it is to allow you to determine some of the parameters
255
+ in a graphical fashion.
256
+
257
+ Since as of September 2019, there is also a mini-widget for quickly
258
+ removing the first page of a .pdf file. This is really minimal right
259
+ now and not very elegant; it may be improved in the future, but for
260
+ the time being it is what it is. It is more a proof-of-concept that
261
+ it can work.
262
+
263
+ You can start this via:
264
+
265
+ require 'pdf_paradise/gui/gtk2/remove_first_page_of_pdf_file.rb'
266
+
267
+ PdfParadise.start_gtk_gui_remove_first_page_of_pdf_file
268
+
269
+ Note that as of **January 2021** the gtk bindings will default to
270
+ ruby-gtk3. Support for ruby-gtk2 will be retained, though.
271
+
272
+ I am slowly porting the individual widgets.
273
+
274
+ The following widgets have been ported so far:
275
+
276
+ PdfParadise::GUI::Gtk::StatisticsWidget # can be found under pdf_paradise/gui/gtk3/statistics_widget/statistics_widget.rb
277
+
278
+ ADD_CONTACT_INFORMATION