pdf_paradise 0.1.66
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.
- checksums.yaml +7 -0
- data/README.md +705 -0
- data/bin/automatic_pdf_title +7 -0
- data/bin/combine_these_pdf_pages +7 -0
- data/bin/compress_via_hexapdf +7 -0
- data/bin/convert_markdown_to_pdf +7 -0
- data/bin/convert_pdf_to_text +7 -0
- data/bin/delete_first_page_of_this_pdf_file +7 -0
- data/bin/merge_then_open +7 -0
- data/bin/n_pages +10 -0
- data/bin/open_main_pdf +7 -0
- data/bin/pdf_paradise +9 -0
- data/bin/set_main_book +7 -0
- data/bin/set_title_of_this_pdf_file +15 -0
- data/doc/README.gen +662 -0
- data/doc/todo/todo.md +7 -0
- data/lib/pdf_paradise/base/base.rb +239 -0
- data/lib/pdf_paradise/base/colours.rb +36 -0
- data/lib/pdf_paradise/commandline/commandline.rb +101 -0
- data/lib/pdf_paradise/commandline/help.rb +73 -0
- data/lib/pdf_paradise/commandline/menu.rb +142 -0
- data/lib/pdf_paradise/compress/compress_via_hexapdf.rb +27 -0
- data/lib/pdf_paradise/compress_this_pdf_file.rb +87 -0
- data/lib/pdf_paradise/constants/constants.rb +76 -0
- data/lib/pdf_paradise/convert_text_to_pdf.rb +94 -0
- data/lib/pdf_paradise/css/project.css +17 -0
- data/lib/pdf_paradise/djvu_to_pdf.rb +85 -0
- data/lib/pdf_paradise/gui/README.md +6 -0
- data/lib/pdf_paradise/gui/fox/split_pdf_file.rb +77 -0
- 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
- data/lib/pdf_paradise/gui/gtk2/pdf_viewer/pdf_viewer.rb +34 -0
- data/lib/pdf_paradise/gui/gtk2/split_pdf_file/split_pdf_file.rb +34 -0
- data/lib/pdf_paradise/gui/gtk2/statistics_widget/statistics_widget.rb +34 -0
- data/lib/pdf_paradise/gui/gtk2/to_pdf/to_pdf.rb +32 -0
- data/lib/pdf_paradise/gui/gtk3/controller/controller.rb +212 -0
- data/lib/pdf_paradise/gui/gtk3/convert_pdf_to_text/convert_pdf_to_text.rb +34 -0
- 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
- data/lib/pdf_paradise/gui/gtk3/pdf_viewer/pdf_viewer.rb +34 -0
- data/lib/pdf_paradise/gui/gtk3/split_pdf_file/split_pdf_file.rb +34 -0
- data/lib/pdf_paradise/gui/gtk3/statistics_widget/statistics_widget.rb +34 -0
- data/lib/pdf_paradise/gui/gtk3/to_pdf/to_pdf.rb +32 -0
- data/lib/pdf_paradise/gui/libui/extract_all_images_from_this_pdf_file/extract_all_images_from_this_pdf_file.rb +223 -0
- data/lib/pdf_paradise/gui/libui/statistics_widget/statistics_widget.rb +233 -0
- data/lib/pdf_paradise/gui/shared_code/convert_pdf_to_text/convert_pdf_to_text_module.rb +277 -0
- 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 +443 -0
- data/lib/pdf_paradise/gui/shared_code/pdf_viewer/pdf_viewer.css +5 -0
- data/lib/pdf_paradise/gui/shared_code/pdf_viewer/pdf_viewer_module.rb +284 -0
- data/lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file.css +0 -0
- data/lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb +294 -0
- data/lib/pdf_paradise/gui/shared_code/statistics_widget/statistics_widget_module.rb +349 -0
- data/lib/pdf_paradise/gui/shared_code/to_pdf/to_pdf_module.rb +281 -0
- data/lib/pdf_paradise/hexapdf/001_rainbow_pattern_example.rb +0 -0
- data/lib/pdf_paradise/hexapdf/hexapdf.rb +123 -0
- data/lib/pdf_paradise/images/PDF_PARADISE_LOGO.png +0 -0
- data/lib/pdf_paradise/main_pdf/main_pdf.rb +444 -0
- data/lib/pdf_paradise/merge_pdf/menu.rb +63 -0
- data/lib/pdf_paradise/merge_pdf/merge_pdf.rb +306 -0
- data/lib/pdf_paradise/merge_pdf_namespace.rb +9 -0
- data/lib/pdf_paradise/merge_then_open/merge_then_open.rb +105 -0
- data/lib/pdf_paradise/pdf_file_n_total_pages.rb +249 -0
- data/lib/pdf_paradise/prawn_addons/README.md +2 -0
- data/lib/pdf_paradise/prawn_addons/prawn_addons.rb +17 -0
- data/lib/pdf_paradise/project/project.rb +22 -0
- data/lib/pdf_paradise/remove_pdf_password.rb +391 -0
- data/lib/pdf_paradise/requires/batch_require_toplevel_files.rb +22 -0
- data/lib/pdf_paradise/requires/colours.rb +7 -0
- data/lib/pdf_paradise/requires/colours_and_esystem_and_save_file_and_fileutils_and_opn.rb +11 -0
- data/lib/pdf_paradise/requires/esystem_and_colours.rb +10 -0
- data/lib/pdf_paradise/requires/esystem_and_opn_and_colours.rb +8 -0
- data/lib/pdf_paradise/requires/require_the_whole_project.rb +28 -0
- data/lib/pdf_paradise/requires/require_utility_scripts.rb +9 -0
- data/lib/pdf_paradise/set_main_book.rb +156 -0
- data/lib/pdf_paradise/set_pdf_title.rb +220 -0
- data/lib/pdf_paradise/sinatra/embeddable_interface.rb +318 -0
- data/lib/pdf_paradise/toplevel_methods/automatic_pdf_title.rb +55 -0
- data/lib/pdf_paradise/toplevel_methods/convert_epub_to_pdf.rb +27 -0
- data/lib/pdf_paradise/toplevel_methods/convert_markdown_to_pdf.rb +45 -0
- data/lib/pdf_paradise/toplevel_methods/convert_ppt_to_pdf.rb +35 -0
- data/lib/pdf_paradise/toplevel_methods/e.rb +16 -0
- data/lib/pdf_paradise/toplevel_methods/esystem.rb +19 -0
- data/lib/pdf_paradise/toplevel_methods/misc.rb +76 -0
- data/lib/pdf_paradise/toplevel_methods/number_pages.rb +38 -0
- data/lib/pdf_paradise/toplevel_methods/opened_pdf_files.rb +221 -0
- data/lib/pdf_paradise/toplevel_methods/query_pdf_title.rb +191 -0
- data/lib/pdf_paradise/toplevel_methods/reduce_size_of_this_pdf_file.rb +46 -0
- data/lib/pdf_paradise/toplevel_methods/roebe.rb +17 -0
- data/lib/pdf_paradise/toplevel_methods/rotate_pdf_file.rb +143 -0
- data/lib/pdf_paradise/toplevel_methods/to_pdf.rb +38 -0
- data/lib/pdf_paradise/utility_scripts/README.md +3 -0
- data/lib/pdf_paradise/utility_scripts/combine_these_pdf_pages.rb +118 -0
- data/lib/pdf_paradise/utility_scripts/convert_pdf_to_text.rb +175 -0
- data/lib/pdf_paradise/utility_scripts/delete_first_page_of_this_pdf_file.rb +221 -0
- data/lib/pdf_paradise/utility_scripts/delete_last_page_of_this_pdf_file.rb +180 -0
- data/lib/pdf_paradise/utility_scripts/delete_this_page_of_this_pdf_file.rb +329 -0
- data/lib/pdf_paradise/utility_scripts/extract_all_images_from_this_pdf_file.rb +129 -0
- data/lib/pdf_paradise/utility_scripts/extract_pdf_page.rb +283 -0
- data/lib/pdf_paradise/utility_scripts/pdf_optimizer.rb +111 -0
- data/lib/pdf_paradise/utility_scripts/pdf_statistics.rb +148 -0
- data/lib/pdf_paradise/utility_scripts/pdf_to_html.rb +75 -0
- data/lib/pdf_paradise/utility_scripts/remove_images.rb +110 -0
- data/lib/pdf_paradise/utility_scripts/split_pdf.rb +340 -0
- data/lib/pdf_paradise/utility_scripts/to_qdf.rb +82 -0
- data/lib/pdf_paradise/version/version.rb +19 -0
- data/lib/pdf_paradise/www/README.md +2 -0
- data/lib/pdf_paradise/www/sinatra/app.rb +276 -0
- data/lib/pdf_paradise/yaml/working_on_these_pdf_files.yml +4 -0
- data/lib/pdf_paradise.rb +5 -0
- data/pdf_paradise.gemspec +61 -0
- data/test/testing_pdf_paradise.rb +9 -0
- metadata +219 -0
@@ -0,0 +1,123 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === HexaPDF::Document
|
6
|
+
# =========================================================================== #
|
7
|
+
# require 'pdf_paradise/hexapdf/hexapdf.rb'
|
8
|
+
# =========================================================================== #
|
9
|
+
begin
|
10
|
+
require 'hexapdf'
|
11
|
+
rescue LoadError; end
|
12
|
+
|
13
|
+
module HexaPDF
|
14
|
+
|
15
|
+
class Document
|
16
|
+
|
17
|
+
alias e puts
|
18
|
+
|
19
|
+
# ========================================================================= #
|
20
|
+
# === optimize_this_pdf_file
|
21
|
+
#
|
22
|
+
# This method can be used to optimise a given .pdf file.
|
23
|
+
# ========================================================================= #
|
24
|
+
def optimize_this_pdf_file(
|
25
|
+
this_pdf_file = '/Depot/j/foobar.pdf',
|
26
|
+
store_into_this_pdf_file = 'optimized_pdf_file.pdf'
|
27
|
+
)
|
28
|
+
HexaPDF.optimize_this_pdf_file(
|
29
|
+
this_pdf_file,
|
30
|
+
store_into_this_pdf_file
|
31
|
+
)
|
32
|
+
end; alias optimise_this_pdf_file optimize_this_pdf_file # === optimise_this_pdf_file
|
33
|
+
|
34
|
+
# ========================================================================= #
|
35
|
+
# === add_this_font
|
36
|
+
#
|
37
|
+
# This method can be used to add a specific font.
|
38
|
+
# ========================================================================= #
|
39
|
+
def add_this_font(
|
40
|
+
font_path = '/usr/share/fonts/truetype/hack/Hack-Regular.ttf'
|
41
|
+
)
|
42
|
+
case font_path
|
43
|
+
# ======================================================================= #
|
44
|
+
# === :hack
|
45
|
+
# ======================================================================= #
|
46
|
+
when :hack,
|
47
|
+
:default
|
48
|
+
font_path = '/usr/share/fonts/truetype/hack/Hack-Regular.ttf'
|
49
|
+
end
|
50
|
+
puts "Adding the font from: #{font_path}"
|
51
|
+
return self.fonts.add(font_path)
|
52
|
+
end; alias add_font add_this_font # === add_font
|
53
|
+
|
54
|
+
# ========================================================================= #
|
55
|
+
# === create_pie_chart
|
56
|
+
# ========================================================================= #
|
57
|
+
def create_pie_chart(
|
58
|
+
# doc = HexaPDF::Document.new,
|
59
|
+
use_this_stroke_colour = :default,
|
60
|
+
use_this_fill_colour = 'ddddff',
|
61
|
+
radius = 75,
|
62
|
+
store_into_this_pdf_file = 'arcs.pdf'
|
63
|
+
)
|
64
|
+
doc = self
|
65
|
+
if use_this_stroke_colour.is_a? Hash
|
66
|
+
# ===================================================================== #
|
67
|
+
# === :store_into
|
68
|
+
#
|
69
|
+
# Usage example:
|
70
|
+
#
|
71
|
+
# create_pie_chart(doc, store_into: 'bla.pdf')
|
72
|
+
#
|
73
|
+
# ===================================================================== #
|
74
|
+
if use_this_stroke_colour.has_key? :store_into
|
75
|
+
store_into_this_pdf_file = use_this_stroke_colour.delete(:store_into)
|
76
|
+
use_this_stroke_colour = :default
|
77
|
+
end
|
78
|
+
end
|
79
|
+
case use_this_stroke_colour
|
80
|
+
when :default
|
81
|
+
use_this_stroke_colour = '777777'
|
82
|
+
end
|
83
|
+
page = doc.pages.add # Add a new page.
|
84
|
+
canvas = page.canvas
|
85
|
+
# ======================================================================= #
|
86
|
+
# A centered pie chart:
|
87
|
+
# ======================================================================= #
|
88
|
+
center = [page.box.width * 0.75, page.box.height * 0.85]
|
89
|
+
canvas.stroke_color(use_this_stroke_colour)
|
90
|
+
pie = canvas.graphic_object(:solid_arc, cx: center[0], cy: center[1],
|
91
|
+
outer_a: radius, outer_b: radius)
|
92
|
+
canvas.fill_color(use_this_fill_colour)
|
93
|
+
canvas.draw(pie, start_angle: 30, end_angle: 110).fill_stroke
|
94
|
+
canvas.fill_color('ffdddd')
|
95
|
+
canvas.draw(pie, start_angle: 110, end_angle: 130).fill_stroke
|
96
|
+
canvas.fill_color('ddffdd')
|
97
|
+
canvas.draw(pie, start_angle: 130, end_angle: 30).fill_stroke
|
98
|
+
doc.write(store_into_this_pdf_file, optimize: true)
|
99
|
+
return canvas
|
100
|
+
end; alias pie_chart create_pie_chart # === pie_chart
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
# =========================================================================== #
|
105
|
+
# === HexaPDF.optimize_this_pdf_file
|
106
|
+
#
|
107
|
+
# This method can be used to optimise a given .pdf file.
|
108
|
+
# =========================================================================== #
|
109
|
+
def self.optimize_this_pdf_file(
|
110
|
+
this_pdf_file = '/Depot/j/foobar.pdf',
|
111
|
+
store_into_this_pdf_file = 'optimized_pdf_file.pdf'
|
112
|
+
)
|
113
|
+
HexaPDF::Document.open(this_pdf_file) { |doc|
|
114
|
+
doc.task(:optimize,
|
115
|
+
compact: true,
|
116
|
+
object_streams: :generate,
|
117
|
+
compress_pages: false)
|
118
|
+
puts 'Storing into the file `'+store_into_this_pdf_file+'`.'
|
119
|
+
doc.write(store_into_this_pdf_file)
|
120
|
+
}
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
Binary file
|
@@ -0,0 +1,444 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === PdfParadise::MainPdf
|
6
|
+
#
|
7
|
+
# Use this file to open one or several .pdf files.
|
8
|
+
#
|
9
|
+
# The convention is that you can pass both commandlines and also
|
10
|
+
# filenames on the commandlines.
|
11
|
+
#
|
12
|
+
# Usage example:
|
13
|
+
#
|
14
|
+
# PdfParadise::MainPdf.new
|
15
|
+
#
|
16
|
+
# =========================================================================== #
|
17
|
+
# require 'pdf_paradise/main_pdf/main_pdf.rb'
|
18
|
+
# =========================================================================== #
|
19
|
+
require 'pdf_paradise/base/base.rb'
|
20
|
+
require 'pdf_paradise/constants/constants.rb'
|
21
|
+
|
22
|
+
module PdfParadise
|
23
|
+
|
24
|
+
class MainPdf < Base # === PdfParadise::MainPdf
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'directory_paradise'
|
28
|
+
rescue LoadError; end
|
29
|
+
|
30
|
+
# ========================================================================= #
|
31
|
+
# === MAIN_PDF_YAML_FILE
|
32
|
+
# ========================================================================= #
|
33
|
+
MAIN_PDF_YAML_FILE = ::PdfParadise.file_main_pdf_yaml_file?
|
34
|
+
|
35
|
+
# ========================================================================= #
|
36
|
+
# === HOME_DIR
|
37
|
+
# ========================================================================= #
|
38
|
+
HOME_DIR = ENV['HOME'].to_s+'/'
|
39
|
+
|
40
|
+
# ========================================================================= #
|
41
|
+
# === LAST_DOWNLOADED_FILE
|
42
|
+
# ========================================================================= #
|
43
|
+
LAST_DOWNLOADED_FILE =
|
44
|
+
"#{HOME_DIR}LAST_DOWNLOADED_FILE.md"
|
45
|
+
|
46
|
+
# ========================================================================= #
|
47
|
+
# === LAST_PDF_FILE_OPENED
|
48
|
+
# ========================================================================= #
|
49
|
+
LAST_PDF_FILE_OPENED =
|
50
|
+
"#{HOME_DIR}LAST_PDF_FILE_OPENED.md"
|
51
|
+
|
52
|
+
# ========================================================================= #
|
53
|
+
# === initialize
|
54
|
+
#
|
55
|
+
# The first argument can be an Array or a String, of pdf-files that
|
56
|
+
# we attempt to open.
|
57
|
+
# ========================================================================= #
|
58
|
+
def initialize(
|
59
|
+
these_pdf_files = nil,
|
60
|
+
run_already = true
|
61
|
+
)
|
62
|
+
reset
|
63
|
+
check_commandline_options(
|
64
|
+
these_pdf_files
|
65
|
+
)
|
66
|
+
case run_already
|
67
|
+
when :do_not_run_yet
|
68
|
+
run_already = false
|
69
|
+
end
|
70
|
+
run if run_already
|
71
|
+
end
|
72
|
+
|
73
|
+
# ========================================================================= #
|
74
|
+
# === reset (reset tag)
|
75
|
+
# ========================================================================= #
|
76
|
+
def reset
|
77
|
+
super()
|
78
|
+
# ======================================================================= #
|
79
|
+
# === @pdf_viewer
|
80
|
+
# ======================================================================= #
|
81
|
+
if File.exist? MAIN_PDF_YAML_FILE
|
82
|
+
@pdf_viewer = YAML.load_file(MAIN_PDF_YAML_FILE)
|
83
|
+
else
|
84
|
+
ewarn "The file at `#{MAIN_PDF_YAML_FILE}` was not found."
|
85
|
+
end
|
86
|
+
@pdf_viewer = @pdf_viewer.first if @pdf_viewer.is_a? Array # Use only the first entry for now if we read in an Array.
|
87
|
+
# ======================================================================= #
|
88
|
+
# === @open_these_pdf_files
|
89
|
+
# ======================================================================= #
|
90
|
+
@open_these_pdf_files = []
|
91
|
+
# ======================================================================= #
|
92
|
+
# === @commandline_options
|
93
|
+
# ======================================================================= #
|
94
|
+
@commandline_options = [] # This array may contain our commandline options.
|
95
|
+
end
|
96
|
+
|
97
|
+
# ========================================================================= #
|
98
|
+
# === save_new_pdf_handler
|
99
|
+
#
|
100
|
+
# The first (and only) argument to this method is which new pdf handler
|
101
|
+
# we will use. Afterwards we will exit.
|
102
|
+
#
|
103
|
+
# To invoke this method, do:
|
104
|
+
#
|
105
|
+
# mpdf SAVE xournal
|
106
|
+
# mpdf SAVE okular
|
107
|
+
#
|
108
|
+
# ========================================================================= #
|
109
|
+
def save_new_pdf_handler(
|
110
|
+
i = @commandline_options[1]
|
111
|
+
)
|
112
|
+
i = i.to_s
|
113
|
+
e 'Saving `'+sfancy(i)+'` into `'+sfile(MAIN_PDF_YAML_FILE)+'`.'
|
114
|
+
write_what_where(i, MAIN_PDF_YAML_FILE)
|
115
|
+
exit
|
116
|
+
end
|
117
|
+
|
118
|
+
# ========================================================================= #
|
119
|
+
# === show_yaml_file
|
120
|
+
# ========================================================================= #
|
121
|
+
def show_yaml_file
|
122
|
+
e 'The main yaml file is at `'+sfile(main_yaml_file?)+'`.'
|
123
|
+
end
|
124
|
+
|
125
|
+
# ========================================================================= #
|
126
|
+
# === MAIN_PDF_YAML_FILE
|
127
|
+
# ========================================================================= #
|
128
|
+
def main_yaml_file?
|
129
|
+
MAIN_PDF_YAML_FILE
|
130
|
+
end
|
131
|
+
|
132
|
+
# ========================================================================= #
|
133
|
+
# === feedback_pdf_handler_in_use
|
134
|
+
# ========================================================================= #
|
135
|
+
def feedback_pdf_handler_in_use
|
136
|
+
e 'You currently use this as .pdf handler: '+
|
137
|
+
sfancy(@pdf_viewer)
|
138
|
+
end
|
139
|
+
|
140
|
+
# ========================================================================= #
|
141
|
+
# === ecomment
|
142
|
+
# ========================================================================= #
|
143
|
+
def ecomment(i)
|
144
|
+
Colours.ecomment(i)
|
145
|
+
end
|
146
|
+
|
147
|
+
# ========================================================================= #
|
148
|
+
# === check_whether_we_have_found_any_pdf_file
|
149
|
+
#
|
150
|
+
# This method checks whether we have found any .pdf file or not. If not,
|
151
|
+
# we try to check whether the current directory has any .pdf file at all.
|
152
|
+
# ========================================================================= #
|
153
|
+
def check_whether_we_have_found_any_pdf_file
|
154
|
+
if @open_these_pdf_files.empty?
|
155
|
+
any_pdf_file = get_all_pdf_files
|
156
|
+
if ! any_pdf_file.empty?
|
157
|
+
_ = any_pdf_file.first
|
158
|
+
e 'It seems as if no .pdf file was supplied.'
|
159
|
+
e 'We did however find at least one .pdf file. We will now '
|
160
|
+
e 'use this .pdf file at '+sfile(_)+'.'
|
161
|
+
add _
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# ========================================================================= #
|
167
|
+
# === edit_this_file_here
|
168
|
+
# ========================================================================= #
|
169
|
+
def edit_this_file_here
|
170
|
+
_ = 'bluefish '+__FILE__
|
171
|
+
esystem _
|
172
|
+
end
|
173
|
+
|
174
|
+
# ========================================================================= #
|
175
|
+
# === do_log_this_pdf_file_was_opened_last
|
176
|
+
# ========================================================================= #
|
177
|
+
def do_log_this_pdf_file_was_opened_last(i = @full_file_location)
|
178
|
+
save_what_into(i, LAST_PDF_FILE_OPENED)
|
179
|
+
end
|
180
|
+
|
181
|
+
# ========================================================================= #
|
182
|
+
# === set_full_file_location
|
183
|
+
# ========================================================================= #
|
184
|
+
def set_full_file_location(i)
|
185
|
+
unless i.include? '/'
|
186
|
+
i = Dir.pwd+'/'+i
|
187
|
+
end
|
188
|
+
@full_file_location = i
|
189
|
+
end
|
190
|
+
|
191
|
+
# ========================================================================= #
|
192
|
+
# === MainPdf[]
|
193
|
+
# ========================================================================= #
|
194
|
+
def self.[](i, optional_commandline_arguments = nil)
|
195
|
+
_ = self.new(i, :do_not_run_yet)
|
196
|
+
if optional_commandline_arguments
|
197
|
+
_.commandline_arguments = optional_commandline_arguments
|
198
|
+
end
|
199
|
+
_.run
|
200
|
+
end
|
201
|
+
|
202
|
+
# ========================================================================= #
|
203
|
+
# === check_commandline_options
|
204
|
+
#
|
205
|
+
# The convention is simply - if it is a valid file, we
|
206
|
+
# add it to the list of pdf files to open.
|
207
|
+
# ========================================================================= #
|
208
|
+
def check_commandline_options(i)
|
209
|
+
if i.is_a? Array
|
210
|
+
i.each {|entry| check_commandline_options(entry) }
|
211
|
+
else # We either add it to the list of pdf files to open, or to the commandline options
|
212
|
+
if File.exist? i
|
213
|
+
# =================================================================== #
|
214
|
+
# Open the .pdf file here, if it exists.
|
215
|
+
# =================================================================== #
|
216
|
+
add_to_open_these_pdf_files(i)
|
217
|
+
else
|
218
|
+
@commandline_options << i
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end; alias commandline_arguments= check_commandline_options # === commandline_arguments=
|
222
|
+
|
223
|
+
# ========================================================================= #
|
224
|
+
# === process_commandline_options
|
225
|
+
#
|
226
|
+
# Use this method to process the commandline options given.
|
227
|
+
# ========================================================================= #
|
228
|
+
def process_commandline_options
|
229
|
+
_ = @commandline_options.first
|
230
|
+
case _ # case tag
|
231
|
+
# ======================================================================= #
|
232
|
+
# === mpdf --use-atril
|
233
|
+
# ======================================================================= #
|
234
|
+
when 'USE_ATRIL',
|
235
|
+
/^-?-?atril$/i,
|
236
|
+
/^-?-?use(-|_)?atril$/i
|
237
|
+
save_new_pdf_handler :atril
|
238
|
+
# ======================================================================= #
|
239
|
+
# === mpdf --use-evince
|
240
|
+
# ======================================================================= #
|
241
|
+
when 'USE_EVINCE',
|
242
|
+
/^-?-?EVINCE$/i,
|
243
|
+
/^-?-?use(-|_)?evince$/i
|
244
|
+
save_new_pdf_handler :evince
|
245
|
+
# ======================================================================= #
|
246
|
+
# === --open-main-pdf
|
247
|
+
# ======================================================================= #
|
248
|
+
when /^-?-?open(-|_)?main(-|_)?pdf$/i
|
249
|
+
add_to_open_these_pdf_files(:the_main_pdf)
|
250
|
+
# ======================================================================= #
|
251
|
+
# === mpdf --open-last
|
252
|
+
# ======================================================================= #
|
253
|
+
when /^-?-?open(-|_)?last$/i,
|
254
|
+
'OPENLATEST','LATEST',
|
255
|
+
'LAST','last'
|
256
|
+
open_last_found_pdf
|
257
|
+
# ======================================================================= #
|
258
|
+
# === mpdf --query?
|
259
|
+
# ======================================================================= #
|
260
|
+
when /-?-?query\??/,'QUERY','QUERY?','?','PDF?',/-?-?current\??/
|
261
|
+
feedback_pdf_handler_in_use
|
262
|
+
exit
|
263
|
+
# ======================================================================= #
|
264
|
+
# === mpdf --file?
|
265
|
+
# ======================================================================= #
|
266
|
+
when /-?-?file\??/
|
267
|
+
show_yaml_file
|
268
|
+
exit
|
269
|
+
# ======================================================================= #
|
270
|
+
# === mpdf SAVE okular
|
271
|
+
# ======================================================================= #
|
272
|
+
when 'SAVE',
|
273
|
+
'SET','save','set','--save','--set'
|
274
|
+
save_new_pdf_handler
|
275
|
+
# ======================================================================= #
|
276
|
+
# === mpdf --help
|
277
|
+
# ======================================================================= #
|
278
|
+
when /-?-?help/,'HELP'
|
279
|
+
feedback_available_commandline_options
|
280
|
+
# ======================================================================= #
|
281
|
+
# === mpdf --restore
|
282
|
+
# ======================================================================= #
|
283
|
+
when /-?-?restore/,'RESTORE'
|
284
|
+
add( File.readlines(LAST_PDF_FILE_OPENED)[0].to_s.strip )
|
285
|
+
# ======================================================================= #
|
286
|
+
# === mpdf --edit
|
287
|
+
# ======================================================================= #
|
288
|
+
when 'EDIT','OPEN','OPEN_SELF','OPENSELF',/edit/
|
289
|
+
edit_this_file_here; exit
|
290
|
+
# ======================================================================= #
|
291
|
+
# === mpdf --okular
|
292
|
+
# ======================================================================= #
|
293
|
+
when 'USE_OKULAR','OKULAR',/^-?-?okular/
|
294
|
+
save_new_pdf_handler :okular
|
295
|
+
# ======================================================================= #
|
296
|
+
# === mpdf --fullscreen
|
297
|
+
# ======================================================================= #
|
298
|
+
when 'FULLSCREEN','--fullscreen'
|
299
|
+
@pdf_viewer << ' --fullscreen'
|
300
|
+
# ======================================================================= #
|
301
|
+
# === mpdf LAST_DOWNLOAD
|
302
|
+
# ======================================================================= #
|
303
|
+
when 'LAST_DOWNLOAD','LASTDOWNLOAD'
|
304
|
+
last_downloaded_file = LAST_DOWNLOADED_FILE
|
305
|
+
if File.exist? last_downloaded_file
|
306
|
+
add(File.readlines(last_downloaded_file).first)
|
307
|
+
end
|
308
|
+
else # else step
|
309
|
+
unless File.exist? _
|
310
|
+
opn; e 'Unsure what to do with input `'+simp(_)+'`.'
|
311
|
+
end if _
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
# ========================================================================= #
|
316
|
+
# === run_sys_command
|
317
|
+
# ========================================================================= #
|
318
|
+
def run_sys_command
|
319
|
+
process_commandline_options
|
320
|
+
check_whether_we_have_found_any_pdf_file
|
321
|
+
open_all_pdf_files
|
322
|
+
end
|
323
|
+
|
324
|
+
# ========================================================================= #
|
325
|
+
# === open_all_pdf_files
|
326
|
+
# ========================================================================= #
|
327
|
+
def open_all_pdf_files
|
328
|
+
@open_these_pdf_files.each {|entry|
|
329
|
+
consider_opening_this_pdf_file(entry)
|
330
|
+
}
|
331
|
+
end
|
332
|
+
|
333
|
+
# ========================================================================= #
|
334
|
+
# === consider_opening_this_pdf_file
|
335
|
+
#
|
336
|
+
# This method will do the actual opening-part, by using system().
|
337
|
+
# ========================================================================= #
|
338
|
+
def consider_opening_this_pdf_file(i = @open_these_pdf_files)
|
339
|
+
if File.exist? i
|
340
|
+
set_full_file_location(i)
|
341
|
+
i = '"'+i+'"' if i.include? ' '
|
342
|
+
i = '"'+i+'"' if i.include? '('
|
343
|
+
i = '"'+i+'"' if i.include? "'"
|
344
|
+
i = @pdf_viewer+' '+i+' &'
|
345
|
+
do_log_this_pdf_file_was_opened_last
|
346
|
+
esystem i
|
347
|
+
else # Ok, at this point the file does not exist. Try a regex first.
|
348
|
+
results = Dir['*'+i+'*']
|
349
|
+
if results.empty?
|
350
|
+
opn; e 'No valid .pdf file was found at `'+sfile(i)+'`.'
|
351
|
+
opn; e 'Thus we can not open anything.'
|
352
|
+
else
|
353
|
+
consider_opening_this_pdf_file(results.first)
|
354
|
+
end
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
# ========================================================================= #
|
359
|
+
# === feedback_available_commandline_options (help tag)
|
360
|
+
#
|
361
|
+
# Show the available help options next.
|
362
|
+
# ========================================================================= #
|
363
|
+
def feedback_available_commandline_options(
|
364
|
+
shall_we_exit = true
|
365
|
+
)
|
366
|
+
cliner {
|
367
|
+
ecomment ' RESTORE - open the last opened .pdf file in general'
|
368
|
+
ecomment ' OPEN_LAST - open the "youngest" .pdf file in the current working directory'
|
369
|
+
ecomment ' EDIT - open this file here'
|
370
|
+
ecomment ' QUERY - query which is our current default pdf reader'
|
371
|
+
ecomment ' --current? - alias to the above'
|
372
|
+
ecomment ' --file? - show the location of the .yml file'
|
373
|
+
ecomment ' SAVE / SET - save a new mpdf handler to use (i.e. '\
|
374
|
+
'"okular", via "mpdf SAVE okular")'
|
375
|
+
ecomment ' LAST_DOWNLOAD - open the last downloaded file stored in '+
|
376
|
+
LAST_DOWNLOADED_FILE
|
377
|
+
}
|
378
|
+
exit if shall_we_exit
|
379
|
+
end
|
380
|
+
|
381
|
+
# ========================================================================= #
|
382
|
+
# === get_all_pdf_files
|
383
|
+
# ========================================================================= #
|
384
|
+
def get_all_pdf_files
|
385
|
+
_ = DirectoryParadise::Reprt.new('', :do_not_run_yetfalse)
|
386
|
+
_.menu(:latest)
|
387
|
+
_.gather_content
|
388
|
+
only_pdf_files = _.content.select {|entry|
|
389
|
+
entry.include? '.pdf'
|
390
|
+
}
|
391
|
+
return only_pdf_files
|
392
|
+
end
|
393
|
+
|
394
|
+
# ========================================================================= #
|
395
|
+
# === open_last_found_pdf
|
396
|
+
#
|
397
|
+
# This will open the last .pdf file in the current directory. Which
|
398
|
+
# one is that? We will act on the file information here.
|
399
|
+
# ========================================================================= #
|
400
|
+
def open_last_found_pdf
|
401
|
+
add :latest_pdf
|
402
|
+
end
|
403
|
+
|
404
|
+
# ========================================================================= #
|
405
|
+
# === add_to_open_these_pdf_files (add tag)
|
406
|
+
# ========================================================================= #
|
407
|
+
def add_to_open_these_pdf_files(i)
|
408
|
+
case i
|
409
|
+
# ======================================================================= #
|
410
|
+
# === :main_pdf
|
411
|
+
# ======================================================================= #
|
412
|
+
when :main_pdf,
|
413
|
+
:the_main_pdf
|
414
|
+
i = ENV['MAIN_BOOK'].to_s
|
415
|
+
# ======================================================================= #
|
416
|
+
# === :latest_pdf
|
417
|
+
# ======================================================================= #
|
418
|
+
when :latest_pdf
|
419
|
+
i = get_all_pdf_files.sort.first.to_s # Get the latest .pdf file. [0] Should be the properly sorted one.
|
420
|
+
end
|
421
|
+
@open_these_pdf_files << i
|
422
|
+
end; alias add add_to_open_these_pdf_files # === add
|
423
|
+
|
424
|
+
# ========================================================================= #
|
425
|
+
# === run (run tag)
|
426
|
+
# ========================================================================= #
|
427
|
+
def run
|
428
|
+
run_sys_command
|
429
|
+
end
|
430
|
+
|
431
|
+
end
|
432
|
+
|
433
|
+
# =========================================================================== #
|
434
|
+
# === PdfParadise.main_pdf
|
435
|
+
# =========================================================================== #
|
436
|
+
def self.main_pdf(i = ARGV)
|
437
|
+
::PdfParadise::MainPdf.new(i)
|
438
|
+
end
|
439
|
+
|
440
|
+
end
|
441
|
+
|
442
|
+
if __FILE__ == $PROGRAM_NAME
|
443
|
+
PdfParadise.main_pdf(ARGV)
|
444
|
+
end # mpdf AUPC_Einheit_I_Einfuehrung_2013.pdf AUPC_Einheit_II_2013.pdf
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'pdf_paradise/merge_pdf/menu.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'pdf_paradise/base/base.rb'
|
8
|
+
|
9
|
+
module PdfParadise
|
10
|
+
|
11
|
+
class MergePdf < Base # === PdfParadise::MergePdf
|
12
|
+
|
13
|
+
# ========================================================================= #
|
14
|
+
# === menu (menu tag)
|
15
|
+
#
|
16
|
+
# This is check_against_menu(). We respond to some given input.
|
17
|
+
# ========================================================================= #
|
18
|
+
def menu(
|
19
|
+
i = commandline_arguments?
|
20
|
+
)
|
21
|
+
if i.is_a? Array
|
22
|
+
i.each {|entry| menu(entry) }
|
23
|
+
else
|
24
|
+
case i # (case tag)
|
25
|
+
# ===================================================================== #
|
26
|
+
# === --use-hexapdf
|
27
|
+
# ===================================================================== #
|
28
|
+
when /^-?-?use(-|_| )?hexapdf$/i,
|
29
|
+
/^-?-?hexapdf$/i
|
30
|
+
@use_this_program_for_merging_the_pdf_files = :hexapdf
|
31
|
+
# ===================================================================== #
|
32
|
+
# === --use-ghostscript
|
33
|
+
# ===================================================================== #
|
34
|
+
when /^-?-?use(-|_| )?ghostscript$/i,
|
35
|
+
/^-?-?ghostscript$/i
|
36
|
+
@use_this_program_for_merging_the_pdf_files = :ghostscript
|
37
|
+
# ===================================================================== #
|
38
|
+
# === --remove
|
39
|
+
# ===================================================================== #
|
40
|
+
when '1',
|
41
|
+
/^-?-?last$/i,
|
42
|
+
/^-?-?kill$/i,
|
43
|
+
/^-?-?remove$/i
|
44
|
+
remove_merged_files
|
45
|
+
exit
|
46
|
+
# ===================================================================== #
|
47
|
+
# === --openself
|
48
|
+
# ===================================================================== #
|
49
|
+
when '2',
|
50
|
+
/^-?-?openself$/i
|
51
|
+
open_this_file_here
|
52
|
+
exit
|
53
|
+
# ===================================================================== #
|
54
|
+
# === mergepdf --help
|
55
|
+
# ===================================================================== #
|
56
|
+
when /help/
|
57
|
+
show_help
|
58
|
+
exit
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end; alias check_against_menu menu # === check_against_menu
|
62
|
+
|
63
|
+
end; end
|