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,43 @@
|
|
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
|
+
require 'esystem'
|
8
|
+
require 'pdf_paradise/toplevel_methods/e.rb'
|
9
|
+
|
10
|
+
module PdfParadise
|
11
|
+
|
12
|
+
# ========================================================================= #
|
13
|
+
# === PdfParadise.reduce_size_of_this_pdf_file
|
14
|
+
#
|
15
|
+
# This method can be used to reduce the size of the passed .pdf file.
|
16
|
+
#
|
17
|
+
# This functionality depends on ghostscript (on the "gs" binary,
|
18
|
+
# specifically).
|
19
|
+
# ========================================================================= #
|
20
|
+
def self.reduce_size_of_this_pdf_file(this_pdf_file)
|
21
|
+
if this_pdf_file.is_a? Array
|
22
|
+
this_pdf_file.each {|entry|
|
23
|
+
reduce_size_of_this_pdf_file(entry)
|
24
|
+
}
|
25
|
+
else
|
26
|
+
guessed_name = File.basename(this_pdf_file).sub(/#{File.extname(this_pdf_file)}$/,'').dup
|
27
|
+
name_of_the_output_file = "output_#{guessed_name}".dup
|
28
|
+
name_of_the_output_file << '.pdf' unless name_of_the_output_file.end_with?('.pdf')
|
29
|
+
e
|
30
|
+
e 'Trying to reduce the size of the file '+this_pdf_file+' next:'
|
31
|
+
e
|
32
|
+
_ = 'gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 '\
|
33
|
+
'-dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH '\
|
34
|
+
'-sOutputFile='+name_of_the_output_file+' '+this_pdf_file
|
35
|
+
Esystem.esystem(_)
|
36
|
+
end
|
37
|
+
end; self.instance_eval { alias reduce_size reduce_size_of_this_pdf_file } # === PdfParadise.reduce_size
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
if __FILE__ == $PROGRAM_NAME
|
42
|
+
PdfParadise.reduce_size_of_this_pdf_file(ARGV)
|
43
|
+
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,38 @@
|
|
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
|
+
module PdfParadise
|
9
|
+
|
10
|
+
require 'pdf_paradise/toplevel_methods/e.rb'
|
11
|
+
|
12
|
+
# ========================================================================= #
|
13
|
+
# === PdfParadise.to_pdf
|
14
|
+
#
|
15
|
+
# This method can, by using soffice, convert a file such as .docx into
|
16
|
+
# the corresponding .pdf file - all on the commandline.
|
17
|
+
# ========================================================================= #
|
18
|
+
def self.to_pdf(
|
19
|
+
these_pdf_files = ARGV
|
20
|
+
)
|
21
|
+
[these_pdf_files].flatten.compact.map {|this_pdf_file|
|
22
|
+
if File.exist? this_pdf_file
|
23
|
+
_ = 'soffice --headless --invisible --convert-to pdf '+this_pdf_file
|
24
|
+
e _
|
25
|
+
system _
|
26
|
+
this_pdf_file # Return the path here, in case it has to be used.
|
27
|
+
else
|
28
|
+
e "No file exists at `#{this_pdf_file}.`"
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
if __FILE__ == $PROGRAM_NAME
|
37
|
+
PdfParadise.to_pdf(ARGV)
|
38
|
+
end # to_pdf
|
@@ -0,0 +1,166 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === PdfParadise::ConvertPdfToText
|
6
|
+
#
|
7
|
+
# This file can convert one or several .pdf files to text files.
|
8
|
+
#
|
9
|
+
# Usage examples:
|
10
|
+
#
|
11
|
+
# PdfParadise::ConvertPdfToText.new(ARGV)
|
12
|
+
#
|
13
|
+
# =========================================================================== #
|
14
|
+
# require 'pdf_paradise/utility_scripts/convert_pdf_to_text.rb'
|
15
|
+
# PdfParadise::ConvertPdfToText.new(ARGV)
|
16
|
+
# =========================================================================== #
|
17
|
+
require 'pdf_paradise/base/base.rb'
|
18
|
+
|
19
|
+
module PdfParadise
|
20
|
+
|
21
|
+
class ConvertPdfToText < ::PdfParadise::Base # === PdfParadise::ConvertPdfToText
|
22
|
+
|
23
|
+
# ========================================================================= #
|
24
|
+
# === NAMESPACE
|
25
|
+
# ========================================================================= #
|
26
|
+
NAMESPACE = inspect
|
27
|
+
|
28
|
+
# ========================================================================= #
|
29
|
+
# === initialize
|
30
|
+
# ========================================================================= #
|
31
|
+
def initialize(
|
32
|
+
i = ARGV,
|
33
|
+
run_already = true
|
34
|
+
)
|
35
|
+
reset
|
36
|
+
# ======================================================================= #
|
37
|
+
# Next designate which files are to be converted.
|
38
|
+
# ======================================================================= #
|
39
|
+
set_convert_these(i)
|
40
|
+
run if run_already
|
41
|
+
end
|
42
|
+
|
43
|
+
# ========================================================================= #
|
44
|
+
# === reset
|
45
|
+
# ========================================================================= #
|
46
|
+
def reset
|
47
|
+
super()
|
48
|
+
end
|
49
|
+
|
50
|
+
# ========================================================================= #
|
51
|
+
# === get_all_pdf_files_from_current_directory
|
52
|
+
#
|
53
|
+
# This method will obtain all pdf files from the current directory.
|
54
|
+
# ========================================================================= #
|
55
|
+
def get_all_pdf_files_from_current_directory
|
56
|
+
return Dir['*.pdf']
|
57
|
+
end
|
58
|
+
|
59
|
+
# ========================================================================= #
|
60
|
+
# === set_convert_these
|
61
|
+
#
|
62
|
+
# This method will preferentially try to work on only .pdf files.
|
63
|
+
# ========================================================================= #
|
64
|
+
def set_convert_these(
|
65
|
+
i = return_pwd
|
66
|
+
)
|
67
|
+
i = return_pwd if i.nil?
|
68
|
+
if i.is_a? String
|
69
|
+
if i.empty?
|
70
|
+
i = get_all_pdf_files_from_current_directory()
|
71
|
+
elsif File.directory? i
|
72
|
+
i = get_all_pdf_files_from_current_directory()
|
73
|
+
end
|
74
|
+
elsif i.is_a? Array
|
75
|
+
i = get_all_pdf_files_from_current_directory() if i.empty?
|
76
|
+
end
|
77
|
+
i = [i] unless i.is_a? Array
|
78
|
+
@convert_these = i # This must be an Array.
|
79
|
+
end
|
80
|
+
|
81
|
+
# ========================================================================= #
|
82
|
+
# === start_conversion
|
83
|
+
# ========================================================================= #
|
84
|
+
def start_conversion
|
85
|
+
@convert_these.each {|pdf| convert_this_pdf(pdf) }
|
86
|
+
end
|
87
|
+
|
88
|
+
# ========================================================================= #
|
89
|
+
# === opnn
|
90
|
+
# ========================================================================= #
|
91
|
+
def opnn
|
92
|
+
super(NAMESPACE)
|
93
|
+
end
|
94
|
+
|
95
|
+
# ========================================================================= #
|
96
|
+
# === convert_this_pdf
|
97
|
+
#
|
98
|
+
# This will make use of the binary called "pdftotext".
|
99
|
+
# ========================================================================= #
|
100
|
+
def convert_this_pdf(
|
101
|
+
i = @convert_these
|
102
|
+
)
|
103
|
+
if i.is_a? Array
|
104
|
+
i.each {|entry| convert_this_pdf(entry) }
|
105
|
+
else
|
106
|
+
if File.exist? i
|
107
|
+
opnn; e "Now converting `#{sfile(i)}` via #{simp('pdftotext')}."
|
108
|
+
cmdline_to_use = 'pdftotext "'+i+'"' # We use "".
|
109
|
+
@output_file = i.gsub(/#{File.extname(i)}/, '')+'.txt'
|
110
|
+
system(cmdline_to_use)
|
111
|
+
opnn; e "Storing into the file `#{sfile(@output_file)}`."
|
112
|
+
else
|
113
|
+
unless i.start_with? '--'
|
114
|
+
opnn; e 'No file called '+sfile(i)+' could be found.'
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end; alias do_convert convert_this_pdf # === do_convert
|
119
|
+
|
120
|
+
# ========================================================================= #
|
121
|
+
# === output_file?
|
122
|
+
# ========================================================================= #
|
123
|
+
def output_file?
|
124
|
+
@output_file
|
125
|
+
end
|
126
|
+
|
127
|
+
# ========================================================================= #
|
128
|
+
# === menu (menu tag)
|
129
|
+
# ========================================================================= #
|
130
|
+
def menu(
|
131
|
+
i = @convert_these
|
132
|
+
)
|
133
|
+
if i.is_a? Array
|
134
|
+
i.each {|entry| menu(entry) }
|
135
|
+
else
|
136
|
+
case i
|
137
|
+
# ===================================================================== #
|
138
|
+
# === cpdf --gui
|
139
|
+
# ===================================================================== #
|
140
|
+
when /^-?-?gui/i
|
141
|
+
do_start_the_GUI_interface
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
# ========================================================================= #
|
147
|
+
# === do_start_the_GUI_interface
|
148
|
+
# ========================================================================= #
|
149
|
+
def do_start_the_GUI_interface
|
150
|
+
require 'pdf_paradise/gui/gtk3/convert_pdf_to_text/convert_pdf_to_text.rb'
|
151
|
+
::PdfParadise::GUI::Gtk::ConvertPdfToText.run
|
152
|
+
end
|
153
|
+
|
154
|
+
# ========================================================================= #
|
155
|
+
# === run (run tag)
|
156
|
+
# ========================================================================= #
|
157
|
+
def run
|
158
|
+
menu
|
159
|
+
start_conversion
|
160
|
+
end
|
161
|
+
|
162
|
+
end; end
|
163
|
+
|
164
|
+
if __FILE__ == $PROGRAM_NAME
|
165
|
+
PdfParadise::ConvertPdfToText.new(ARGV)
|
166
|
+
end # cpdf foobar.pdf
|
@@ -0,0 +1,185 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === PdfParadise::DeleteFirstPageOfThisPdfFile
|
6
|
+
#
|
7
|
+
# This class will accept one (or several) .pdf files and then proceed
|
8
|
+
# to remove the very first .pdf page in that file. So if that pdf-file
|
9
|
+
# has had 100 pages, we will end up with 99 pages, and the first page
|
10
|
+
# will be gone.
|
11
|
+
#
|
12
|
+
# By default, the class here will create a new output file and leave
|
13
|
+
# the original file untouched.
|
14
|
+
#
|
15
|
+
# Note that the functionality made available through this class here
|
16
|
+
# depends on either the binary called "qpdf" or on the binary called
|
17
|
+
# "pdftk".
|
18
|
+
# =========================================================================== #
|
19
|
+
# require 'pdf_paradise/utility_scripts/delete_first_page_of_this_pdf_file.rb'
|
20
|
+
# =========================================================================== #
|
21
|
+
require 'pdf_paradise/base/base.rb'
|
22
|
+
require 'pdf_paradise/pdf_file_n_total_pages.rb'
|
23
|
+
|
24
|
+
module PdfParadise
|
25
|
+
|
26
|
+
class DeleteFirstPageOfThisPdfFile < Base
|
27
|
+
|
28
|
+
# ========================================================================= #
|
29
|
+
# === NAMESPACE
|
30
|
+
# ========================================================================= #
|
31
|
+
NAMESPACE = inspect
|
32
|
+
|
33
|
+
# ========================================================================= #
|
34
|
+
# === SHALL_WE_OVERWRITE_THE_ORIGINAL_PDF_FILE
|
35
|
+
# ========================================================================= #
|
36
|
+
SHALL_WE_OVERWRITE_THE_ORIGINAL_PDF_FILE = true
|
37
|
+
|
38
|
+
# ========================================================================= #
|
39
|
+
# === initialize
|
40
|
+
# ========================================================================= #
|
41
|
+
def initialize(
|
42
|
+
input_files = ARGV,
|
43
|
+
run_already = true
|
44
|
+
)
|
45
|
+
reset
|
46
|
+
set_input_files(
|
47
|
+
input_files
|
48
|
+
)
|
49
|
+
run if run_already
|
50
|
+
end
|
51
|
+
|
52
|
+
# ========================================================================= #
|
53
|
+
# === reset
|
54
|
+
# ========================================================================= #
|
55
|
+
def reset
|
56
|
+
super()
|
57
|
+
# ======================================================================= #
|
58
|
+
# === @namespace
|
59
|
+
# ======================================================================= #
|
60
|
+
@namespace = NAMESPACE
|
61
|
+
end
|
62
|
+
|
63
|
+
# ========================================================================= #
|
64
|
+
# === set_input_files
|
65
|
+
# ========================================================================= #
|
66
|
+
def set_input_files(i)
|
67
|
+
i = [i] unless i.is_a? Array
|
68
|
+
# ======================================================================= #
|
69
|
+
# Next, if i is empty, and we are on Roebe, we will use the default
|
70
|
+
# book, if a certain ENV variable exists AND if the file that points
|
71
|
+
# to that location also exists.
|
72
|
+
# ======================================================================= #
|
73
|
+
if i.empty? and is_on_roebe?
|
74
|
+
if ENV.has_key?('MAIN_BOOK') and
|
75
|
+
File.exist?(ENV['MAIN_BOOK'])
|
76
|
+
this_file = ENV['MAIN_BOOK'].dup
|
77
|
+
e "#{rev}As we are on roebe, we will use this file:"
|
78
|
+
e
|
79
|
+
e sfile(" #{this_file}")
|
80
|
+
e
|
81
|
+
i << this_file
|
82
|
+
end
|
83
|
+
end
|
84
|
+
@input_files = i
|
85
|
+
sanitize_input_files
|
86
|
+
end
|
87
|
+
|
88
|
+
# ========================================================================= #
|
89
|
+
# === sanitize_input_files
|
90
|
+
# ========================================================================= #
|
91
|
+
def sanitize_input_files
|
92
|
+
unless @input_files.empty?
|
93
|
+
# ===================================================================== #
|
94
|
+
# Select only .pdf files next.
|
95
|
+
# ===================================================================== #
|
96
|
+
@input_files.select! {|entry|
|
97
|
+
entry.end_with? '.pdf'
|
98
|
+
}
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# ========================================================================= #
|
103
|
+
# === process_each_pdf
|
104
|
+
# ========================================================================= #
|
105
|
+
def process_each_pdf
|
106
|
+
@input_files.each {|this_pdf_file|
|
107
|
+
# ===================================================================== #
|
108
|
+
# First, we must find out how many pdf pages are in the given
|
109
|
+
# pdf file at hand.
|
110
|
+
# ===================================================================== #
|
111
|
+
if File.exist? this_pdf_file
|
112
|
+
opnn; e 'Now working on the .pdf file '+sfancy(this_pdf_file)
|
113
|
+
has_n_pages = PdfParadise.n_pages_in_this_pdf_file?(this_pdf_file)
|
114
|
+
if use_pdftk?
|
115
|
+
_ = 'pdftk '+this_pdf_file+' cat 2-'+(has_n_pages.to_i).to_s+' '+
|
116
|
+
has_n_pages.to_s+'-end output '+
|
117
|
+
name_of_the_output_file?(this_pdf_file)
|
118
|
+
else # else we use qpdf
|
119
|
+
_ = 'qpdf --pages '+this_pdf_file+' 2-'+(has_n_pages.to_i).to_s+' -- '+
|
120
|
+
this_pdf_file+' '+name_of_the_output_file?(this_pdf_file)
|
121
|
+
end
|
122
|
+
esystem _
|
123
|
+
if SHALL_WE_OVERWRITE_THE_ORIGINAL_PDF_FILE
|
124
|
+
# ================================================================= #
|
125
|
+
# In this case we will overwrite the original .pdf file.
|
126
|
+
# ================================================================= #
|
127
|
+
mv(
|
128
|
+
name_of_the_output_file?(this_pdf_file),
|
129
|
+
this_pdf_file
|
130
|
+
)
|
131
|
+
end
|
132
|
+
else
|
133
|
+
opnn; no_file_exists_at(this_pdf_file)
|
134
|
+
end
|
135
|
+
}
|
136
|
+
end
|
137
|
+
|
138
|
+
# ========================================================================= #
|
139
|
+
# === use_pdftk?
|
140
|
+
# ========================================================================= #
|
141
|
+
def use_pdftk?
|
142
|
+
false
|
143
|
+
end
|
144
|
+
|
145
|
+
# ========================================================================= #
|
146
|
+
# === input?
|
147
|
+
# ========================================================================= #
|
148
|
+
def input?
|
149
|
+
@input_files
|
150
|
+
end
|
151
|
+
|
152
|
+
# ========================================================================= #
|
153
|
+
# === name_of_the_output_file?
|
154
|
+
#
|
155
|
+
# This method will determine the output file of the .pdf file.
|
156
|
+
# ========================================================================= #
|
157
|
+
def name_of_the_output_file?(i)
|
158
|
+
i.sub(/\.pdf$/,'')+'_output_file.pdf'
|
159
|
+
end; alias output? name_of_the_output_file? # === output?
|
160
|
+
|
161
|
+
# ========================================================================= #
|
162
|
+
# === run
|
163
|
+
# ========================================================================= #
|
164
|
+
def run
|
165
|
+
process_each_pdf
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
# =========================================================================== #
|
171
|
+
# === PdfParadise.delete_first_page_of_this_pdf_file
|
172
|
+
#
|
173
|
+
# Easier method-way to invoke the above class.
|
174
|
+
# =========================================================================== #
|
175
|
+
def self.delete_first_page_of_this_pdf_file(i = ARGV)
|
176
|
+
PdfParadise::DeleteFirstPageOfThisPdfFile.new(i)
|
177
|
+
end; self.instance_eval {
|
178
|
+
alias remove_the_first_page_of_this_pdf_file delete_first_page_of_this_pdf_file
|
179
|
+
} # === PdfParadise.remove_the_first_page_of_this_pdf_file
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
if __FILE__ == $PROGRAM_NAME
|
184
|
+
PdfParadise::DeleteFirstPageOfThisPdfFile.new(ARGV)
|
185
|
+
end # delete_first_page_of_this_pdf_file
|