pdf_paradise 0.3.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,351 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# === PdfParadise::GUI::UniversalWidgets::ToPDF
|
|
6
|
+
#
|
|
7
|
+
# Usage example:
|
|
8
|
+
#
|
|
9
|
+
# PdfParadise::GUI::UniversalWidgets::ToPDF.new(ARGV)
|
|
10
|
+
#
|
|
11
|
+
# =========================================================================== #
|
|
12
|
+
# require 'pdf_paradise/gui/universal_widgets/to_pdf/to_pdf.rb'
|
|
13
|
+
# =========================================================================== #
|
|
14
|
+
require 'pdf_paradise/base/base.rb'
|
|
15
|
+
|
|
16
|
+
module PdfParadise
|
|
17
|
+
|
|
18
|
+
module GUI
|
|
19
|
+
|
|
20
|
+
module UniversalWidgets
|
|
21
|
+
|
|
22
|
+
class ToPDF < ::PdfParadise::Base # === PdfParadise::GUI::UniversalWidgets::ToPDF
|
|
23
|
+
|
|
24
|
+
require 'universal_widgets/base_module/base_module.rb'
|
|
25
|
+
include ::UniversalWidgets::BaseModule
|
|
26
|
+
|
|
27
|
+
require 'pdf_paradise/toplevel_methods/to_pdf.rb'
|
|
28
|
+
|
|
29
|
+
begin
|
|
30
|
+
require 'pdf-reader' # Add an optional dependency here.
|
|
31
|
+
rescue LoadError; end
|
|
32
|
+
|
|
33
|
+
# ========================================================================= #
|
|
34
|
+
# === TITLE
|
|
35
|
+
# ========================================================================= #
|
|
36
|
+
TITLE = 'Convert to .pdf'
|
|
37
|
+
|
|
38
|
+
# ========================================================================= #
|
|
39
|
+
# === FONT_SIZE
|
|
40
|
+
# ========================================================================= #
|
|
41
|
+
FONT_SIZE = 18
|
|
42
|
+
|
|
43
|
+
# ========================================================================= #
|
|
44
|
+
# === USE_THIS_FONT
|
|
45
|
+
# ========================================================================= #
|
|
46
|
+
USE_THIS_FONT = :hack_28
|
|
47
|
+
|
|
48
|
+
# ========================================================================= #
|
|
49
|
+
# === WIDTH
|
|
50
|
+
# ========================================================================= #
|
|
51
|
+
WIDTH = '95% or minimum 1820px'
|
|
52
|
+
|
|
53
|
+
# ========================================================================= #
|
|
54
|
+
# === HEIGHT
|
|
55
|
+
# ========================================================================= #
|
|
56
|
+
HEIGHT = '35% or minimum 840px'
|
|
57
|
+
|
|
58
|
+
# ========================================================================= #
|
|
59
|
+
# === LARGER_FONT
|
|
60
|
+
# ========================================================================= #
|
|
61
|
+
LARGER_FONT = :hack_24
|
|
62
|
+
|
|
63
|
+
# ========================================================================= #
|
|
64
|
+
# === SMALLER_FONT
|
|
65
|
+
# ========================================================================= #
|
|
66
|
+
SMALLER_FONT = :hack_28
|
|
67
|
+
|
|
68
|
+
# ========================================================================= #
|
|
69
|
+
# === initialize
|
|
70
|
+
# ========================================================================= #
|
|
71
|
+
def initialize(
|
|
72
|
+
commandline_arguments = nil,
|
|
73
|
+
run_already = true
|
|
74
|
+
)
|
|
75
|
+
determine_the_GUI_to_be_used(commandline_arguments) # This must come first, even before reset().
|
|
76
|
+
reset
|
|
77
|
+
set_commandline_arguments(
|
|
78
|
+
commandline_arguments
|
|
79
|
+
)
|
|
80
|
+
run if run_already
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# ========================================================================= #
|
|
84
|
+
# === reset (reset tag)
|
|
85
|
+
# ========================================================================= #
|
|
86
|
+
def reset
|
|
87
|
+
super() if respond_to?(:super)
|
|
88
|
+
reset_the_base_module
|
|
89
|
+
reset_the_internal_variables
|
|
90
|
+
infer_the_namespace
|
|
91
|
+
# ======================================================================= #
|
|
92
|
+
# === @configuration
|
|
93
|
+
# ======================================================================= #
|
|
94
|
+
@configuration = [true, __dir__, namespace?]
|
|
95
|
+
# ======================================================================= #
|
|
96
|
+
# === Set the title, width, height and the font in use.
|
|
97
|
+
# ======================================================================= #
|
|
98
|
+
title_width_height_font(TITLE, WIDTH, HEIGHT, USE_THIS_FONT)
|
|
99
|
+
if use_gtk3?
|
|
100
|
+
append_project_css_file
|
|
101
|
+
use_gtk_paradise_project_css_file
|
|
102
|
+
end
|
|
103
|
+
infer_the_size_automatically
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# ========================================================================= #
|
|
107
|
+
# === create_the_statusbar
|
|
108
|
+
# ========================================================================= #
|
|
109
|
+
def create_the_statusbar
|
|
110
|
+
@statusbar = gtk_statusbar_with_handle
|
|
111
|
+
@status_bar_context_id = @statusbar.get_context_id('to_pdf')
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# ========================================================================= #
|
|
115
|
+
# === create_skeleton (create tag, skeleton tag)
|
|
116
|
+
# ========================================================================= #
|
|
117
|
+
def create_the_skeleton
|
|
118
|
+
create_the_buttons
|
|
119
|
+
create_the_statusbar
|
|
120
|
+
create_the_entry_filename
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# ========================================================================= #
|
|
124
|
+
# === connect_the_skeleton (connect tag)
|
|
125
|
+
# ========================================================================= #
|
|
126
|
+
def connect_the_skeleton
|
|
127
|
+
abort_on_exception
|
|
128
|
+
|
|
129
|
+
chdir('/Depot/j/') if File.directory? '/Depot/j/'
|
|
130
|
+
|
|
131
|
+
outer_vbox = create_vbox
|
|
132
|
+
|
|
133
|
+
text1 = label('Input the filename that you wish to convert here:')
|
|
134
|
+
text1.make_selectable
|
|
135
|
+
text1.deselect
|
|
136
|
+
outer_vbox.minimal(
|
|
137
|
+
text1, 1
|
|
138
|
+
)
|
|
139
|
+
outer_vbox.minimal(@entry_filename, 1)
|
|
140
|
+
outer_vbox.minimal(@button_choose_file, 1)
|
|
141
|
+
small_hbox = create_hbox
|
|
142
|
+
small_hbox.minimal(@button_do_convert)
|
|
143
|
+
small_hbox.hcenter
|
|
144
|
+
outer_vbox.minimal(small_hbox, 1)
|
|
145
|
+
hbox = create_hbox
|
|
146
|
+
hbox.maximal(@statusbar, 1)
|
|
147
|
+
hbox.minimal(@button_open_the_converted_file, 1)
|
|
148
|
+
outer_vbox.minimal(hbox)
|
|
149
|
+
@text_buffer = create_text_buffer
|
|
150
|
+
@text_view = create_text_view(@text_buffer)
|
|
151
|
+
@scrolled_window = create_scrolled_window(@text_view) { :top_to_bottom }
|
|
152
|
+
@scrolled_window.bblack1
|
|
153
|
+
@scrolled_window.css_class('pad4px')
|
|
154
|
+
@scrolled_window.width_height(500, 400)
|
|
155
|
+
outer_vbox.minimal(@scrolled_window)
|
|
156
|
+
|
|
157
|
+
window = create_window_or_runner(
|
|
158
|
+
widget: outer_vbox,
|
|
159
|
+
width: width?,
|
|
160
|
+
height: height?,
|
|
161
|
+
title: title?,
|
|
162
|
+
font: font?
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
window.set_padding(padding?)
|
|
166
|
+
window.set_border_size(border_size?)
|
|
167
|
+
window.show_all
|
|
168
|
+
do_style_all_buttons_in_a_uniform_manner
|
|
169
|
+
do_jump_into_the_scrolled_window
|
|
170
|
+
run_main
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
# ========================================================================= #
|
|
174
|
+
# === do_jump_into_the_scrolled_window
|
|
175
|
+
# ========================================================================= #
|
|
176
|
+
def do_jump_into_the_scrolled_window
|
|
177
|
+
@scrolled_window.do_focus
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# ========================================================================= #
|
|
181
|
+
# === do_style_all_buttons_in_a_uniform_manner
|
|
182
|
+
# ========================================================================= #
|
|
183
|
+
def do_style_all_buttons_in_a_uniform_manner
|
|
184
|
+
return_all_buttons.each {|entry|
|
|
185
|
+
entry.bblack2
|
|
186
|
+
entry.pad5px
|
|
187
|
+
}
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# ========================================================================= #
|
|
191
|
+
# === favicon?
|
|
192
|
+
# ========================================================================= #
|
|
193
|
+
def favicon?
|
|
194
|
+
:tabble
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
# ========================================================================= #
|
|
198
|
+
# === create_the_buttons (buttons tag, button tag)
|
|
199
|
+
# ========================================================================= #
|
|
200
|
+
def create_the_buttons
|
|
201
|
+
# ======================================================================= #
|
|
202
|
+
# === @button_do_convert
|
|
203
|
+
# ======================================================================= #
|
|
204
|
+
@button_do_convert = button('_Convert it to .pdf format') {
|
|
205
|
+
:do_convert_the_given_file
|
|
206
|
+
}
|
|
207
|
+
#@button_do_convert.disallow_resizing
|
|
208
|
+
@button_do_convert.css_class('clear_background')
|
|
209
|
+
@button_do_convert.on_hover(:steelblue)
|
|
210
|
+
@button_do_convert.css_class('BG_lightblue')
|
|
211
|
+
@button_do_convert.pad5px
|
|
212
|
+
@button_do_convert.hint = 'This will use libreoffice '\
|
|
213
|
+
'to convert the file at hand into a <b>.pdf file</b>.'
|
|
214
|
+
# ======================================================================= #
|
|
215
|
+
# === @button_choose_file (open tag)
|
|
216
|
+
#
|
|
217
|
+
# This is the "Open File" button.
|
|
218
|
+
# ======================================================================= #
|
|
219
|
+
@button_choose_file = create_file_chooser_button
|
|
220
|
+
@button_choose_file.on_clicked {
|
|
221
|
+
create_a_new_file_chooser_dialog
|
|
222
|
+
main_entry?.set_text(main_file?.to_s)
|
|
223
|
+
}
|
|
224
|
+
# ======================================================================= #
|
|
225
|
+
# === @button_open_the_converted_file
|
|
226
|
+
# ======================================================================= #
|
|
227
|
+
@button_open_the_converted_file = create_button('_Open the converted file')
|
|
228
|
+
@button_open_the_converted_file.hint = 'Click to open the '\
|
|
229
|
+
'converted file via main .pdf reader.'
|
|
230
|
+
@button_open_the_converted_file.on_clicked {
|
|
231
|
+
do_open_the_converted_file_via_a_pdf_reader
|
|
232
|
+
}
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
# ========================================================================= #
|
|
236
|
+
# === entry_filename?
|
|
237
|
+
# ========================================================================= #
|
|
238
|
+
def entry_filename?
|
|
239
|
+
@entry_filename
|
|
240
|
+
end; alias main_entry? entry_filename? # === main_entry?
|
|
241
|
+
|
|
242
|
+
# ========================================================================= #
|
|
243
|
+
# === create_the_entry_filename
|
|
244
|
+
# ========================================================================= #
|
|
245
|
+
def create_the_entry_filename
|
|
246
|
+
@entry_filename = create_entry
|
|
247
|
+
@entry_filename.clear_background
|
|
248
|
+
@entry_filename.bblack1
|
|
249
|
+
@entry_filename.yellow_background
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
# ========================================================================= #
|
|
253
|
+
# === do_open_the_converted_file_via_a_pdf_reader
|
|
254
|
+
# ========================================================================= #
|
|
255
|
+
def do_open_the_converted_file_via_a_pdf_reader(
|
|
256
|
+
stored_here = stored_where?
|
|
257
|
+
)
|
|
258
|
+
if File.exist? stored_here
|
|
259
|
+
esystem "evince #{stored_here}"
|
|
260
|
+
else
|
|
261
|
+
e 'No file exists at '+sfile(stored_here)+'.'
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
# ========================================================================= #
|
|
266
|
+
# === padding?
|
|
267
|
+
# ========================================================================= #
|
|
268
|
+
def padding?
|
|
269
|
+
4
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
# ========================================================================= #
|
|
273
|
+
# === border_size?
|
|
274
|
+
# ========================================================================= #
|
|
275
|
+
def border_size?
|
|
276
|
+
8
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
# ========================================================================= #
|
|
280
|
+
# === stored_where?
|
|
281
|
+
# ========================================================================= #
|
|
282
|
+
def stored_where?(
|
|
283
|
+
i = @entry_filename.text?
|
|
284
|
+
)
|
|
285
|
+
_ = PdfParadise.to_pdf(i)
|
|
286
|
+
_ = _.dup
|
|
287
|
+
_ = _.join(' ').strip if _.is_a? Array
|
|
288
|
+
_.delete_suffix!(File.extname(i))
|
|
289
|
+
_ << '.pdf' unless _.end_with? '.pdf'
|
|
290
|
+
return _.to_s
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
# ========================================================================= #
|
|
294
|
+
# === do_convert_the_given_file
|
|
295
|
+
#
|
|
296
|
+
# This is the method that will convert the target file into the
|
|
297
|
+
# .pdf file, usually by using "soffice".
|
|
298
|
+
# ========================================================================= #
|
|
299
|
+
def do_convert_the_given_file
|
|
300
|
+
_ = stored_where?
|
|
301
|
+
@statusbar.display(
|
|
302
|
+
'Stored the file at: '+_, :default, @status_bar_context_id
|
|
303
|
+
) if File.exist? _
|
|
304
|
+
# ======================================================================= #
|
|
305
|
+
# Read in the .pdf file if it exists and if the PDF::Reader namespace
|
|
306
|
+
# exists.
|
|
307
|
+
# ======================================================================= #
|
|
308
|
+
if File.exist?(_) and
|
|
309
|
+
Object.const_defined?(:PDF) and PDF.const_defined?(:Reader)
|
|
310
|
+
reader = PDF::Reader.new(_)
|
|
311
|
+
page = reader.page(1)
|
|
312
|
+
use_this_text = page.text.to_s
|
|
313
|
+
@scrolled_window.set_text(use_this_text.to_s)
|
|
314
|
+
end
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
# ========================================================================= #
|
|
318
|
+
# === run (run tag)
|
|
319
|
+
# ========================================================================= #
|
|
320
|
+
def run
|
|
321
|
+
run_super
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
# ========================================================================= #
|
|
325
|
+
# === PdfParadise::GUI::Gtk::ToPDF.run
|
|
326
|
+
# ========================================================================= #
|
|
327
|
+
def self.run(
|
|
328
|
+
i = ARGV
|
|
329
|
+
)
|
|
330
|
+
require 'gtk_paradise/run'
|
|
331
|
+
_ = ::PdfParadise::GUI::Gtk::ToPDF.new(i)
|
|
332
|
+
r = ::Gtk.run
|
|
333
|
+
r << _
|
|
334
|
+
r.automatic_size
|
|
335
|
+
r.automatic_title
|
|
336
|
+
r.easy_exit
|
|
337
|
+
r.top_left_then_run
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
# ========================================================================= #
|
|
341
|
+
# === PdfParadise::GUI::UniversalWidgets::ToPDF[]
|
|
342
|
+
# ========================================================================= #
|
|
343
|
+
def self.[](i = ARGV)
|
|
344
|
+
new(i)
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
end; end; end; end
|
|
348
|
+
|
|
349
|
+
if __FILE__ == $PROGRAM_NAME
|
|
350
|
+
PdfParadise::GUI::UniversalWidgets::ToPDF.new(ARGV)
|
|
351
|
+
end # gtk_todo_viewer
|
|
File without changes
|
|
@@ -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
|