pdf_paradise 0.1.43
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of pdf_paradise might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/README.md +376 -0
- data/bin/automatic_pdf_title +7 -0
- data/bin/convert_markdown_to_pdf +7 -0
- data/bin/convert_pdf_to_text +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 +7 -0
- data/bin/set_main_book +7 -0
- data/bin/set_title_of_this_pdf_file +15 -0
- data/doc/README.gen +348 -0
- data/doc/todo/todo.md +2 -0
- data/lib/pdf_paradise.rb +5 -0
- data/lib/pdf_paradise/base/base.rb +173 -0
- data/lib/pdf_paradise/commandline/help.rb +69 -0
- data/lib/pdf_paradise/commandline/menu.rb +160 -0
- data/lib/pdf_paradise/compress_this_pdf_file.rb +82 -0
- data/lib/pdf_paradise/constants/constants.rb +59 -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 +197 -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/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 +428 -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 +333 -0
- data/lib/pdf_paradise/gui/shared_code/to_pdf/to_pdf_module.rb +273 -0
- data/lib/pdf_paradise/main_pdf/main_pdf.rb +437 -0
- data/lib/pdf_paradise/merge_pdf/menu.rb +63 -0
- data/lib/pdf_paradise/merge_pdf/merge_pdf.rb +292 -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 +227 -0
- data/lib/pdf_paradise/project/project_base_directory.rb +22 -0
- data/lib/pdf_paradise/remove_pdf_password.rb +392 -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 +25 -0
- data/lib/pdf_paradise/requires/require_utility_scripts.rb +7 -0
- data/lib/pdf_paradise/rotate_pdf_file.rb +144 -0
- data/lib/pdf_paradise/set_main_book.rb +156 -0
- data/lib/pdf_paradise/set_pdf_title.rb +218 -0
- data/lib/pdf_paradise/sinatra/embeddable_interface.rb +315 -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 +43 -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 +52 -0
- data/lib/pdf_paradise/toplevel_methods/number_pages.rb +38 -0
- data/lib/pdf_paradise/toplevel_methods/opened_pdf_files.rb +191 -0
- data/lib/pdf_paradise/toplevel_methods/query_pdf_title.rb +182 -0
- data/lib/pdf_paradise/toplevel_methods/reduce_size_of_this_pdf_file.rb +43 -0
- data/lib/pdf_paradise/toplevel_methods/roebe.rb +17 -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/convert_pdf_to_text.rb +166 -0
- data/lib/pdf_paradise/utility_scripts/delete_first_page_of_this_pdf_file.rb +185 -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 +310 -0
- data/lib/pdf_paradise/utility_scripts/extract_pdf_page.rb +280 -0
- data/lib/pdf_paradise/utility_scripts/pdf_optimizer.rb +113 -0
- data/lib/pdf_paradise/utility_scripts/pdf_statistics.rb +150 -0
- data/lib/pdf_paradise/utility_scripts/remove_images.rb +110 -0
- data/lib/pdf_paradise/utility_scripts/split_pdf.rb +294 -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/pdf_paradise.gemspec +64 -0
- data/test/testing_pdf_paradise.rb +9 -0
- metadata +216 -0
@@ -0,0 +1,280 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === PdfParadise::ExtractPdfPage
|
6
|
+
#
|
7
|
+
# Use this class to extract one or more pdf pages from a given .pdf file.
|
8
|
+
#
|
9
|
+
# Three arguments can be passed to this class:
|
10
|
+
#
|
11
|
+
# The first argument is the first page of the range to extract
|
12
|
+
# The second argument is the last page of the range to extract
|
13
|
+
# The third argument is the given input file (the .pdf file)
|
14
|
+
#
|
15
|
+
# Specific invocation examples:
|
16
|
+
#
|
17
|
+
# pdfpextr START_PAGE.pdf 5 19
|
18
|
+
# pdfpextr inputfile.pdf 22 36
|
19
|
+
# ext_pdf foo.pdf 1 100
|
20
|
+
#
|
21
|
+
# Usage examples:
|
22
|
+
# require 'extract_pdf_page'
|
23
|
+
# ExtractPdfPage.new
|
24
|
+
# ExtractPdfPage.new :save_here => '/Depot/Temp/test.pdf'
|
25
|
+
#
|
26
|
+
# Usage examples from the commandline:
|
27
|
+
# epdf foo.pdf 5
|
28
|
+
# epdf foo.pdf 5 10
|
29
|
+
# =========================================================================== #
|
30
|
+
# require 'extract_pdf_page.rb'
|
31
|
+
# =========================================================================== #
|
32
|
+
require 'pdf_paradise/requires/esystem_and_opn_and_colours.rb'
|
33
|
+
require 'pdf_paradise/base/base.rb'
|
34
|
+
|
35
|
+
module PdfParadise
|
36
|
+
|
37
|
+
class ExtractPdfPage < PdfParadise::Base # ExtractPdfPage.new
|
38
|
+
|
39
|
+
# ========================================================================= #
|
40
|
+
# === NAMESPACE
|
41
|
+
# ========================================================================= #
|
42
|
+
NAMESPACE = inspect
|
43
|
+
|
44
|
+
# ========================================================================= #
|
45
|
+
# === DEFAULT_START_PAGE
|
46
|
+
# ========================================================================= #
|
47
|
+
DEFAULT_START_PAGE = '1'
|
48
|
+
|
49
|
+
# ========================================================================= #
|
50
|
+
# === DEFAULT_END_PAGE
|
51
|
+
#
|
52
|
+
# This number can be modified automatically during runtime.
|
53
|
+
# ========================================================================= #
|
54
|
+
DEFAULT_END_PAGE = '10'
|
55
|
+
|
56
|
+
# ========================================================================= #
|
57
|
+
# === DEFAULT_EXTRACT_N_PDF_FILES
|
58
|
+
# ========================================================================= #
|
59
|
+
DEFAULT_EXTRACT_N_PDF_FILES = 1
|
60
|
+
|
61
|
+
# ========================================================================= #
|
62
|
+
# === initialize
|
63
|
+
#
|
64
|
+
# We accept three arguments:
|
65
|
+
#
|
66
|
+
# (1) the name of the .pdf file
|
67
|
+
# (2) the start page
|
68
|
+
# (3) the end page
|
69
|
+
#
|
70
|
+
# ========================================================================= #
|
71
|
+
def initialize(
|
72
|
+
mandatory_name_of_pdf_file = nil,
|
73
|
+
optional_start_page = DEFAULT_START_PAGE,
|
74
|
+
extract_n_pdf_files = DEFAULT_EXTRACT_N_PDF_FILES,
|
75
|
+
run_already = true
|
76
|
+
)
|
77
|
+
reset
|
78
|
+
check_against_menu(mandatory_name_of_pdf_file)
|
79
|
+
if mandatory_name_of_pdf_file.is_a? Hash
|
80
|
+
if mandatory_name_of_pdf_file.has_key? :dont_run_yet
|
81
|
+
run_already = !mandatory_name_of_pdf_file.delete(:dont_run_yet)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
set_name_of_pdf_file(mandatory_name_of_pdf_file) # Must come before set_extract_n_pdf_files()
|
85
|
+
unless mandatory_name_of_pdf_file.is_a? Hash
|
86
|
+
set_start_page(optional_start_page)
|
87
|
+
set_extract_n_pdf_files(extract_n_pdf_files)
|
88
|
+
end
|
89
|
+
run if run_already
|
90
|
+
end
|
91
|
+
|
92
|
+
# ========================================================================= #
|
93
|
+
# === reset (reset tag)
|
94
|
+
# ========================================================================= #
|
95
|
+
def reset
|
96
|
+
super()
|
97
|
+
end
|
98
|
+
|
99
|
+
# ========================================================================= #
|
100
|
+
# === set_name_of_pdf_file
|
101
|
+
#
|
102
|
+
# The input can also be a Hash.
|
103
|
+
# ========================================================================= #
|
104
|
+
def set_name_of_pdf_file(i)
|
105
|
+
if i.is_a? Hash
|
106
|
+
if i.has_key? :start_page
|
107
|
+
set_start_page(i.delete(:start_page))
|
108
|
+
end
|
109
|
+
if i.has_key? :end_page
|
110
|
+
set_end_page(i.delete(:end_page))
|
111
|
+
end
|
112
|
+
if i.has_key? :pdf_file_to_use
|
113
|
+
i = i.delete(:pdf_file_to_use)
|
114
|
+
end
|
115
|
+
else
|
116
|
+
i = i.to_s
|
117
|
+
end
|
118
|
+
unless File.exist? i
|
119
|
+
opnn; e 'Warning - no file at `'+sfile(i.to_s)+'` could be found.'
|
120
|
+
opnn; e 'Thus we can not extract anything. Exiting now'
|
121
|
+
exit
|
122
|
+
end
|
123
|
+
@name_of_pdf_file = i
|
124
|
+
end; alias use_this_input_file set_name_of_pdf_file # === use_this_input_file
|
125
|
+
|
126
|
+
# ========================================================================= #
|
127
|
+
# === set_start_page
|
128
|
+
# ========================================================================= #
|
129
|
+
def set_start_page(
|
130
|
+
i = DEFAULT_START_PAGE
|
131
|
+
)
|
132
|
+
i = DEFAULT_START_PAGE if i.nil?
|
133
|
+
if i.is_a? Hash
|
134
|
+
if i.has_key? :save_here
|
135
|
+
set_save_here(i.delete(:save_here))
|
136
|
+
end
|
137
|
+
end
|
138
|
+
i = i.to_s
|
139
|
+
if File.exist?(i) and i.include? '.pdf'
|
140
|
+
use_this_input_file(i)
|
141
|
+
i = DEFAULT_START_PAGE
|
142
|
+
end
|
143
|
+
i = i.to_i
|
144
|
+
@start_page = i
|
145
|
+
end
|
146
|
+
|
147
|
+
# ========================================================================= #
|
148
|
+
# === report_to_the_user_where_we_stored_the_new_pdf_file
|
149
|
+
# ========================================================================= #
|
150
|
+
def report_to_the_user_where_we_stored_the_new_pdf_file
|
151
|
+
_ = output_file?
|
152
|
+
if File.exist? _
|
153
|
+
opnn; e 'Finished storing at `'+sfile(_)+'`.'
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
# ========================================================================= #
|
158
|
+
# === check_against_menu (menu tag)
|
159
|
+
# ========================================================================= #
|
160
|
+
def check_against_menu(i = nil)
|
161
|
+
case i
|
162
|
+
when '--help','HELP'
|
163
|
+
e 'Usage example:'
|
164
|
+
e ' ext_pdf foo.pdf 1 100'
|
165
|
+
exit
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# ========================================================================= #
|
170
|
+
# === start_page?
|
171
|
+
# ========================================================================= #
|
172
|
+
def start_page?
|
173
|
+
@start_page.to_s
|
174
|
+
end; alias which_page? start_page? # === which_page?
|
175
|
+
|
176
|
+
# ========================================================================= #
|
177
|
+
# === calculate_last_page
|
178
|
+
#
|
179
|
+
# This will calculate which page must be the last.
|
180
|
+
# ========================================================================= #
|
181
|
+
def calculate_last_page
|
182
|
+
return start_page?.to_i + (@extract_n_pdf_files.to_i - 1)
|
183
|
+
end
|
184
|
+
|
185
|
+
# ========================================================================= #
|
186
|
+
# === difference?
|
187
|
+
# ========================================================================= #
|
188
|
+
def difference?
|
189
|
+
return (calculate_last_page - start_page?.to_i)
|
190
|
+
end; alias n_times difference? # === n_times
|
191
|
+
|
192
|
+
# ========================================================================= #
|
193
|
+
# === output_file?
|
194
|
+
# ========================================================================= #
|
195
|
+
def output_file?
|
196
|
+
@output_file
|
197
|
+
end
|
198
|
+
|
199
|
+
# ========================================================================= #
|
200
|
+
# === report_to_the_user_how_many_pages_we_extracted
|
201
|
+
# ========================================================================= #
|
202
|
+
def report_to_the_user_how_many_pages_we_extracted
|
203
|
+
n_pdf_pages = @extract_n_pdf_files.to_i
|
204
|
+
if File.exist? input_file?
|
205
|
+
opnn; e 'We extracted '+sfancy(n_pdf_pages.to_s)+' pdf pages.'
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
# ========================================================================= #
|
210
|
+
# === report_to_the_user
|
211
|
+
# ========================================================================= #
|
212
|
+
def report_to_the_user
|
213
|
+
report_to_the_user_how_many_pages_we_extracted
|
214
|
+
report_to_the_user_where_we_stored_the_new_pdf_file
|
215
|
+
end
|
216
|
+
|
217
|
+
# ========================================================================= #
|
218
|
+
# === name_of_pdf_file?
|
219
|
+
# ========================================================================= #
|
220
|
+
def name_of_pdf_file?
|
221
|
+
@name_of_pdf_file
|
222
|
+
end; alias input_file? name_of_pdf_file? # === input_file?
|
223
|
+
|
224
|
+
# ========================================================================= #
|
225
|
+
# === run_verbose_system_command
|
226
|
+
# ========================================================================= #
|
227
|
+
def run_verbose_system_command
|
228
|
+
n_times.times.each {|index|
|
229
|
+
start = start_page?.to_i+index.to_i
|
230
|
+
_ = ''
|
231
|
+
_ << 'gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER'
|
232
|
+
_ << ' -dFirstPage='+start.to_s
|
233
|
+
_ << ' -dLastPage='+( start.to_i ).to_s
|
234
|
+
_ << ' -sOutputFile='+start.to_s+'_'+output_file?
|
235
|
+
_ << ' '+name_of_pdf_file?.to_s
|
236
|
+
esystem _
|
237
|
+
}
|
238
|
+
end
|
239
|
+
|
240
|
+
# ========================================================================= #
|
241
|
+
# === determine_output_file
|
242
|
+
# ========================================================================= #
|
243
|
+
def determine_output_file
|
244
|
+
# @output_file = 'extracted_page_'+which_page?+'_from_file_'+name_of_pdf_file?
|
245
|
+
@output_file = 'extracted_page_from_file_'+name_of_pdf_file?
|
246
|
+
end
|
247
|
+
|
248
|
+
# ========================================================================= #
|
249
|
+
# === set_end_page
|
250
|
+
# ========================================================================= #
|
251
|
+
def set_extract_n_pdf_files(i = DEFAULT_EXTRACT_N_PDF_FILES)
|
252
|
+
i = DEFAULT_EXTRACT_N_PDF_FILES if i.nil?
|
253
|
+
i = i.to_i
|
254
|
+
if i > ::PdfParadise.n_pdf_pages?(name_of_the_pdf_file?)
|
255
|
+
i = ::PdfParadise.n_pdf_pages?(name_of_the_pdf_file?)
|
256
|
+
end
|
257
|
+
@extract_n_pdf_files = i
|
258
|
+
end; alias set_end_page set_extract_n_pdf_files # === set_end_page
|
259
|
+
|
260
|
+
# ========================================================================= #
|
261
|
+
# === opnn
|
262
|
+
# ========================================================================= #
|
263
|
+
def opnn
|
264
|
+
super(NAMESPACE)
|
265
|
+
end
|
266
|
+
|
267
|
+
# ========================================================================= #
|
268
|
+
# === run (run tag)
|
269
|
+
# ========================================================================= #
|
270
|
+
def run
|
271
|
+
determine_output_file
|
272
|
+
run_verbose_system_command
|
273
|
+
report_to_the_user
|
274
|
+
end
|
275
|
+
|
276
|
+
end; end
|
277
|
+
|
278
|
+
if __FILE__ == $PROGRAM_NAME
|
279
|
+
PdfParadise::ExtractPdfPage.new(ARGV[0], ARGV[1], ARGV[2])
|
280
|
+
end # epdf
|
@@ -0,0 +1,113 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: false
|
4
|
+
# =========================================================================== #
|
5
|
+
# === PdfParadise::PdfOptimizer
|
6
|
+
#
|
7
|
+
# /screen selects low-resolution output similar to the Acrobat Distiller
|
8
|
+
# "Screen Optimized" setting.
|
9
|
+
# /ebook selects medium-resolution output similar to the Acrobat Distiller
|
10
|
+
# "eBook" setting.
|
11
|
+
# /printer selects output similar to the Acrobat Distiller "Print Optimized"
|
12
|
+
# setting.
|
13
|
+
# /prepress selects output similar to Acrobat Distiller "Prepress Optimized"
|
14
|
+
# setting.
|
15
|
+
# /default selects output intended to be useful across a wide variety of
|
16
|
+
# uses, possibly at the expense of a larger output file.
|
17
|
+
#
|
18
|
+
# Usage example:
|
19
|
+
#
|
20
|
+
# PdfParadise::PdfOptimizer.new(ARGV)
|
21
|
+
#
|
22
|
+
# =========================================================================== #
|
23
|
+
# require 'pdf_paradise/utility_scripts/pdf_optimizer.rb'
|
24
|
+
# =========================================================================== #
|
25
|
+
require 'pdf_paradise/base/base.rb'
|
26
|
+
|
27
|
+
module PdfParadise
|
28
|
+
|
29
|
+
class PdfOptimizer < ::PdfParadise::Base # === PdfParadise::PdfOptimizer
|
30
|
+
|
31
|
+
include SaveFile
|
32
|
+
|
33
|
+
# ========================================================================= #
|
34
|
+
# === initialize
|
35
|
+
# ========================================================================= #
|
36
|
+
def initialize(
|
37
|
+
i = nil,
|
38
|
+
run_already = true
|
39
|
+
)
|
40
|
+
reset
|
41
|
+
set_input(i)
|
42
|
+
run if run_already
|
43
|
+
end
|
44
|
+
|
45
|
+
# ========================================================================= #
|
46
|
+
# === reset (reset tag)
|
47
|
+
# ========================================================================= #
|
48
|
+
def reset
|
49
|
+
end
|
50
|
+
|
51
|
+
# ========================================================================= #
|
52
|
+
# === set_input
|
53
|
+
# ========================================================================= #
|
54
|
+
def set_input(i = '')
|
55
|
+
i = i.first if i.is_a? Array
|
56
|
+
i = i.to_s.dup
|
57
|
+
@input = i
|
58
|
+
end
|
59
|
+
|
60
|
+
# ========================================================================= #
|
61
|
+
# === input?
|
62
|
+
# ========================================================================= #
|
63
|
+
def input?
|
64
|
+
@input
|
65
|
+
end; alias input_file input? # === input_file
|
66
|
+
alias input_file? input? # === input_file?
|
67
|
+
|
68
|
+
# ========================================================================= #
|
69
|
+
# === output_file?
|
70
|
+
# ========================================================================= #
|
71
|
+
def output_file?
|
72
|
+
'output.pdf'
|
73
|
+
end; alias output_pdf? output_file? # === output_pdf?
|
74
|
+
|
75
|
+
# ========================================================================= #
|
76
|
+
# === use_ghostscript?
|
77
|
+
# ========================================================================= #
|
78
|
+
def use_ghostscript?
|
79
|
+
true # For now this is hardcoded.
|
80
|
+
end
|
81
|
+
|
82
|
+
# ========================================================================= #
|
83
|
+
# === output_ps
|
84
|
+
# ========================================================================= #
|
85
|
+
def output_ps
|
86
|
+
'output.ps'
|
87
|
+
end
|
88
|
+
|
89
|
+
# ========================================================================= #
|
90
|
+
# === run (run tag)
|
91
|
+
# ========================================================================= #
|
92
|
+
def run
|
93
|
+
# ======================================================================= #
|
94
|
+
# We have two different solutions.
|
95
|
+
# ======================================================================= #
|
96
|
+
if use_ghostscript?
|
97
|
+
_ = 'gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen '\
|
98
|
+
'-dNOPAUSE -dQUIET -dBATCH -sOutputFile='+
|
99
|
+
output_file?+' '+
|
100
|
+
input_file?
|
101
|
+
else
|
102
|
+
_ = 'pdf2ps '+input?+' '+output_ps
|
103
|
+
esystem _
|
104
|
+
_ = 'ps2pdf '+output_ps+' '+output_pdf?
|
105
|
+
end
|
106
|
+
esystem _
|
107
|
+
end
|
108
|
+
|
109
|
+
end; end
|
110
|
+
|
111
|
+
if __FILE__ == $PROGRAM_NAME
|
112
|
+
PdfParadise::PdfOptimizer.new(ARGV)
|
113
|
+
end # pdfoptimizer
|
@@ -0,0 +1,150 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === PdfParadise::PdfStatistics
|
6
|
+
#
|
7
|
+
# This class will make use of PDF::Reader to provide us with some
|
8
|
+
# statistical information about a given .pdf file.
|
9
|
+
#
|
10
|
+
# You can also ouput information from a specific page.
|
11
|
+
#
|
12
|
+
# PDF is a page based file format, so most visible information
|
13
|
+
# is available via page-based iteration
|
14
|
+
#
|
15
|
+
# reader = PDF::Reader.new("somefile.pdf")
|
16
|
+
#
|
17
|
+
# reader.pages.each { |page|
|
18
|
+
# puts page.fonts
|
19
|
+
# puts page.text
|
20
|
+
# puts page.raw_content
|
21
|
+
# }
|
22
|
+
#
|
23
|
+
# Usage example:
|
24
|
+
#
|
25
|
+
# PdfParadise::PdfStatistics.new(ARGV)
|
26
|
+
#
|
27
|
+
# =========================================================================== #
|
28
|
+
# require 'pdf_paradise/utility_scripts/pdf_statistics.rb'
|
29
|
+
# =========================================================================== #
|
30
|
+
require 'pdf_paradise/base/base.rb'
|
31
|
+
|
32
|
+
module PdfParadise
|
33
|
+
|
34
|
+
class PdfStatistics < ::PdfParadise::Base # === PdfParadise::PdfStatistics
|
35
|
+
|
36
|
+
include SaveFile
|
37
|
+
|
38
|
+
# ========================================================================= #
|
39
|
+
# === initialize
|
40
|
+
# ========================================================================= #
|
41
|
+
def initialize(
|
42
|
+
i = nil,
|
43
|
+
run_already = true
|
44
|
+
)
|
45
|
+
require_pdf_reader
|
46
|
+
reset
|
47
|
+
set_input(i)
|
48
|
+
run if run_already
|
49
|
+
end
|
50
|
+
|
51
|
+
# ========================================================================= #
|
52
|
+
# === reset (reset tag)
|
53
|
+
# ========================================================================= #
|
54
|
+
def reset
|
55
|
+
end
|
56
|
+
|
57
|
+
# ========================================================================= #
|
58
|
+
# === require_pdf_reader
|
59
|
+
# ========================================================================= #
|
60
|
+
def require_pdf_reader
|
61
|
+
old_verbose = $VERBOSE
|
62
|
+
$VERBOSE = nil
|
63
|
+
require 'pdf-reader'
|
64
|
+
$VERBOSE = old_verbose # Restore it again here.
|
65
|
+
end
|
66
|
+
|
67
|
+
# ========================================================================= #
|
68
|
+
# === set_input
|
69
|
+
# ========================================================================= #
|
70
|
+
def set_input(i = '')
|
71
|
+
i = i.first if i.is_a? Array
|
72
|
+
i = i.to_s.dup
|
73
|
+
@input = i
|
74
|
+
end
|
75
|
+
|
76
|
+
# ========================================================================= #
|
77
|
+
# === input?
|
78
|
+
# ========================================================================= #
|
79
|
+
def input?
|
80
|
+
@input
|
81
|
+
end
|
82
|
+
|
83
|
+
# ========================================================================= #
|
84
|
+
# === instantiate_reader_object
|
85
|
+
# ========================================================================= #
|
86
|
+
def instantiate_reader_object
|
87
|
+
@reader = PDF::Reader.new(input?)
|
88
|
+
end
|
89
|
+
|
90
|
+
# ========================================================================= #
|
91
|
+
# === show_extended_info
|
92
|
+
#
|
93
|
+
# This will tap into the .info method.
|
94
|
+
# ========================================================================= #
|
95
|
+
def show_extended_info
|
96
|
+
hash = @reader.info
|
97
|
+
ljust = 32
|
98
|
+
if hash.has_key? :Title
|
99
|
+
e 'The title of this .pdf is: '.ljust(ljust)+simp(hash[:Title])
|
100
|
+
end
|
101
|
+
if hash.has_key? :CreationDate
|
102
|
+
e 'This .pdf was created at: '.ljust(ljust)+simp(hash[:CreationDate])
|
103
|
+
end
|
104
|
+
if hash.has_key? :Author
|
105
|
+
e 'The author of this .pdf is: '.ljust(ljust)+simp(hash[:Author])
|
106
|
+
end
|
107
|
+
if hash.has_key? :Producer
|
108
|
+
e 'It was produced via: '.ljust(ljust)+simp(hash[:Producer])
|
109
|
+
end
|
110
|
+
if hash.has_key? :ModDate
|
111
|
+
e 'It was last modified at: '.ljust(ljust)+simp(hash[:ModDate])
|
112
|
+
end
|
113
|
+
if hash.has_key? :Creator
|
114
|
+
e 'It was created via: '.ljust(ljust)+simp(hash[:Creator])
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# ========================================================================= #
|
119
|
+
# === report_n_pages_in_the_pdf_document
|
120
|
+
# ========================================================================= #
|
121
|
+
def report_n_pages_in_the_pdf_document
|
122
|
+
e 'n pages in this .pdf document: '+simp(@reader.page_count)
|
123
|
+
end
|
124
|
+
|
125
|
+
# ========================================================================= #
|
126
|
+
# === run (run tag)
|
127
|
+
# ========================================================================= #
|
128
|
+
def run
|
129
|
+
instantiate_reader_object
|
130
|
+
cliner
|
131
|
+
e ::Colours.rev+
|
132
|
+
'The PDF version for this .pdf file was: '+simp(@reader.pdf_version)
|
133
|
+
show_extended_info
|
134
|
+
# e @reader.metadata # <- This is how to obtain the metadata information.
|
135
|
+
report_n_pages_in_the_pdf_document
|
136
|
+
cliner
|
137
|
+
end
|
138
|
+
|
139
|
+
# ========================================================================= #
|
140
|
+
# === PdfParadise::PdfStatistics[]
|
141
|
+
# ========================================================================= #
|
142
|
+
def self.[](i = '')
|
143
|
+
self.class.new
|
144
|
+
end
|
145
|
+
|
146
|
+
end; end
|
147
|
+
|
148
|
+
if __FILE__ == $PROGRAM_NAME
|
149
|
+
PdfParadise::PdfStatistics.new(ARGV)
|
150
|
+
end # pdfstatistics /Depot/PDF/foobar.pdf
|