pdf_paradise 0.3.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +933 -0
- data/bin/automatic_pdf_title +7 -0
- data/bin/burst_this_pdf_file +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/djvu_to_pdf +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/rotate_pdf +7 -0
- data/bin/set_main_book +7 -0
- data/bin/set_title_of_this_pdf_file +15 -0
- data/doc/README.gen +871 -0
- data/doc/todo/todo.md +13 -0
- data/images/Logo_for_the_pdf_paradise_project.avif +0 -0
- data/lib/pdf_paradise/base/base.rb +344 -0
- data/lib/pdf_paradise/base/colours.rb +67 -0
- data/lib/pdf_paradise/colours/colours.rb +27 -0
- data/lib/pdf_paradise/commandline/commandline.rb +109 -0
- data/lib/pdf_paradise/commandline/help.rb +77 -0
- data/lib/pdf_paradise/commandline/menu.rb +173 -0
- data/lib/pdf_paradise/compress/compress_this_pdf_file.rb +108 -0
- data/lib/pdf_paradise/compress/compress_via_hexapdf.rb +27 -0
- data/lib/pdf_paradise/compress/compress_via_qpdf.rb +32 -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/fpdf/README.md +2 -0
- data/lib/pdf_paradise/fpdf/bookmark.rb +129 -0
- data/lib/pdf_paradise/fpdf/chinese.rb +454 -0
- data/lib/pdf_paradise/fpdf/fpdf.rb +1902 -0
- data/lib/pdf_paradise/fpdf/fpdf_eps.rb +138 -0
- data/lib/pdf_paradise/fpdf/makefont.rb +1794 -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/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/gtk3/controller/controller.rb +214 -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/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
- 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
- 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/remove_the_first_page_of_this_pdf_file/remove_the_first_page_of_this_pdf_file.rb +267 -0
- data/lib/pdf_paradise/gui/libui/rotate_pdf_file/rotate_pdf_file.rb +219 -0
- data/lib/pdf_paradise/gui/libui/statistics_widget/statistics_widget.rb +233 -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 +287 -0
- 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
- data/lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb +295 -0
- data/lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb +366 -0
- 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
- data/lib/pdf_paradise/gui/universal_widgets/statistics_widget/statistics_widget.rb +407 -0
- data/lib/pdf_paradise/gui/universal_widgets/to_pdf/to_pdf.rb +351 -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 +474 -0
- data/lib/pdf_paradise/merge_pdf/menu.rb +63 -0
- data/lib/pdf_paradise/merge_pdf/merge_pdf.rb +307 -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/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 +11 -0
- data/lib/pdf_paradise/requires/colours_and_esystem_and_save_file_and_fileutils_and_opn.rb +13 -0
- data/lib/pdf_paradise/requires/esystem_and_colours.rb +11 -0
- data/lib/pdf_paradise/requires/esystem_and_opn_and_colours.rb +10 -0
- data/lib/pdf_paradise/requires/require_the_whole_project.rb +30 -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 +389 -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 +20 -0
- data/lib/pdf_paradise/toplevel_methods/misc.rb +228 -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 +201 -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/to_pdf.rb +12 -0
- data/lib/pdf_paradise/utility_scripts/README.md +3 -0
- data/lib/pdf_paradise/utility_scripts/automatic_pdf_title.rb +104 -0
- data/lib/pdf_paradise/utility_scripts/check_syntax_of_pdf_files.rb +106 -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 +179 -0
- data/lib/pdf_paradise/utility_scripts/delete_last_page_of_this_pdf_file.rb +180 -0
- 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
- data/lib/pdf_paradise/utility_scripts/delete_this_page_of_this_pdf_file.rb +356 -0
- data/lib/pdf_paradise/utility_scripts/djvu_to_pdf.rb +87 -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_file_n_total_pages.rb +348 -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/rotate_pdf_file.rb +303 -0
- data/lib/pdf_paradise/utility_scripts/split_pdf.rb +364 -0
- data/lib/pdf_paradise/utility_scripts/to_pdf.rb +130 -0
- data/lib/pdf_paradise/utility_scripts/to_qdf.rb +66 -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 +304 -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/fpdf/001_minimal_example.rb +12 -0
- data/test/fpdf/002.pdf +0 -0
- data/test/fpdf/002_header_and_footer_example.rb +64 -0
- data/test/fpdf/003.pdf +98 -0
- data/test/fpdf/003_justified_paragraphs.rb +96 -0
- data/test/fpdf/file1.md +3 -0
- data/test/fpdf/file2.md +3 -0
- data/test/fpdf/test.pdf +0 -0
- data/test/testing_pdf_paradise.rb +12 -0
- metadata +239 -0
@@ -0,0 +1,201 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === PdfParadise::QueryPdfTitle
|
6
|
+
#
|
7
|
+
# This class will simply report the title of a .pdf file (or more accurately,
|
8
|
+
# all .pdf files that were passed to this class).
|
9
|
+
#
|
10
|
+
# Presently this depends on exiftool, but there are other ways how to
|
11
|
+
# query the title of a .pdf file, such as via prawn.
|
12
|
+
#
|
13
|
+
# However had, for the time being, we will depend on exiftool.
|
14
|
+
#
|
15
|
+
# The shell-invocation command for this would be:
|
16
|
+
#
|
17
|
+
# exiftool *.pdf | grep Title
|
18
|
+
#
|
19
|
+
# Usage example:
|
20
|
+
#
|
21
|
+
# PdfParadise::QueryPdfTitle.new(ARGV)
|
22
|
+
#
|
23
|
+
# =========================================================================== #
|
24
|
+
# require 'pdf_paradise/toplevel_methods/query_pdf_title.rb'
|
25
|
+
# PdfParadise::QueryPdfTitle.new(ARGV)
|
26
|
+
# =========================================================================== #
|
27
|
+
require 'pdf_paradise/base/base.rb'
|
28
|
+
|
29
|
+
module PdfParadise
|
30
|
+
|
31
|
+
class QueryPdfTitle < Base # === PdfParadise::QueryPdfTitle
|
32
|
+
|
33
|
+
# ========================================================================= #
|
34
|
+
# === NAMESPACE
|
35
|
+
# ========================================================================= #
|
36
|
+
NAMESPACE = inspect
|
37
|
+
|
38
|
+
# ========================================================================= #
|
39
|
+
# === initialize
|
40
|
+
# ========================================================================= #
|
41
|
+
def initialize(
|
42
|
+
i = nil,
|
43
|
+
run_already = true
|
44
|
+
)
|
45
|
+
reset
|
46
|
+
set_input(i)
|
47
|
+
if block_given?
|
48
|
+
yielded = yield
|
49
|
+
case yielded
|
50
|
+
when :be_verbose
|
51
|
+
@be_verbose = true
|
52
|
+
when :be_quiet
|
53
|
+
@be_verbose = false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
run if run_already
|
57
|
+
end
|
58
|
+
|
59
|
+
# ========================================================================= #
|
60
|
+
# === reset (reset tag)
|
61
|
+
# ========================================================================= #
|
62
|
+
def reset
|
63
|
+
super()
|
64
|
+
# ======================================================================= #
|
65
|
+
# === @be_verbose
|
66
|
+
# ======================================================================= #
|
67
|
+
@be_verbose = true
|
68
|
+
# ======================================================================= #
|
69
|
+
# === @namespace
|
70
|
+
# ======================================================================= #
|
71
|
+
@namespace = NAMESPACE
|
72
|
+
end
|
73
|
+
|
74
|
+
# ========================================================================= #
|
75
|
+
# === set_input
|
76
|
+
# ========================================================================= #
|
77
|
+
def set_input(i = '')
|
78
|
+
i = [i] unless i.is_a? Array
|
79
|
+
@input = i
|
80
|
+
end
|
81
|
+
|
82
|
+
# ========================================================================= #
|
83
|
+
# === input?
|
84
|
+
# ========================================================================= #
|
85
|
+
def input?
|
86
|
+
@input
|
87
|
+
end; alias pdf_files? input? # === pdf_files?
|
88
|
+
|
89
|
+
# ========================================================================= #
|
90
|
+
# === iterate_over_the_input_files
|
91
|
+
# ========================================================================= #
|
92
|
+
def iterate_over_the_input_files
|
93
|
+
use_this_regex = /^Title\s*: (.+)$/
|
94
|
+
pdf_files?.each {|this_pdf_file|
|
95
|
+
if File.exist? this_pdf_file
|
96
|
+
sys_cmd = `exiftool #{this_pdf_file}`
|
97
|
+
begin
|
98
|
+
@title = sys_cmd.scan(use_this_regex).flatten.first
|
99
|
+
rescue ArgumentError => error
|
100
|
+
e 'An error happened for '+sfile(this_pdf_file)+'.'
|
101
|
+
pp error
|
102
|
+
pp error.class
|
103
|
+
exit
|
104
|
+
end
|
105
|
+
if @be_verbose
|
106
|
+
e "#{rev}The title for `#{sfile(this_pdf_file)}#{rev}` is:"
|
107
|
+
e
|
108
|
+
e " #{sfancy(@title)}"
|
109
|
+
e
|
110
|
+
end
|
111
|
+
else
|
112
|
+
opnn(namespace: @namespace); e "No file exists at `#{sfile(this_pdf_file)}`."
|
113
|
+
end
|
114
|
+
}
|
115
|
+
end
|
116
|
+
|
117
|
+
# ========================================================================= #
|
118
|
+
# === title?
|
119
|
+
# ========================================================================= #
|
120
|
+
def title?
|
121
|
+
@title
|
122
|
+
end
|
123
|
+
|
124
|
+
# ========================================================================= #
|
125
|
+
# === string?
|
126
|
+
#
|
127
|
+
# This variant will always return a String - an empty String if the .pdf
|
128
|
+
# file has no title set.
|
129
|
+
# ========================================================================= #
|
130
|
+
def string?
|
131
|
+
title?.to_s
|
132
|
+
end
|
133
|
+
|
134
|
+
# ========================================================================= #
|
135
|
+
# === run (run tag)
|
136
|
+
# ========================================================================= #
|
137
|
+
def run
|
138
|
+
iterate_over_the_input_files
|
139
|
+
end
|
140
|
+
|
141
|
+
# ========================================================================= #
|
142
|
+
# === PdfParadise::QueryPdfTitle[]
|
143
|
+
# ========================================================================= #
|
144
|
+
def self.[](i = '')
|
145
|
+
self.new(i)
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
# =========================================================================== #
|
151
|
+
# === PdfParadise.does_this_pdf_file_have_a_title?
|
152
|
+
#
|
153
|
+
# This method can be used to query whether a given .pdf file has a title
|
154
|
+
# or whether it does not.
|
155
|
+
#
|
156
|
+
# Usage examples:
|
157
|
+
#
|
158
|
+
# PdfParadise.does_this_pdf_file_have_a_title? "foobar.pdf" # => true
|
159
|
+
# PdfParadise.has_title? "foobar.pdf" # => true
|
160
|
+
#
|
161
|
+
# =========================================================================== #
|
162
|
+
def self.does_this_pdf_file_have_a_title?(i)
|
163
|
+
!query_pdf_title(i).empty?
|
164
|
+
end; self.instance_eval { alias has_title? does_this_pdf_file_have_a_title? } # === PdfParadise.has_title?
|
165
|
+
|
166
|
+
# =========================================================================== #
|
167
|
+
# === PdfParadise.pdf_has_no_title?
|
168
|
+
# =========================================================================== #
|
169
|
+
def self.pdf_has_no_title?(i)
|
170
|
+
!does_this_pdf_file_have_a_title?(i)
|
171
|
+
end
|
172
|
+
|
173
|
+
# =========================================================================== #
|
174
|
+
# === PdfParadise.query_pdf_title
|
175
|
+
#
|
176
|
+
# The input to this method should be an existing .pdf file.
|
177
|
+
#
|
178
|
+
# It will call class QueryPdfTitle to determine the title of the .pdf
|
179
|
+
# file at hand.
|
180
|
+
#
|
181
|
+
# This method will return a String if a title can be found in the
|
182
|
+
# .pdf file at hand.
|
183
|
+
#
|
184
|
+
# Usage example:
|
185
|
+
#
|
186
|
+
# title = PdfParadise.query_pdf_title('/foobar.pdf') # => "Lecture 2 - Scaling"
|
187
|
+
# title = PdfParadise.return_title_of_this_pdf_file('')
|
188
|
+
#
|
189
|
+
# =========================================================================== #
|
190
|
+
def self.query_pdf_title(i)
|
191
|
+
PdfParadise::QueryPdfTitle.new(i) { :be_quiet }.string?
|
192
|
+
end; self.instance_eval { alias return_pdf_title_of query_pdf_title } # === PdfParadise.return_pdf_title
|
193
|
+
self.instance_eval { alias return_title_of_this_pdf_file query_pdf_title } # === PdfParadise.return_title_of_this_pdf_file
|
194
|
+
self.instance_eval { alias title? query_pdf_title } # === PdfParadise.title?
|
195
|
+
self.instance_eval { alias return_title_of_this_pdf_file query_pdf_title } # === PdfParadise.return_title_of_this_pdf_file
|
196
|
+
|
197
|
+
end
|
198
|
+
|
199
|
+
if __FILE__ == $PROGRAM_NAME
|
200
|
+
PdfParadise::QueryPdfTitle.new(ARGV)
|
201
|
+
end # querypdftitle
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'pdf_paradise/toplevel_methods/reduce_size_of_this_pdf_file.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module PdfParadise
|
8
|
+
|
9
|
+
require 'pdf_paradise/toplevel_methods/e.rb'
|
10
|
+
|
11
|
+
begin
|
12
|
+
require 'esystem'
|
13
|
+
rescue LoadError; end
|
14
|
+
|
15
|
+
# ========================================================================= #
|
16
|
+
# === PdfParadise.reduce_size_of_this_pdf_file
|
17
|
+
#
|
18
|
+
# This method can be used to reduce the size of the passed .pdf file.
|
19
|
+
#
|
20
|
+
# This functionality depends on ghostscript (on the "gs" binary,
|
21
|
+
# specifically).
|
22
|
+
# ========================================================================= #
|
23
|
+
def self.reduce_size_of_this_pdf_file(this_pdf_file)
|
24
|
+
if this_pdf_file.is_a? Array
|
25
|
+
this_pdf_file.each {|entry|
|
26
|
+
reduce_size_of_this_pdf_file(entry)
|
27
|
+
}
|
28
|
+
else
|
29
|
+
guessed_name = File.basename(this_pdf_file).sub(/#{File.extname(this_pdf_file)}$/,'').dup
|
30
|
+
name_of_the_output_file = "output_#{guessed_name}".dup
|
31
|
+
name_of_the_output_file << '.pdf' unless name_of_the_output_file.end_with?('.pdf')
|
32
|
+
e
|
33
|
+
e 'Trying to reduce the size of the file '+this_pdf_file+' next:'
|
34
|
+
e
|
35
|
+
_ = 'gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 '\
|
36
|
+
'-dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH '\
|
37
|
+
'-sOutputFile='+name_of_the_output_file+' '+this_pdf_file
|
38
|
+
Esystem.esystem(_)
|
39
|
+
end
|
40
|
+
end; self.instance_eval { alias reduce_size reduce_size_of_this_pdf_file } # === PdfParadise.reduce_size
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
if __FILE__ == $PROGRAM_NAME
|
45
|
+
PdfParadise.reduce_size_of_this_pdf_file(ARGV)
|
46
|
+
end # reduce_size_of_this_pdf_file
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'pdf_paradise/toplevel_methods/roebe.rb'
|
6
|
+
# PdfParadise.is_on_roebe?
|
7
|
+
# =========================================================================== #
|
8
|
+
module PdfParadise
|
9
|
+
|
10
|
+
# ========================================================================= #
|
11
|
+
# === PdfParadise.is_on_roebe?
|
12
|
+
# ========================================================================= #
|
13
|
+
def self.is_on_roebe?
|
14
|
+
ENV['IS_ROEBE'].to_s == '1'
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'pdf_paradise/toplevel_methods/to_pdf.rb'
|
6
|
+
# PdfParadise.to_pdf
|
7
|
+
# =========================================================================== #
|
8
|
+
require 'pdf_paradise/utility_scripts/to_pdf.rb'
|
9
|
+
|
10
|
+
if __FILE__ == $PROGRAM_NAME
|
11
|
+
PdfParadise.to_pdf(ARGV)
|
12
|
+
end # topdf
|
@@ -0,0 +1,104 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === PdfParadise::AutomaticPdfTitle
|
6
|
+
#
|
7
|
+
# This class can automatically set the title of a .pdf file.
|
8
|
+
# =========================================================================== #
|
9
|
+
# require 'pdf_paradise/utility_scripts/automatic_pdf_title.rb'
|
10
|
+
# PdfParadise.autotitle(ARGV)
|
11
|
+
# =========================================================================== #
|
12
|
+
require 'pdf_paradise/base/base.rb'
|
13
|
+
|
14
|
+
module PdfParadise
|
15
|
+
|
16
|
+
class AutomaticPdfTitle < Base # === PdfParadise::AutomaticPdfTitle
|
17
|
+
|
18
|
+
require 'pdf_paradise/set_pdf_title.rb'
|
19
|
+
|
20
|
+
# ========================================================================= #
|
21
|
+
# === initialize
|
22
|
+
# ========================================================================= #
|
23
|
+
def initialize(
|
24
|
+
input_files = ARGV,
|
25
|
+
run_already = true
|
26
|
+
)
|
27
|
+
reset
|
28
|
+
set_commandline_arguments(
|
29
|
+
input_files
|
30
|
+
)
|
31
|
+
run if run_already
|
32
|
+
end
|
33
|
+
|
34
|
+
# ========================================================================= #
|
35
|
+
# === reset
|
36
|
+
# ========================================================================= #
|
37
|
+
def reset
|
38
|
+
super()
|
39
|
+
infer_the_namespace
|
40
|
+
end
|
41
|
+
|
42
|
+
# ========================================================================= #
|
43
|
+
# === automatic_pdf_title
|
44
|
+
# ========================================================================= #
|
45
|
+
def automatic_pdf_title(
|
46
|
+
i = commandline_arguments?
|
47
|
+
)
|
48
|
+
i.each {|this_pdf_file|
|
49
|
+
if File.exist? this_pdf_file
|
50
|
+
new_pdf_title = File.basename(this_pdf_file).
|
51
|
+
sub(/#{File.extname(this_pdf_file)}$/,'').
|
52
|
+
tr('_',' ')
|
53
|
+
# =================================================================== #
|
54
|
+
# Remove leading 'DONE_' substrings:
|
55
|
+
# =================================================================== #
|
56
|
+
if new_pdf_title.start_with? 'DONE'
|
57
|
+
new_pdf_title.sub!(/^DONE_/,'') if new_pdf_title.include? 'DONE_'
|
58
|
+
new_pdf_title.sub!(/^DONE /,'') if new_pdf_title.include? 'DONE '
|
59
|
+
end
|
60
|
+
e "#{rev}Setting the title of the .pdf file "\
|
61
|
+
"#{sfile(this_pdf_file)} #{rev}to:"
|
62
|
+
e
|
63
|
+
e " #{PdfParadise.darkolivegreen(new_pdf_title)}"
|
64
|
+
e
|
65
|
+
PdfParadise.set_pdf_title(
|
66
|
+
this_pdf_file,
|
67
|
+
new_pdf_title # First comes the file, then the title.
|
68
|
+
)
|
69
|
+
else
|
70
|
+
e "#{rev}No .pdf file exists at `#{sfile(this_pdf_file)}#{rev}`."
|
71
|
+
end
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
# ========================================================================= #
|
76
|
+
# === run (run tag)
|
77
|
+
# ========================================================================= #
|
78
|
+
def run
|
79
|
+
automatic_pdf_title(commandline_arguments?)
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
# =========================================================================== #
|
85
|
+
# === PdfParadise.automatic_pdf_title
|
86
|
+
#
|
87
|
+
# This method will automatically set the title of a .pdf file to its
|
88
|
+
# filename, with all '_' tokens replaced by ' ' tokens.
|
89
|
+
#
|
90
|
+
# The input to this method should be .pdf files that are existing locally.
|
91
|
+
# =========================================================================== #
|
92
|
+
def self.automatic_pdf_title(
|
93
|
+
of_this_pdf_file = ARGV
|
94
|
+
)
|
95
|
+
[of_this_pdf_file].flatten.compact.each {|this_pdf_file|
|
96
|
+
PdfParadise::AutomaticPdfTitle.new(this_pdf_file)
|
97
|
+
}
|
98
|
+
end; self.instance_eval { alias autotitle automatic_pdf_title } # === PdfParadise.autotitle
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
if __FILE__ == $PROGRAM_NAME
|
103
|
+
PdfParadise.automatic_pdf_title(ARGV)
|
104
|
+
end # apdf
|
@@ -0,0 +1,106 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === PdfParadise::CheckSyntaxOfPdfFiles
|
6
|
+
#
|
7
|
+
# This class will check for the syntax of .pdf files.
|
8
|
+
#
|
9
|
+
# Usage example:
|
10
|
+
#
|
11
|
+
# PdfParadise::CheckSyntaxOfPdfFiles.new(ARGV)
|
12
|
+
#
|
13
|
+
# =========================================================================== #
|
14
|
+
# require 'pdf_paradise/utility_scripts/check_syntax_of_pdf_files.rb'
|
15
|
+
# PdfParadise::CheckSyntaxOfPdfFiles.new(ARGV)
|
16
|
+
# =========================================================================== #
|
17
|
+
require 'pdf_paradise/base/base.rb'
|
18
|
+
|
19
|
+
module PdfParadise
|
20
|
+
|
21
|
+
class CheckSyntaxOfPdfFiles < ::PdfParadise::Base # === PdfParadise::CheckSyntaxOfPdfFiles
|
22
|
+
|
23
|
+
# ========================================================================= #
|
24
|
+
# === initialize
|
25
|
+
# ========================================================================= #
|
26
|
+
def initialize(
|
27
|
+
i = ARGV,
|
28
|
+
run_already = true
|
29
|
+
)
|
30
|
+
reset
|
31
|
+
set_commandline_arguments(i)
|
32
|
+
run if run_already
|
33
|
+
end
|
34
|
+
|
35
|
+
# ========================================================================= #
|
36
|
+
# === reset (reset tag)
|
37
|
+
# ========================================================================= #
|
38
|
+
def reset
|
39
|
+
super()
|
40
|
+
end
|
41
|
+
|
42
|
+
# ========================================================================= #
|
43
|
+
# === run (run tag)
|
44
|
+
# ========================================================================= #
|
45
|
+
def run
|
46
|
+
_ = commandline_arguments?
|
47
|
+
work_on_these_files(_)
|
48
|
+
end
|
49
|
+
|
50
|
+
# ========================================================================= #
|
51
|
+
# === work_on_these_files
|
52
|
+
# ========================================================================= #
|
53
|
+
def work_on_these_files(i)
|
54
|
+
if i.is_a?(Array) and (i.first == :work_on_every_pdf_file_in_the_current_working_directory)
|
55
|
+
i = Dir['*.pdf']
|
56
|
+
end
|
57
|
+
i.each {|entry|
|
58
|
+
if File.file?(entry)
|
59
|
+
check_this_pdf_file(entry)
|
60
|
+
end
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
# ========================================================================= #
|
65
|
+
# === check_this_pdf_file
|
66
|
+
#
|
67
|
+
# This is the method that does the syntax-check, via qpdf.
|
68
|
+
#
|
69
|
+
# The specific commandline that will be invoked is:
|
70
|
+
#
|
71
|
+
# qpdf --check 09.11.2009_Scan_Dr_Kirchmayer_Statik_und_Edbebensicherheit.pdf
|
72
|
+
#
|
73
|
+
# ========================================================================= #
|
74
|
+
def check_this_pdf_file(
|
75
|
+
i
|
76
|
+
)
|
77
|
+
# ======================================================================= #
|
78
|
+
# Always work on an Array:
|
79
|
+
# ======================================================================= #
|
80
|
+
[i].flatten.compact.each {|this_pdf_file|
|
81
|
+
cmd_to_run = "qpdf --check #{this_pdf_file}"
|
82
|
+
e
|
83
|
+
e cmd_to_run
|
84
|
+
e
|
85
|
+
result = `#{cmd_to_run}`
|
86
|
+
if result.include? 'No syntax or stream encoding errors found'
|
87
|
+
e sfile(this_pdf_file)+rev+': all is fine with this .pdf file.'
|
88
|
+
else
|
89
|
+
e swarn('Some problem exists for ')+sfile(this_pdf_file)+rev
|
90
|
+
pp result
|
91
|
+
end
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
# ========================================================================= #
|
96
|
+
# === PdfParadise::CheckSyntaxOfPdfFiles[]
|
97
|
+
# ========================================================================= #
|
98
|
+
def self.[](i = ARGV)
|
99
|
+
new(i)
|
100
|
+
end
|
101
|
+
|
102
|
+
end; end
|
103
|
+
|
104
|
+
if __FILE__ == $PROGRAM_NAME
|
105
|
+
PdfParadise::CheckSyntaxOfPdfFiles.new(ARGV)
|
106
|
+
end # CheckSyntaxOfPdfFiles
|
@@ -0,0 +1,118 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === PdfParadise::CombineThesePdfPages
|
6
|
+
# =========================================================================== #
|
7
|
+
# require 'pdf_paradise/utility_scripts/combine_these_pdf_pages.rb'
|
8
|
+
# =========================================================================== #
|
9
|
+
require 'pdf_paradise/base/base.rb'
|
10
|
+
|
11
|
+
module PdfParadise
|
12
|
+
|
13
|
+
class CombineThesePdfPages < PdfParadise::Base # === PdfParadise::CombineThesePdfPages
|
14
|
+
|
15
|
+
require 'pdf_paradise/utility_scripts/split_pdf.rb'
|
16
|
+
|
17
|
+
# ========================================================================= #
|
18
|
+
# === NAMESPACE
|
19
|
+
# ========================================================================= #
|
20
|
+
NAMESPACE = inspect
|
21
|
+
|
22
|
+
# ========================================================================= #
|
23
|
+
# === initialize
|
24
|
+
# ========================================================================= #
|
25
|
+
def initialize(
|
26
|
+
commandline_arguments = ARGV,
|
27
|
+
run_already = true
|
28
|
+
)
|
29
|
+
reset
|
30
|
+
set_commandline_arguments(
|
31
|
+
commandline_arguments
|
32
|
+
)
|
33
|
+
run if run_already
|
34
|
+
end
|
35
|
+
|
36
|
+
# ========================================================================= #
|
37
|
+
# === reset (reset tag)
|
38
|
+
# ========================================================================= #
|
39
|
+
def reset
|
40
|
+
super()
|
41
|
+
end
|
42
|
+
|
43
|
+
# ========================================================================= #
|
44
|
+
# === opnn
|
45
|
+
# ========================================================================= #
|
46
|
+
def opnn
|
47
|
+
super(NAMESPACE)
|
48
|
+
end
|
49
|
+
|
50
|
+
# ========================================================================= #
|
51
|
+
# === run (run tag)
|
52
|
+
# ========================================================================= #
|
53
|
+
def run
|
54
|
+
name_of_the_pdf_file = File.absolute_path(first_argument?)
|
55
|
+
unless File.exist? name_of_the_pdf_file
|
56
|
+
e 'Please provide a path to an existing .pdf file.'
|
57
|
+
return
|
58
|
+
end
|
59
|
+
_ = log_dir?
|
60
|
+
mkdir(_) unless File.directory? _
|
61
|
+
cd _
|
62
|
+
if File.exist? name_of_the_pdf_file
|
63
|
+
unless File.exist? File.absolute_path(File.basename(name_of_the_pdf_file))
|
64
|
+
e 'Copying the file '+name_of_the_pdf_file+'.'
|
65
|
+
copy_file(name_of_the_pdf_file)
|
66
|
+
end
|
67
|
+
if File.exist? File.basename(name_of_the_pdf_file)
|
68
|
+
name_of_the_pdf_file = File.absolute_path(File.basename(name_of_the_pdf_file))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
these_pages_must_be_kept = commandline_arguments?[1]
|
72
|
+
# Must be converted into an array.
|
73
|
+
if these_pages_must_be_kept.include? ','
|
74
|
+
these_pages_must_be_kept = these_pages_must_be_kept.split(',')
|
75
|
+
else
|
76
|
+
these_pages_must_be_kept = [these_pages_must_be_kept]
|
77
|
+
end
|
78
|
+
these_pages_must_be_kept.map! {|entry| entry.to_i }
|
79
|
+
begin
|
80
|
+
require 'hexapdf'
|
81
|
+
pdf = HexaPDF::Document.open(name_of_the_pdf_file)
|
82
|
+
new_pdf = HexaPDF::Document.new
|
83
|
+
pdf.pages.each_with_index { |page, index| index += 1
|
84
|
+
if these_pages_must_be_kept.include? index
|
85
|
+
e 'Copying page page number: '+
|
86
|
+
steelblue(index.to_s)
|
87
|
+
new_pdf.pages << new_pdf.import(page)
|
88
|
+
end
|
89
|
+
}
|
90
|
+
@output_file_to_use = 'output.pdf'
|
91
|
+
@output_file_to_use = File.absolute_path(@output_file_to_use)
|
92
|
+
delete_file(@output_file_to_use) if File.exist? @output_file_to_use
|
93
|
+
e 'Storing into `'+@output_file_to_use+'`.'
|
94
|
+
new_pdf.write(
|
95
|
+
@output_file_to_use,
|
96
|
+
validate: false,
|
97
|
+
optimize: true
|
98
|
+
)
|
99
|
+
rescue LoadError
|
100
|
+
e 'HexaPDF is not available. Please install it via:'
|
101
|
+
e
|
102
|
+
e ' gem install hexapdf'
|
103
|
+
e
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# ========================================================================= #
|
108
|
+
# === stored_where?
|
109
|
+
# ========================================================================= #
|
110
|
+
def stored_where?
|
111
|
+
@output_file_to_use
|
112
|
+
end; alias output_file_to_use? stored_where? # === output_file_to_use?
|
113
|
+
|
114
|
+
end; end
|
115
|
+
|
116
|
+
if __FILE__ == $PROGRAM_NAME
|
117
|
+
PdfParadise::CombineThesePdfPages.new(ARGV)
|
118
|
+
end # combinethesepdfpages
|