pdf_paradise 0.3.20

Sign up to get free protection for your applications and to get access to all the features.
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,130 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === PdfParadise::ToPdf
6
+ #
7
+ # Usage example:
8
+ #
9
+ # PdfParadise::ToPdf.new(ARGV)
10
+ #
11
+ # =========================================================================== #
12
+ # require 'pdf_paradise/utility_scripts/to_pdf.rb'
13
+ # =========================================================================== #
14
+ require 'pdf_paradise/base/base.rb'
15
+
16
+ module PdfParadise
17
+
18
+ class ToPdf < ::PdfParadise::Base # === PdfParadise::ToPdf
19
+
20
+ # ========================================================================= #
21
+ # === initialize
22
+ # ========================================================================= #
23
+ def initialize(
24
+ commandline_arguments = nil,
25
+ run_already = true
26
+ )
27
+ reset
28
+ set_commandline_arguments(
29
+ commandline_arguments
30
+ )
31
+ run if run_already
32
+ end
33
+
34
+ # ========================================================================= #
35
+ # === reset (reset tag)
36
+ # ========================================================================= #
37
+ def reset
38
+ super()
39
+ infer_the_namespace
40
+ end
41
+
42
+ # ========================================================================= #
43
+ # === run (run tag)
44
+ # ========================================================================= #
45
+ def run
46
+ commandline_arguments?.each {|entry|
47
+ if entry.end_with?('.docx','.pptx')
48
+ convert_this_docx_file(entry)
49
+ elsif File.directory?(entry)
50
+ handle_this_directory(File.absolute_path(entry))
51
+ else
52
+ opnn; e "Unsure what to do with #{steelblue(entry)}."
53
+ end
54
+ }
55
+ end
56
+
57
+ # ========================================================================= #
58
+ # === convert_this_docx_file
59
+ # ========================================================================= #
60
+ def convert_this_docx_file(i)
61
+ _ = "soffice --headless --invisible --convert-to pdf #{i}"
62
+ e _
63
+ system _
64
+ end
65
+
66
+ # ========================================================================= #
67
+ # === handle_this_directory
68
+ # ========================================================================= #
69
+ def handle_this_directory(i)
70
+ require 'image_paradise/toplevel_methods/misc.rb'
71
+ require 'pdf_paradise/merge_pdf/merge_pdf.rb'
72
+ i = i.dup
73
+ i << '/' unless i.end_with?('/')
74
+ e "#{rev}First, we will obtain all image files "\
75
+ "of the directory #{sdir(i)}:"
76
+ all_image_files = Dir["#{i}*"].select {|entry|
77
+ is_an_image_file?(entry)
78
+ }
79
+ result = all_image_files.map {|this_image_file|
80
+ this_image_file = ::ImageParadise.img2pdf(this_image_file)
81
+ this_image_file
82
+ }
83
+ e 'Next merging these generated files into a new .pdf file:'
84
+ merge_pdf = PdfParadise::MergePdf.new(result)
85
+ _ = merge_pdf.where_it_is_stored? # Call it manually.
86
+ opnn; e 'If everything worked well then the resulting '\
87
+ '.pdf file can'
88
+ opnn; e 'be found at: '+sfile(_)
89
+ end
90
+
91
+ # ========================================================================= #
92
+ # === PdfParadise::ToPdf[]
93
+ # ========================================================================= #
94
+ def self.[](i = ARGV)
95
+ new(i)
96
+ end
97
+
98
+ end
99
+
100
+ # =========================================================================== #
101
+ # === PdfParadise.to_pdf
102
+ #
103
+ # This method can, by using soffice, convert a file such as .docx into
104
+ # the corresponding .pdf file - all on the commandline.
105
+ # =========================================================================== #
106
+ def self.to_pdf(
107
+ these_pdf_files = ARGV
108
+ )
109
+ [these_pdf_files].flatten.compact.map {|this_pdf_file|
110
+ if File.exist? this_pdf_file
111
+ # ===================================================================== #
112
+ # The soffice binary must exist in order for this functionality
113
+ # to work.
114
+ # ===================================================================== #
115
+ _ = "soffice --headless --invisible --convert-to pdf #{this_pdf_file}"
116
+ e _
117
+ system _
118
+ this_pdf_file # Return the path here, in case it has to be used.
119
+ else
120
+ e "No file exists at `#{this_pdf_file}.`"
121
+ nil
122
+ end
123
+ }
124
+ end
125
+
126
+ end
127
+
128
+ if __FILE__ == $PROGRAM_NAME
129
+ PdfParadise::ToPdf.new(ARGV)
130
+ end # topdf
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === PdfParadise::ToQdf
6
+ #
7
+ # This class will convert a .pdf file into a .qdf file.
8
+ #
9
+ # Usage example:
10
+ #
11
+ # PdfParadise::ToQdf.new(ARGV)
12
+ #
13
+ # =========================================================================== #
14
+ # require 'pdf_paradise/utility_scripts/to_qdf.rb'
15
+ # PdfParadise::ToQdf.new(ARGV)
16
+ # =========================================================================== #
17
+ require 'pdf_paradise/base/base.rb'
18
+
19
+ module PdfParadise
20
+
21
+ class ToQdf < ::PdfParadise::Base # === PdfParadise::ToQdf
22
+
23
+ # ========================================================================= #
24
+ # === initialize
25
+ # ========================================================================= #
26
+ def initialize(
27
+ commandline_arguments = nil,
28
+ run_already = true
29
+ )
30
+ reset
31
+ set_commandline_arguments(
32
+ commandline_arguments
33
+ )
34
+ run if run_already
35
+ end
36
+
37
+ # ========================================================================= #
38
+ # === reset (reset tag)
39
+ # ========================================================================= #
40
+ def reset
41
+ super()
42
+ infer_the_namespace
43
+ end
44
+
45
+ # ========================================================================= #
46
+ # === run (run tag)
47
+ # ========================================================================= #
48
+ def run
49
+ commandline_arguments?.each {|entry|
50
+ qdf_file = entry.sub(/\.?pdf$/,)
51
+ esystem "qpdf -qdf #{entry} #{qdf_file}.qdf"
52
+ }
53
+ end
54
+
55
+ # ========================================================================= #
56
+ # === PdfParadise::ToQdf[]
57
+ # ========================================================================= #
58
+ def self.[](i = ARGV)
59
+ new(i)
60
+ end
61
+
62
+ end; end
63
+
64
+ if __FILE__ == $PROGRAM_NAME
65
+ PdfParadise::ToQdf.new(ARGV)
66
+ end # toqdf
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'pdf_paradise/version/version.rb'
6
+ # =========================================================================== #
7
+ module PdfParadise
8
+
9
+ # ========================================================================= #
10
+ # === VERSION
11
+ # ========================================================================= #
12
+ VERSION = '0.3.20'
13
+
14
+ # ========================================================================= #
15
+ # === LAST_UPDATE
16
+ # ========================================================================= #
17
+ LAST_UPDATE = '04.02.2024'
18
+
19
+ end
@@ -0,0 +1,2 @@
1
+ In this directory we will put code that can be used on
2
+ the www.
@@ -0,0 +1,304 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === PdfParadise::Sinatra
6
+ # =========================================================================== #
7
+ # require 'pdf_paradise/www/sinatra/app.rb'
8
+ # PdfParadise.start_sinatra_interface
9
+ # =========================================================================== #
10
+ require 'sinatra/base.rb'
11
+
12
+ module PdfParadise
13
+
14
+ class Sinatra < ::Sinatra::Base
15
+
16
+ require 'pdf_paradise'
17
+
18
+ require 'beautiful_url'
19
+
20
+ # ========================================================================= #
21
+ # A lot of the code for this class is stored in the following module:
22
+ # ========================================================================= #
23
+ require 'pdf_paradise/sinatra/embeddable_interface.rb'
24
+ include PdfParadise::EmbeddableInterface
25
+
26
+ begin
27
+ require 'cyberweb'
28
+ rescue LoadError; end
29
+
30
+ include ::Colours
31
+
32
+ set :port, USE_THIS_PORT
33
+
34
+ # ========================================================================= #
35
+ # === PdfParadise::Sinatra.sub_routes?
36
+ # ========================================================================= #
37
+ def self.sub_routes?
38
+ PdfParadise::EmbeddableInterface.sub_routes?
39
+ end
40
+
41
+ # ========================================================================= #
42
+ # === initialize
43
+ # ========================================================================= #
44
+ def initialize
45
+ super()
46
+ reset
47
+ Dir.chdir('/home/Temp/') if File.directory? '/home/Temp'
48
+ if ::PdfParadise.is_on_roebe?
49
+ require 'open'
50
+ # ===================================================================== #
51
+ # Tell us which port will be used:
52
+ # ===================================================================== #
53
+ target = "http://localhost:#{USE_THIS_PORT}/"
54
+ e sfancy(target)
55
+ Thread.new {
56
+ Open.in_browser(target) {{ delay: '1.0 seconds' }}
57
+ }
58
+ end
59
+ end
60
+
61
+ # ========================================================================= #
62
+ # === reset
63
+ # ========================================================================= #
64
+ def reset
65
+ end
66
+
67
+ # ========================================================================= #
68
+ # === report_file_listing
69
+ # ========================================================================= #
70
+ def report_file_listing
71
+ _ = '<p style="padding:1em; font-size: larger">'.dup
72
+ _ << '<b>File listing from the directory: '+Dir.pwd+'</b><br><br>'
73
+ Dir['*'].select {|entry| File.file?(entry) }.each {|entry|
74
+ _ << "→ <b style=\"margin-left:3em\">#{entry}</b><br>"
75
+ }
76
+ _ << '</p>'
77
+ _
78
+ end
79
+
80
+ # =========================================================================== #
81
+ # === View (view tag)
82
+ #
83
+ # http://localhost:5200/view
84
+ # http://localhost:5200/overview
85
+ # =========================================================================== #
86
+ %w( /view /overview ).each {|path|
87
+ get(path) {
88
+ result = ''.dup
89
+ result << p(
90
+ 'The <b style="color: darkblue">content</b> of <b>'+
91
+ PdfParadise.main_directory?.to_s+'</b> is:'
92
+ ).dup
93
+ all_pdf_files = Dir[
94
+ PdfParadise.main_directory?.to_s+'*.pdf'
95
+ ]
96
+ if all_pdf_files.empty?
97
+ result << 'No .pdf files were found.<br>'
98
+ else
99
+ all_pdf_files.each {|this_file|
100
+ result << HtmlTags.p(
101
+ '<span style="color: darkblue">'+
102
+ RARROW+
103
+ '</span> '+this_file,
104
+ css_style: 'margin-left:1.5em; font-weight: bold; font-size: larger'
105
+ )
106
+ }
107
+ end
108
+ result << html_then_title+
109
+ p(
110
+ '(Do not forget to remove .pdf files that you do not '\
111
+ 'wish to autoconvert, from that directory.)'
112
+ )+
113
+ return_link_to_root
114
+ result # Return the result here.
115
+ }
116
+ }
117
+
118
+ # ========================================================================= #
119
+ # === view
120
+ #
121
+ # http://localhost:5200/view
122
+ # ========================================================================= #
123
+ get('/view') { # view tag
124
+ return_view_string
125
+ }
126
+
127
+ # =========================================================================== #
128
+ # http://localhost:5200/title
129
+ #
130
+ # Show the title of the pdf file at hand.
131
+ # =========================================================================== #
132
+ get('/title/*'){ # n pdf pages
133
+ _ = web_params?
134
+ if _.is_a? Array
135
+ _ = _.first
136
+ end
137
+ if File.exist? _
138
+ title = PdfParadise.return_title_of_this_pdf_file(_).to_s
139
+ content = "This .pdf's file title is: <b>#{title}</b>."
140
+ if title.empty?
141
+ content = "This .pdf file has no title."
142
+ end
143
+ result = p(
144
+ content
145
+ ).dup
146
+ result
147
+ else
148
+ html_start_then_title+
149
+ p("No file called #{_} exists.")
150
+ end
151
+ }
152
+
153
+ # =========================================================================== #
154
+ # http://localhost:5200/title
155
+ #
156
+ # Show how many pdf pages a pdf file has.
157
+ # =========================================================================== #
158
+ get('/title'){ # n pdf pages
159
+ route_to_this_action = '/title'
160
+ html_start_then_title
161
+ p('Provide the path to a <b>.pdf</b> file:')+
162
+ form(action: route_to_this_action, id: route_to_this_action.delete('/'), css_style: 'margin-left:2em; margin-top:2px') {
163
+ input_type_user_input+
164
+ br+
165
+ input_type_submit
166
+ }+
167
+ report_file_listing
168
+ }
169
+
170
+ # ========================================================================= #
171
+ # === /convert_single_pdf_file
172
+ #
173
+ # http://localhost:5200/convert_single_pdf_file/
174
+ # ========================================================================= #
175
+ get('/convert_single_pdf_file/*') {
176
+ user_input = web_params?
177
+ if params.has_key?('user_input')
178
+ user_input = params.fetch('user_input')
179
+ end
180
+ result =
181
+ html_then_title+
182
+ p(
183
+ 'Next attempting to work with the pdf file '\
184
+ 'at `<b>'+user_input+'</b>`.<br>'
185
+ ).dup
186
+ if File.exist? user_input
187
+ path = PdfParadise.convert(user_input).to_s
188
+ result << br+
189
+ p(
190
+ 'The converted .pdf file(s) should now be '\
191
+ 'available at: <b>'+path+'</b>'
192
+ )
193
+ else
194
+ result << p(
195
+ 'Unfortunately no .pdf file exists at that path.'
196
+ )
197
+ end
198
+ result
199
+ }
200
+
201
+ # =========================================================================== #
202
+ # === /autoconvert
203
+ #
204
+ # http://localhost:5200/autoconvert
205
+ # =========================================================================== #
206
+ get('/autoconvert'){
207
+ # Start the autoconversion next, part of the PdfParadise project.
208
+ PdfParadise.autoconvert_pdf_files
209
+ result = p(
210
+ 'Trying to autoconvert all .pdf files - look at <b>'+
211
+ PdfParadise.main_directory?.to_s+'</b> for results.'
212
+ ).dup
213
+ Dir[PdfParadise.main_directory?.to_s+'*.pdf'].each {|this_file|
214
+ result << p(this_file)
215
+ }
216
+ result << return_view_string
217
+ result
218
+ }
219
+
220
+ # =========================================================================== #
221
+ # http://localhost:5200/n_pdf_pages
222
+ #
223
+ # Show how many pdf pages a pdf file has.
224
+ # =========================================================================== #
225
+ get('/n_pdf_pages'){ # n pdf pages
226
+ return_n_pdf_pages
227
+ }
228
+
229
+ # =========================================================================== #
230
+ # === /n_pdf_pages
231
+ #
232
+ # http://localhost:5200/n_pdf_pages
233
+ #
234
+ # Show how many pdf pages a pdf file has.
235
+ # =========================================================================== #
236
+ get(sub_routes?[:n_pdf_pages]+'/*'){ # n pdf pages
237
+ _ = web_params_as_string?
238
+ _.prepend('/') unless _.start_with? '/'
239
+ if File.exist? _
240
+ result = html_start_then_title+
241
+ p(
242
+ 'This .pdf file (at <b>'+_+'</b>) has <b>'+
243
+ PdfParadise.n_pages?(_).to_s+'</b> pages.'
244
+ ).dup
245
+ result
246
+ else
247
+ html_start_then_title+
248
+ p('No file called '+_+' exists.')
249
+ end
250
+ }
251
+
252
+ # ========================================================================= #
253
+ # === / Entry point (root tag)
254
+ #
255
+ # This is the root of our web-application.
256
+ #
257
+ # http://localhost:5200
258
+ # ========================================================================= #
259
+ get('/'){
260
+ return_root_string
261
+ }
262
+
263
+ # =========================================================================== #
264
+ # http://localhost:5200/remove_the_first_page_of_this_pdf_file
265
+ #
266
+ # Invocation example:
267
+ #
268
+ # http://localhost:5200/remove_the_first_page_of_this_pdf_file/Time_of_Our_Lives_The_Science_of_Human_Aging_by_Tom_Kirkwood_2001.pdf
269
+ #
270
+ # =========================================================================== #
271
+ get('/remove_the_first_page_of_this_pdf_file/*'){
272
+ _ = web_params?
273
+ _ = _.first if _.is_a? Array
274
+ unless File.exist? _
275
+ all_pdf_files = Dir['/home/x/books/**/*.pdf']
276
+ selection = all_pdf_files.select {|entry|
277
+ entry.end_with?(_)
278
+ }
279
+ if selection and !selection.empty?
280
+ _ = selection.first
281
+ end
282
+ end
283
+ PdfParadise.remove_the_first_page_of_this_pdf_file(_)
284
+ 'Removed the first page of the .pdf file at '+_+'.'
285
+ }
286
+
287
+ end
288
+
289
+ # =========================================================================== #
290
+ # === PdfParadise.start_sinatra_interface
291
+ #
292
+ # This method can be used to start the sinatra interface of the
293
+ # PdfParadise project.
294
+ # =========================================================================== #
295
+ def self.start_sinatra_interface
296
+ e 'Starting the sinatra-interface of the PdfParadise project next.'
297
+ ::PdfParadise::Sinatra.run!
298
+ end
299
+
300
+ end
301
+
302
+ if __FILE__ == $PROGRAM_NAME
303
+ PdfParadise.start_sinatra_interface
304
+ end
@@ -0,0 +1,4 @@
1
+ ---
2
+ - "/home/x/books/NANO_TECHNOLOGY/DONE_Drexler_K.E._Engines_of_Creation_2.0_The_Coming_Era_of_Nanotechnology_2006.pdf"
3
+ - "/home/x/books/GENETICS/DONE_Jochen_Graw_auth._Genetik-Springer_Spektrum_2015.pdf"
4
+ - "/home/x/books/MICROBIOLOGY_IMMUNOLOGY_AND_VACCINATION/DONE_Immunulogie_für_Einsteiger_2015.pdf"
@@ -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,61 @@
1
+ # =========================================================================== #
2
+ # Gemspec for Project PdfParadise.
3
+ # =========================================================================== #
4
+ require 'pdf_paradise/version/version.rb'
5
+ require 'roebe/toplevel_methods/misc.rb'
6
+
7
+ Gem::Specification.new { |s|
8
+
9
+ s.name = 'pdf_paradise'
10
+ s.version = PdfParadise::VERSION
11
+ s.date = Time.now.strftime('%Y-%m-%d')
12
+
13
+ DESCRIPTION = <<-EOF
14
+
15
+ This gem is called pdf_paradise.
16
+
17
+ It attempts to be a swiss army knife, a wrapper, over pdf-related
18
+ functionality in general, by tapping into external projects,
19
+ such as prawn, qpdf and so forth.
20
+
21
+ For more information, please have a look at the documentation
22
+ of the project on the homepage of this gem, at:
23
+
24
+ https://www.rubydoc.info/gems/pdf_paradise/
25
+
26
+ EOF
27
+
28
+ s.summary = DESCRIPTION
29
+ s.description = DESCRIPTION
30
+
31
+ # ========================================================================= #
32
+ # Show this when a user installs this project.
33
+ # ========================================================================= #
34
+ s.post_install_message = <<-EOF
35
+
36
+ You can use this project to manipulate .pdf files.
37
+
38
+ You can find out the amount of pages in a .pdf file, you can use
39
+ it to merge pdf files and so on and so forth.
40
+
41
+ EOF
42
+
43
+ s.authors = ['Robert A. Heiler']
44
+ s.email = Roebe.email?
45
+ s.files = Dir['**/*']
46
+ s.license = 'MIT-0'
47
+ s.homepage = 'https://rubygems.org/gems/pdf_paradise'
48
+
49
+ s.required_ruby_version = '>= '+Roebe.third_most_stable_version_of_ruby
50
+ s.required_rubygems_version = '>= '+Gem::VERSION
51
+ s.rubygems_version = '>= '+Gem::VERSION
52
+
53
+ # ========================================================================= #
54
+ # External dependencies for the project:
55
+ # ========================================================================= #
56
+ s.add_dependency 'cliner'
57
+ s.add_dependency 'colours'
58
+ s.add_dependency 'opn'
59
+ s.add_dependency 'save_file'
60
+
61
+ }
@@ -0,0 +1,12 @@
1
+ require 'pdf_paradise/fpdf/fpdf.rb'
2
+ require 'save_file'
3
+ alias e puts
4
+
5
+ pdf = FPDF.new
6
+ pdf.new_page
7
+ pdf.set_font('Arial','B',16)
8
+ pdf.Cell(40,10,'Hello World!')
9
+ dataset = pdf.Output
10
+
11
+ e 'Storing into test.pdf next.'
12
+ SaveFile.write_what_into(dataset, 'test.pdf')
data/test/fpdf/002.pdf ADDED
Binary file
@@ -0,0 +1,64 @@
1
+ require 'pdf_paradise/fpdf/fpdf.rb'
2
+ require 'save_file'
3
+ alias e puts
4
+
5
+ class PDF < FPDF
6
+
7
+ # ========================================================================= #
8
+ # === initialize
9
+ # ========================================================================= #
10
+ def initialize
11
+ super()
12
+ end
13
+
14
+ # ========================================================================= #
15
+ # === Header
16
+ #
17
+ # Page header
18
+ # ========================================================================= #
19
+ def Header
20
+ # Logo
21
+ Image('/home/x/data/images/NJOY/StringTime.jpg',10,6,30)
22
+ # ========================================================================= #
23
+ # Determine the font next:
24
+ #
25
+ # Arial bold 15
26
+ #
27
+ # ========================================================================= #
28
+ SetFont('Arial','B',15)
29
+ # SetFont('Hack','B',30)
30
+ # SetFont('Liberation Sans Narrow','B',30)
31
+ # Move to the right
32
+ Cell(80)
33
+ # Title
34
+ Cell(120,10,'This showcases how to show a cell',1,0,'C')
35
+ # Line break
36
+ Ln(20)
37
+ end
38
+
39
+ # ========================================================================= #
40
+ # === Footer
41
+ #
42
+ # Page footer
43
+ # ========================================================================= #
44
+ def Footer
45
+ # Position at 1.5 cm from bottom
46
+ SetY(-15)
47
+ # Arial italic 8
48
+ set_font('Arial','I',8)
49
+ # Page number:
50
+ Cell(0,10,'Page '+PageNo().to_s+'/{nb}',0,0,'C')
51
+ end
52
+
53
+ end
54
+
55
+ pdf = PDF.new
56
+ pdf.AliasNbPages
57
+ pdf.AddPage
58
+ pdf.SetFont('Times','',12)
59
+ 40.times {|n_run| n_run += 1
60
+ pdf.Cell(0,10,'Printing line number '+n_run.to_s,0,1)
61
+ }
62
+ dataset = pdf.Output
63
+ e 'Storing into 002.pdf next.'
64
+ SaveFile.write_what_into(dataset, '002.pdf')