origamindee 3.0.0
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/CHANGELOG.md +89 -0
- data/COPYING.LESSER +165 -0
- data/README.md +131 -0
- data/bin/config/pdfcop.conf.yml +236 -0
- data/bin/pdf2pdfa +87 -0
- data/bin/pdf2ruby +333 -0
- data/bin/pdfcop +476 -0
- data/bin/pdfdecompress +97 -0
- data/bin/pdfdecrypt +91 -0
- data/bin/pdfencrypt +113 -0
- data/bin/pdfexplode +223 -0
- data/bin/pdfextract +277 -0
- data/bin/pdfmetadata +143 -0
- data/bin/pdfsh +12 -0
- data/bin/shell/console.rb +128 -0
- data/bin/shell/hexdump.rb +59 -0
- data/bin/shell/irbrc +69 -0
- data/examples/README.md +34 -0
- data/examples/attachments/attachment.rb +38 -0
- data/examples/attachments/nested_document.rb +51 -0
- data/examples/encryption/encryption.rb +28 -0
- data/examples/events/events.rb +72 -0
- data/examples/flash/flash.rb +37 -0
- data/examples/flash/helloworld.swf +0 -0
- data/examples/forms/javascript.rb +54 -0
- data/examples/forms/xfa.rb +115 -0
- data/examples/javascript/hello_world.rb +22 -0
- data/examples/javascript/js_emulation.rb +54 -0
- data/examples/loop/goto.rb +32 -0
- data/examples/loop/named.rb +33 -0
- data/examples/signature/signature.rb +65 -0
- data/examples/uri/javascript.rb +56 -0
- data/examples/uri/open-uri.rb +21 -0
- data/examples/uri/submitform.rb +47 -0
- data/lib/origami/3d.rb +364 -0
- data/lib/origami/acroform.rb +321 -0
- data/lib/origami/actions.rb +318 -0
- data/lib/origami/annotations.rb +711 -0
- data/lib/origami/array.rb +242 -0
- data/lib/origami/boolean.rb +90 -0
- data/lib/origami/catalog.rb +418 -0
- data/lib/origami/collections.rb +144 -0
- data/lib/origami/compound.rb +161 -0
- data/lib/origami/destinations.rb +252 -0
- data/lib/origami/dictionary.rb +192 -0
- data/lib/origami/encryption.rb +1084 -0
- data/lib/origami/extensions/fdf.rb +347 -0
- data/lib/origami/extensions/ppklite.rb +422 -0
- data/lib/origami/filespec.rb +197 -0
- data/lib/origami/filters/ascii.rb +211 -0
- data/lib/origami/filters/ccitt/tables.rb +267 -0
- data/lib/origami/filters/ccitt.rb +357 -0
- data/lib/origami/filters/crypt.rb +38 -0
- data/lib/origami/filters/dct.rb +54 -0
- data/lib/origami/filters/flate.rb +69 -0
- data/lib/origami/filters/jbig2.rb +57 -0
- data/lib/origami/filters/jpx.rb +47 -0
- data/lib/origami/filters/lzw.rb +170 -0
- data/lib/origami/filters/predictors.rb +292 -0
- data/lib/origami/filters/runlength.rb +129 -0
- data/lib/origami/filters.rb +364 -0
- data/lib/origami/font.rb +196 -0
- data/lib/origami/functions.rb +79 -0
- data/lib/origami/graphics/colors.rb +230 -0
- data/lib/origami/graphics/instruction.rb +98 -0
- data/lib/origami/graphics/path.rb +182 -0
- data/lib/origami/graphics/patterns.rb +174 -0
- data/lib/origami/graphics/render.rb +62 -0
- data/lib/origami/graphics/state.rb +149 -0
- data/lib/origami/graphics/text.rb +225 -0
- data/lib/origami/graphics/xobject.rb +918 -0
- data/lib/origami/graphics.rb +38 -0
- data/lib/origami/header.rb +75 -0
- data/lib/origami/javascript.rb +713 -0
- data/lib/origami/linearization.rb +330 -0
- data/lib/origami/metadata.rb +172 -0
- data/lib/origami/name.rb +135 -0
- data/lib/origami/null.rb +65 -0
- data/lib/origami/numeric.rb +181 -0
- data/lib/origami/obfuscation.rb +245 -0
- data/lib/origami/object.rb +760 -0
- data/lib/origami/optionalcontent.rb +183 -0
- data/lib/origami/outline.rb +54 -0
- data/lib/origami/outputintents.rb +85 -0
- data/lib/origami/page.rb +722 -0
- data/lib/origami/parser.rb +269 -0
- data/lib/origami/parsers/fdf.rb +56 -0
- data/lib/origami/parsers/pdf/lazy.rb +176 -0
- data/lib/origami/parsers/pdf/linear.rb +122 -0
- data/lib/origami/parsers/pdf.rb +118 -0
- data/lib/origami/parsers/ppklite.rb +57 -0
- data/lib/origami/pdf.rb +1108 -0
- data/lib/origami/reference.rb +134 -0
- data/lib/origami/signature.rb +702 -0
- data/lib/origami/stream.rb +705 -0
- data/lib/origami/string.rb +444 -0
- data/lib/origami/template/patterns.rb +56 -0
- data/lib/origami/template/widgets.rb +151 -0
- data/lib/origami/trailer.rb +190 -0
- data/lib/origami/tree.rb +62 -0
- data/lib/origami/version.rb +23 -0
- data/lib/origami/webcapture.rb +100 -0
- data/lib/origami/xfa/config.rb +453 -0
- data/lib/origami/xfa/connectionset.rb +146 -0
- data/lib/origami/xfa/datasets.rb +49 -0
- data/lib/origami/xfa/localeset.rb +42 -0
- data/lib/origami/xfa/package.rb +59 -0
- data/lib/origami/xfa/pdf.rb +73 -0
- data/lib/origami/xfa/signature.rb +42 -0
- data/lib/origami/xfa/sourceset.rb +43 -0
- data/lib/origami/xfa/stylesheet.rb +44 -0
- data/lib/origami/xfa/template.rb +1691 -0
- data/lib/origami/xfa/xdc.rb +42 -0
- data/lib/origami/xfa/xfa.rb +146 -0
- data/lib/origami/xfa/xfdf.rb +43 -0
- data/lib/origami/xfa/xmpmeta.rb +43 -0
- data/lib/origami/xfa.rb +62 -0
- data/lib/origami/xreftable.rb +557 -0
- data/lib/origami.rb +47 -0
- data/test/dataset/calc.pdf +85 -0
- data/test/dataset/crypto.pdf +36 -0
- data/test/dataset/empty.pdf +49 -0
- data/test/test_actions.rb +27 -0
- data/test/test_annotations.rb +68 -0
- data/test/test_forms.rb +30 -0
- data/test/test_native_types.rb +83 -0
- data/test/test_object_tree.rb +33 -0
- data/test/test_pages.rb +60 -0
- data/test/test_pdf.rb +20 -0
- data/test/test_pdf_attachment.rb +34 -0
- data/test/test_pdf_create.rb +24 -0
- data/test/test_pdf_encrypt.rb +102 -0
- data/test/test_pdf_parse.rb +134 -0
- data/test/test_pdf_parse_lazy.rb +69 -0
- data/test/test_pdf_sign.rb +97 -0
- data/test/test_streams.rb +184 -0
- data/test/test_xrefs.rb +67 -0
- metadata +280 -0
data/bin/pdfmetadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
=begin
|
4
|
+
|
5
|
+
= Info
|
6
|
+
Prints out the metadata contained in a PDF document.
|
7
|
+
|
8
|
+
= License
|
9
|
+
Copyright (C) 2019 Guillaume Delugré.
|
10
|
+
|
11
|
+
Origami is free software: you can redistribute it and/or modify
|
12
|
+
it under the terms of the GNU Lesser General Public License as published by
|
13
|
+
the Free Software Foundation, either version 3 of the License, or
|
14
|
+
(at your option) any later version.
|
15
|
+
|
16
|
+
Origami is distributed in the hope that it will be useful,
|
17
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19
|
+
GNU Lesser General Public License for more details.
|
20
|
+
|
21
|
+
You should have received a copy of the GNU Lesser General Public License
|
22
|
+
along with Origami. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
|
24
|
+
=end
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'origami'
|
28
|
+
rescue LoadError
|
29
|
+
$: << File.join(__dir__, '../lib')
|
30
|
+
require 'origami'
|
31
|
+
end
|
32
|
+
include Origami
|
33
|
+
|
34
|
+
require 'rainbow'
|
35
|
+
require 'optparse'
|
36
|
+
require 'json'
|
37
|
+
|
38
|
+
class OptParser
|
39
|
+
BANNER = <<USAGE
|
40
|
+
Usage: #{$0} [<PDF-file>] [-i] [-x]
|
41
|
+
Prints out the metadata contained in a PDF document.
|
42
|
+
Bug reports or feature requests at: http://github.com/gdelugre/origami
|
43
|
+
|
44
|
+
Options:
|
45
|
+
USAGE
|
46
|
+
|
47
|
+
def self.parser(options)
|
48
|
+
OptionParser.new do |opts|
|
49
|
+
opts.banner = BANNER
|
50
|
+
|
51
|
+
opts.on("-i", "--info", "Extracts document info metadata") do
|
52
|
+
options[:doc_info] = true
|
53
|
+
end
|
54
|
+
|
55
|
+
opts.on("-x", "--xmp", "Extracts XMP document metadata stream") do
|
56
|
+
options[:doc_stream] = true
|
57
|
+
end
|
58
|
+
|
59
|
+
opts.on("-f", "--format [FORMAT]", %i{text json}, "Output format ('text', 'json')") do |format|
|
60
|
+
options[:output_format] = format
|
61
|
+
end
|
62
|
+
|
63
|
+
opts.on("-n", "--no-color", "Turn off colorized output.") do
|
64
|
+
options[:colors_enabled] = false
|
65
|
+
end
|
66
|
+
|
67
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
68
|
+
puts opts
|
69
|
+
exit
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.parse(args)
|
75
|
+
options = {
|
76
|
+
output_format: :text,
|
77
|
+
colors_enabled: true
|
78
|
+
}
|
79
|
+
|
80
|
+
self.parser(options).parse!(args)
|
81
|
+
|
82
|
+
options
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def print_section(name, elements)
|
87
|
+
puts Rainbow("[*] #{name}:").magenta
|
88
|
+
|
89
|
+
elements.each_pair do |name, item|
|
90
|
+
print Rainbow(name.ljust(20, ' ')).green
|
91
|
+
puts ": #{item}"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
begin
|
96
|
+
@options = OptParser.parse(ARGV)
|
97
|
+
|
98
|
+
unless @options[:doc_info] or @options[:doc_stream]
|
99
|
+
@options[:doc_info] = @options[:doc_stream] = true
|
100
|
+
end
|
101
|
+
|
102
|
+
Rainbow.enabled = @options[:colors_enabled]
|
103
|
+
|
104
|
+
target = (ARGV.empty?) ? STDIN : ARGV.shift
|
105
|
+
params =
|
106
|
+
{
|
107
|
+
verbosity: Parser::VERBOSE_QUIET,
|
108
|
+
lazy: true
|
109
|
+
}
|
110
|
+
|
111
|
+
pdf = PDF.read(target, params)
|
112
|
+
result = {}
|
113
|
+
|
114
|
+
if @options[:doc_info] and pdf.document_info?
|
115
|
+
result[:document_info] = pdf.document_info.map {|k,v|
|
116
|
+
key = k.value.to_s
|
117
|
+
obj = v.solve
|
118
|
+
str_value = obj.respond_to?(:to_utf8) ? obj.to_utf8 : obj.value.to_s
|
119
|
+
|
120
|
+
[ key, str_value ]
|
121
|
+
}.to_h
|
122
|
+
end
|
123
|
+
|
124
|
+
if @options[:doc_stream] and pdf.metadata?
|
125
|
+
result[:xmp_metadata] = pdf.metadata
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
if @options[:output_format] == :text
|
130
|
+
print_section("Document information dictionary", result[:document_info]) if result.key?(:document_info)
|
131
|
+
|
132
|
+
if result.key?(:xmp_metadata)
|
133
|
+
puts if result.key?(:document_info)
|
134
|
+
print_section("Metadata stream", result[:xmp_metadata])
|
135
|
+
end
|
136
|
+
elsif @options[:output_format] == :json
|
137
|
+
puts JSON.pretty_generate(result)
|
138
|
+
end
|
139
|
+
|
140
|
+
rescue
|
141
|
+
puts $!.backtrace.join $/
|
142
|
+
abort "#{$!.class}: #{$!.message}"
|
143
|
+
end
|
data/bin/pdfsh
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
This file is part of Origami, PDF manipulation framework for Ruby
|
4
|
+
Copyright (C) 2016 Guillaume Delugré.
|
5
|
+
|
6
|
+
Origami is free software: you can redistribute it and/or modify
|
7
|
+
it under the terms of the GNU Lesser General Public License as published by
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
9
|
+
(at your option) any later version.
|
10
|
+
|
11
|
+
Origami is distributed in the hope that it will be useful,
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
GNU Lesser General Public License for more details.
|
15
|
+
|
16
|
+
You should have received a copy of the GNU Lesser General Public License
|
17
|
+
along with Origami. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
=end
|
20
|
+
|
21
|
+
require 'tempfile'
|
22
|
+
require 'hexdump'
|
23
|
+
require 'colorize'
|
24
|
+
|
25
|
+
String.disable_colorization(false)
|
26
|
+
|
27
|
+
module Origami
|
28
|
+
module Object
|
29
|
+
def inspect
|
30
|
+
to_s
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Stream
|
35
|
+
def edit(editor = ENV['EDITOR'])
|
36
|
+
Tempfile.open("origami") do |tmpfile|
|
37
|
+
tmpfile.write(self.data)
|
38
|
+
tmpfile.flush
|
39
|
+
|
40
|
+
Process.wait Kernel.spawn "#{editor} #{tmpfile.path}"
|
41
|
+
|
42
|
+
self.data = File.read(tmpfile.path)
|
43
|
+
tmpfile.unlink
|
44
|
+
end
|
45
|
+
|
46
|
+
true
|
47
|
+
end
|
48
|
+
|
49
|
+
def inspect
|
50
|
+
self.data.hexdump
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class Page < Dictionary
|
55
|
+
def edit
|
56
|
+
each_content_stream do |stream|
|
57
|
+
stream.edit
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class PDF
|
63
|
+
if defined?(PDF::JavaScript::Engine)
|
64
|
+
class JavaScript::Engine
|
65
|
+
def shell
|
66
|
+
loop do
|
67
|
+
print "js > ".magenta
|
68
|
+
break if (line = gets).nil?
|
69
|
+
|
70
|
+
begin
|
71
|
+
puts exec(line)
|
72
|
+
rescue V8::JSError => e
|
73
|
+
puts "Error: #{e.message}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class Revision
|
81
|
+
def to_s
|
82
|
+
puts "---------- Body ----------".white.bold
|
83
|
+
@body.each_value do |obj|
|
84
|
+
print "#{obj.reference.to_s.rjust(8,' ')}".ljust(10).magenta
|
85
|
+
puts "#{obj.type}".yellow
|
86
|
+
end
|
87
|
+
|
88
|
+
puts "---------- Trailer ---------".white.bold
|
89
|
+
if not @trailer.dictionary
|
90
|
+
puts " [x] No trailer found.".blue
|
91
|
+
else
|
92
|
+
@trailer.dictionary.each_pair do |entry, value|
|
93
|
+
print " [*] ".magenta
|
94
|
+
print "#{entry}: ".yellow
|
95
|
+
puts "#{value}".red
|
96
|
+
end
|
97
|
+
|
98
|
+
print " [+] ".magenta
|
99
|
+
print "startxref: ".yellow
|
100
|
+
puts "#{@trailer.startxref}".red
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def inspect
|
105
|
+
to_s
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def to_s
|
110
|
+
puts
|
111
|
+
|
112
|
+
puts "---------- Header ----------".white.bold
|
113
|
+
print " [+] ".magenta
|
114
|
+
print "Version: ".yellow
|
115
|
+
puts "#{@header.major_version}.#{@header.minor_version}".red
|
116
|
+
|
117
|
+
@revisions.each do |revision|
|
118
|
+
revision.to_s
|
119
|
+
end
|
120
|
+
puts
|
121
|
+
end
|
122
|
+
|
123
|
+
def inspect
|
124
|
+
to_s
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
This file is part of Origami, PDF manipulation framework for Ruby
|
4
|
+
Copyright (C) 2016 Guillaume Delugré.
|
5
|
+
|
6
|
+
Origami is free software: you can redistribute it and/or modify
|
7
|
+
it under the terms of the GNU General Public License as published by
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
9
|
+
(at your option) any later version.
|
10
|
+
|
11
|
+
Origami is distributed in the hope that it will be useful,
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
GNU General Public License for more details.
|
15
|
+
|
16
|
+
You should have received a copy of the GNU General Public License
|
17
|
+
along with Origami. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
=end
|
20
|
+
|
21
|
+
require 'colorize'
|
22
|
+
|
23
|
+
class String #:nodoc:
|
24
|
+
|
25
|
+
def hexdump(bytesperline: 16, upcase: true, offsets: true, delta: 0)
|
26
|
+
dump = ""
|
27
|
+
counter = 0
|
28
|
+
|
29
|
+
while counter < self.length
|
30
|
+
offset = sprintf("%010X", counter + delta)
|
31
|
+
|
32
|
+
linelen = [ self.length - counter, bytesperline ].min
|
33
|
+
bytes = ""
|
34
|
+
linelen.times do |i|
|
35
|
+
byte = self[counter + i].ord.to_s(16).rjust(2, '0')
|
36
|
+
|
37
|
+
bytes << byte
|
38
|
+
bytes << " " unless i == bytesperline - 1
|
39
|
+
end
|
40
|
+
|
41
|
+
ascii = self[counter, linelen].ascii_print
|
42
|
+
|
43
|
+
if upcase
|
44
|
+
offset.upcase!
|
45
|
+
bytes.upcase!
|
46
|
+
end
|
47
|
+
|
48
|
+
dump << "#{offset.yellow if offsets} #{bytes.to_s.ljust(bytesperline * 3 - 1).bold} #{ascii}\n"
|
49
|
+
|
50
|
+
counter += bytesperline
|
51
|
+
end
|
52
|
+
|
53
|
+
dump
|
54
|
+
end
|
55
|
+
|
56
|
+
def ascii_print
|
57
|
+
self.gsub(/[^[[:print:]]]/, ".")
|
58
|
+
end
|
59
|
+
end
|
data/bin/shell/irbrc
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
begin
|
2
|
+
require 'origami'
|
3
|
+
rescue LoadError
|
4
|
+
$: << File.join(__dir__, '../../lib')
|
5
|
+
require 'origami'
|
6
|
+
end
|
7
|
+
include Origami
|
8
|
+
|
9
|
+
require 'console.rb'
|
10
|
+
require 'readline'
|
11
|
+
|
12
|
+
OPENSSL_SUPPORT = (defined?(OpenSSL).nil?) ? 'no' : 'yes'
|
13
|
+
JAVASCRIPT_SUPPORT = (defined?(PDF::JavaScript::Engine).nil?) ? 'no' : 'yes'
|
14
|
+
DEFAULT_BANNER = "Welcome to the PDF shell (Origami release #{Origami::VERSION}) [OpenSSL: #{OPENSSL_SUPPORT}, JavaScript: #{JAVASCRIPT_SUPPORT}]\n"
|
15
|
+
|
16
|
+
def set_completion
|
17
|
+
completionProc = proc { |input|
|
18
|
+
bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
|
19
|
+
|
20
|
+
case input
|
21
|
+
when /^(.*)::$/
|
22
|
+
begin
|
23
|
+
space = eval("Origami::#{$1}", bind)
|
24
|
+
rescue Exception
|
25
|
+
return []
|
26
|
+
end
|
27
|
+
|
28
|
+
return space.constants.reject{|const| space.const_get(const) <= Exception}
|
29
|
+
|
30
|
+
when /^(.*).$/
|
31
|
+
begin
|
32
|
+
space = eval($1, bind)
|
33
|
+
rescue
|
34
|
+
return []
|
35
|
+
end
|
36
|
+
|
37
|
+
return space.public_methods
|
38
|
+
end
|
39
|
+
}
|
40
|
+
|
41
|
+
if Readline.respond_to?("basic_word_break_characters=")
|
42
|
+
Readline.basic_word_break_characters= " \t\n\"\\'`><=;|&{("
|
43
|
+
end
|
44
|
+
|
45
|
+
Readline.completion_append_character = nil
|
46
|
+
Readline.completion_proc = completionProc
|
47
|
+
end
|
48
|
+
|
49
|
+
def set_prompt
|
50
|
+
IRB.conf[:PROMPT][:PDFSH] = {
|
51
|
+
PROMPT_C: "?>> ",
|
52
|
+
RETURN: "%s\n",
|
53
|
+
PROMPT_I: ">>> ",
|
54
|
+
PROMPT_N: ">>> ",
|
55
|
+
PROMPT_S: nil
|
56
|
+
}
|
57
|
+
|
58
|
+
IRB.conf[:PROMPT_MODE] = :PDFSH
|
59
|
+
IRB.conf[:AUTO_INDENT] = true
|
60
|
+
end
|
61
|
+
|
62
|
+
# Print the shell banner.
|
63
|
+
puts DEFAULT_BANNER.green
|
64
|
+
|
65
|
+
# Import the type conversion helper routines.
|
66
|
+
TOPLEVEL_BINDING.eval("using Origami::TypeConversion")
|
67
|
+
|
68
|
+
#set_completion
|
69
|
+
set_prompt
|
data/examples/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Origami samples
|
2
|
+
|
3
|
+
## ``attachments``
|
4
|
+
|
5
|
+
Adding a file attachment to a PDF document.
|
6
|
+
|
7
|
+
## ``javascript``
|
8
|
+
|
9
|
+
Adding JavaScript to a document and emulating it.
|
10
|
+
|
11
|
+
## ``encryption``
|
12
|
+
|
13
|
+
PDF encryption (supports RC4 40-128 bits, and AES128).
|
14
|
+
Create a new encrypted document.
|
15
|
+
|
16
|
+
## ``signature``
|
17
|
+
|
18
|
+
PDF digital signatures. Create a new document and signs it.
|
19
|
+
|
20
|
+
## ``flash``
|
21
|
+
|
22
|
+
Create a document with an embedded SWF file.
|
23
|
+
|
24
|
+
## ``loop``
|
25
|
+
|
26
|
+
Create a looping document using ``GoTo`` and ``Named`` actions.
|
27
|
+
|
28
|
+
## ``events``
|
29
|
+
|
30
|
+
Create a document running JavaScript on various events.
|
31
|
+
|
32
|
+
## ``uri``
|
33
|
+
|
34
|
+
Various methods for connecting to a remote URL.
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'origami'
|
5
|
+
rescue LoadError
|
6
|
+
$: << File.join(__dir__, "../../lib")
|
7
|
+
require 'origami'
|
8
|
+
end
|
9
|
+
include Origami
|
10
|
+
|
11
|
+
OUTPUT_FILE = "#{File.basename(__FILE__, ".rb")}.pdf"
|
12
|
+
|
13
|
+
# Creating a new file
|
14
|
+
pdf = PDF.new
|
15
|
+
|
16
|
+
# Embedding the file into the PDF.
|
17
|
+
pdf.attach_file(DATA,
|
18
|
+
name: "README.txt",
|
19
|
+
filter: :ASCIIHexDecode
|
20
|
+
)
|
21
|
+
|
22
|
+
contents = ContentStream.new
|
23
|
+
contents.write "File attachment sample",
|
24
|
+
x: 150, y: 750, rendering: Text::Rendering::FILL, size: 30
|
25
|
+
|
26
|
+
pdf.append_page Page.new.setContents(contents)
|
27
|
+
|
28
|
+
pdf.onDocumentOpen Action::JavaScript <<JS
|
29
|
+
this.exportDataObject({cName:"README.txt", nLaunch:2});
|
30
|
+
JS
|
31
|
+
|
32
|
+
|
33
|
+
pdf.save(OUTPUT_FILE)
|
34
|
+
|
35
|
+
puts "PDF file saved as #{OUTPUT_FILE}."
|
36
|
+
|
37
|
+
__END__
|
38
|
+
This is the attached file contents.
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'origami'
|
5
|
+
rescue LoadError
|
6
|
+
$: << File.join(__dir__, '../../lib')
|
7
|
+
require 'origami'
|
8
|
+
end
|
9
|
+
include Origami
|
10
|
+
|
11
|
+
require 'stringio'
|
12
|
+
|
13
|
+
OUTPUT_FILE = "#{File.basename(__FILE__, ".rb")}.pdf"
|
14
|
+
EMBEDDED_NAME = "#{('a'..'z').to_a.sample(8).join}.pdf"
|
15
|
+
|
16
|
+
#
|
17
|
+
# Creates the nested document.
|
18
|
+
# A simple document displaying a message box.
|
19
|
+
#
|
20
|
+
output_str = StringIO.new
|
21
|
+
PDF.write(output_str) do |pdf|
|
22
|
+
pdf.onDocumentOpen Action::JavaScript "app.alert('Hello world!');"
|
23
|
+
end
|
24
|
+
|
25
|
+
output_str.rewind
|
26
|
+
|
27
|
+
# The envelope document.
|
28
|
+
pdf = PDF.new.append_page
|
29
|
+
|
30
|
+
# Create an object stream to compress objects.
|
31
|
+
objstm = ObjectStream.new
|
32
|
+
objstm.Filter = :FlateDecode
|
33
|
+
|
34
|
+
pdf.insert(objstm)
|
35
|
+
|
36
|
+
objstm.insert pdf.attach_file(output_str, register: true, name: EMBEDDED_NAME)
|
37
|
+
|
38
|
+
# Compress the page tree.
|
39
|
+
objstm.insert(pdf.Catalog.Pages)
|
40
|
+
objstm.insert(pdf.pages.first)
|
41
|
+
|
42
|
+
# Compress the name tree.
|
43
|
+
objstm.insert(pdf.Catalog.Names)
|
44
|
+
objstm.insert(pdf.Catalog.Names.EmbeddedFiles)
|
45
|
+
|
46
|
+
# Compress the catalog.
|
47
|
+
objstm.insert(pdf.Catalog)
|
48
|
+
|
49
|
+
pdf.pages.first.onOpen Action::GoToE[EMBEDDED_NAME]
|
50
|
+
|
51
|
+
pdf.save(OUTPUT_FILE, noindent: true)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'origami'
|
5
|
+
rescue LoadError
|
6
|
+
$: << File.join(__dir__, "../../lib")
|
7
|
+
require 'origami'
|
8
|
+
end
|
9
|
+
include Origami
|
10
|
+
|
11
|
+
#
|
12
|
+
# Encrypts a document with an empty password.
|
13
|
+
#
|
14
|
+
|
15
|
+
OUTPUT_FILE = "#{File.basename(__FILE__, ".rb")}.pdf"
|
16
|
+
|
17
|
+
# Creates an encrypted document with AES256 and a null password.
|
18
|
+
pdf = PDF.new.encrypt(cipher: 'aes', key_size: 256)
|
19
|
+
|
20
|
+
contents = ContentStream.new
|
21
|
+
contents.write "Encrypted document sample",
|
22
|
+
x: 100, y: 750, rendering: Text::Rendering::STROKE, size: 30
|
23
|
+
|
24
|
+
pdf.append_page Page.new.setContents(contents)
|
25
|
+
|
26
|
+
pdf.save(OUTPUT_FILE)
|
27
|
+
|
28
|
+
puts "PDF file saved as #{OUTPUT_FILE}."
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'origami'
|
5
|
+
rescue LoadError
|
6
|
+
$: << File.join(__dir__, "../../lib")
|
7
|
+
require 'origami'
|
8
|
+
end
|
9
|
+
include Origami
|
10
|
+
|
11
|
+
OUTPUT_FILE = "#{File.basename(__FILE__, ".rb")}.pdf"
|
12
|
+
|
13
|
+
pdf = PDF.new
|
14
|
+
|
15
|
+
page = Page.new
|
16
|
+
|
17
|
+
contents = ContentStream.new
|
18
|
+
contents.write "Pass your mouse over the square",
|
19
|
+
x: 180, y: 750, size: 15
|
20
|
+
|
21
|
+
page.setContents( contents )
|
22
|
+
|
23
|
+
onpageopen = Action::JavaScript "app.alert('Page Opened');"
|
24
|
+
onpageclose = Action::JavaScript "app.alert('Page Closed');"
|
25
|
+
ondocumentopen = Action::JavaScript "app.alert('Document is opened');"
|
26
|
+
ondocumentclose = Action::JavaScript "app.alert('Document is closing');"
|
27
|
+
onmouseover = Action::JavaScript "app.alert('Mouse over');"
|
28
|
+
onmouseleft = Action::JavaScript "app.alert('Mouse left');"
|
29
|
+
onmousedown = Action::JavaScript "app.alert('Mouse down');"
|
30
|
+
onmouseup = Action::JavaScript "app.alert('Mouse up');"
|
31
|
+
onparentopen = Action::JavaScript "app.alert('Parent page has opened');"
|
32
|
+
onparentclose = Action::JavaScript "app.alert('Parent page has closed');"
|
33
|
+
onparentvisible = Action::JavaScript "app.alert('Parent page is visible');"
|
34
|
+
onparentinvisible = Action::JavaScript "app.alert('Parent page is no more visible');"
|
35
|
+
namedscript = Action::JavaScript "app.alert('Names directory script');"
|
36
|
+
|
37
|
+
pdf.onDocumentOpen(ondocumentopen)
|
38
|
+
pdf.onDocumentClose(ondocumentclose)
|
39
|
+
page.onOpen(onpageopen).onClose(onpageclose)
|
40
|
+
|
41
|
+
pdf.register(Names::JAVASCRIPT, "test", namedscript)
|
42
|
+
|
43
|
+
rect_coord = Rectangle[llx: 270, lly: 700, urx: 330, ury: 640]
|
44
|
+
|
45
|
+
# Just draw a yellow rectangle.
|
46
|
+
rect = Annotation::Square.new
|
47
|
+
rect.Rect = rect_coord
|
48
|
+
rect.IC = [ 255, 255, 0 ]
|
49
|
+
|
50
|
+
# Creates a new annotation which will catch mouse actions.
|
51
|
+
annot = Annotation::Screen.new
|
52
|
+
annot.Rect = rect_coord
|
53
|
+
|
54
|
+
# Bind the scripts to numerous triggers.
|
55
|
+
annot.onMouseOver(onmouseover)
|
56
|
+
annot.onMouseOut(onmouseleft)
|
57
|
+
annot.onMouseDown(onmousedown)
|
58
|
+
annot.onMouseUp(onmouseup)
|
59
|
+
annot.onPageOpen(onparentopen)
|
60
|
+
annot.onPageClose(onparentclose)
|
61
|
+
annot.onPageVisible(onparentvisible)
|
62
|
+
annot.onPageInvisible(onparentinvisible)
|
63
|
+
|
64
|
+
page.add_annotation(annot)
|
65
|
+
page.add_annotation(rect)
|
66
|
+
|
67
|
+
pdf.append_page(page)
|
68
|
+
|
69
|
+
# Save the resulting file.
|
70
|
+
pdf.save(OUTPUT_FILE)
|
71
|
+
|
72
|
+
puts "PDF file saved as #{OUTPUT_FILE}."
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'origami'
|
5
|
+
rescue LoadError
|
6
|
+
$: << File.join(__dir__, "../../lib")
|
7
|
+
require 'origami'
|
8
|
+
end
|
9
|
+
include Origami
|
10
|
+
|
11
|
+
#
|
12
|
+
# Embeding a Flash asset inside a PDF document.
|
13
|
+
#
|
14
|
+
|
15
|
+
SWF_PATH = File.join(__dir__, "helloworld.swf")
|
16
|
+
OUTPUT_FILE = "#{File.basename(__FILE__, ".rb")}.pdf"
|
17
|
+
|
18
|
+
# Creating a new file
|
19
|
+
pdf = PDF.new
|
20
|
+
|
21
|
+
# Embedding the SWF file into the PDF.
|
22
|
+
swf = pdf.attach_file(SWF_PATH)
|
23
|
+
|
24
|
+
# Creating a Flash annotation on the page.
|
25
|
+
pdf.append_page do |page|
|
26
|
+
annot = page.add_flash_application(swf,
|
27
|
+
windowed: true,
|
28
|
+
navigation_pane: true,
|
29
|
+
toolbar: true)
|
30
|
+
|
31
|
+
# Setting the player position on the page.
|
32
|
+
annot.Rect = Rectangle.new [204, 573, 403, 718]
|
33
|
+
end
|
34
|
+
|
35
|
+
pdf.save(OUTPUT_FILE)
|
36
|
+
|
37
|
+
puts "PDF file saved as #{OUTPUT_FILE}."
|
Binary file
|