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
@@ -0,0 +1,54 @@
|
|
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
|
+
#
|
12
|
+
# Interactive JavaScript interpreter using an Acrobat Form.
|
13
|
+
#
|
14
|
+
|
15
|
+
require 'origami/template/widgets'
|
16
|
+
|
17
|
+
OUTPUT_FILE = "#{File.basename(__FILE__, ".rb")}.pdf"
|
18
|
+
|
19
|
+
pdf = PDF.new.append_page(page = Page.new)
|
20
|
+
|
21
|
+
contents = ContentStream.new.setFilter(:FlateDecode)
|
22
|
+
|
23
|
+
contents.write "Write your JavaScript below and run it",
|
24
|
+
x: 100, y: 750, size: 24, rendering: Text::Rendering::FILL,
|
25
|
+
fill_color: Graphics::Color::RGB.new(0xFF, 0x80, 0x80)
|
26
|
+
|
27
|
+
contents.write "You need at least Acrobat Reader 8 to use this document.",
|
28
|
+
x: 50, y: 80, size: 12, rendering: Text::Rendering::FILL
|
29
|
+
|
30
|
+
contents.write "\nGenerated with Origami #{Origami::VERSION}.",
|
31
|
+
color: Graphics::Color::RGB.new(0, 0, 255)
|
32
|
+
|
33
|
+
contents.draw_rectangle(45, 35, 320, 60,
|
34
|
+
line_width: 2.0, dash: Graphics::DashPattern.new([3]),
|
35
|
+
fill: false, stroke: true, stroke_color: Graphics::Color::GrayScale.new(0.7))
|
36
|
+
|
37
|
+
page.Contents = contents
|
38
|
+
|
39
|
+
ml = Template::MultiLineEdit.new('scriptedit', x: 50, y: 280, width: 500, height: 400)
|
40
|
+
ml.V = <<JS
|
41
|
+
console.show();
|
42
|
+
console.println('Script entry point');
|
43
|
+
app.alert("Hello");
|
44
|
+
JS
|
45
|
+
|
46
|
+
button = Template::Button.new("Run!", x: 490, y: 240, width: 60, height: 30)
|
47
|
+
button.onActivate Action::JavaScript["eval(this.getField('scriptedit').value);"]
|
48
|
+
|
49
|
+
page.add_annotation(ml, button)
|
50
|
+
pdf.create_form(button, ml)
|
51
|
+
|
52
|
+
pdf.save(OUTPUT_FILE, noindent: true)
|
53
|
+
|
54
|
+
puts "PDF file saved as #{OUTPUT_FILE}."
|
@@ -0,0 +1,115 @@
|
|
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
|
+
require 'origami/template/widgets'
|
12
|
+
|
13
|
+
OUTPUT_FILE = "#{File.basename(__FILE__, ".rb")}.pdf"
|
14
|
+
|
15
|
+
#
|
16
|
+
# Interactive FormCalc interpreter using a XFA form.
|
17
|
+
#
|
18
|
+
|
19
|
+
#
|
20
|
+
# XDP Packet holding the Form.
|
21
|
+
#
|
22
|
+
class SampleXDP < XDP::Package
|
23
|
+
def initialize(script = "")
|
24
|
+
super()
|
25
|
+
|
26
|
+
self.root.add_element(create_config_packet)
|
27
|
+
self.root.add_element(create_template_packet(script))
|
28
|
+
self.root.add_element(create_datasets_packet)
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_config_packet
|
32
|
+
config = XDP::Packet::Config.new
|
33
|
+
|
34
|
+
present = config.add_element(XFA::Element.new("present"))
|
35
|
+
pdf = present.add_element(XFA::Element.new("pdf"))
|
36
|
+
interactive = pdf.add_element(XFA::Element.new("interactive"))
|
37
|
+
interactive.text = 1
|
38
|
+
|
39
|
+
config
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_template_packet(script)
|
43
|
+
template = XDP::Packet::Template.new
|
44
|
+
|
45
|
+
form1 = template.add_subform(layout: 'tb', name: 'form1')
|
46
|
+
form1.add_pageSet
|
47
|
+
form1.add_event(activity: 'initialize', name: 'event__ready')
|
48
|
+
.add_script(contentType: 'application/x-formcalc')
|
49
|
+
.text = script
|
50
|
+
|
51
|
+
subform = form1.add_subform
|
52
|
+
|
53
|
+
button = subform.add_field(name: 'Button1')
|
54
|
+
button.add_ui.add_button(highlight: 'inverted')
|
55
|
+
btncaption = button.add_caption
|
56
|
+
btncaption.add_value.add_text.text = "Send!"
|
57
|
+
btncaption.add_para(vAlign: 'middle', hAlign: 'center')
|
58
|
+
button.add_bind(match: 'none')
|
59
|
+
button.add_event(activity: 'click', name: 'event__click')
|
60
|
+
.add_script(contentType: 'application/x-formcalc')
|
61
|
+
.text = script
|
62
|
+
|
63
|
+
txtfield = subform.add_field(name: 'TextField1')
|
64
|
+
txtfield.add_ui.add_textEdit.add_border.add_edge(stroke: 'lowered')
|
65
|
+
|
66
|
+
template
|
67
|
+
end
|
68
|
+
|
69
|
+
def create_datasets_packet
|
70
|
+
datasets = XDP::Packet::Datasets.new
|
71
|
+
data = datasets.add_element(XDP::Packet::Datasets::Data.new)
|
72
|
+
|
73
|
+
data.add_element(XFA::Element.new('form1'))
|
74
|
+
.add_element(XFA::Element.new('TextField1'))
|
75
|
+
.text = '$host.messageBox("Hello from FormCalc!")'
|
76
|
+
|
77
|
+
datasets
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
pdf = PDF.new.append_page(page = Page.new)
|
82
|
+
|
83
|
+
contents = ContentStream.new.setFilter(:FlateDecode)
|
84
|
+
|
85
|
+
contents.write "Write your FormCalc below and run it",
|
86
|
+
x: 100, y: 750, size: 24, rendering: Text::Rendering::FILL,
|
87
|
+
fill_color: Graphics::Color::RGB.new(0xFF, 0x80, 0x80)
|
88
|
+
|
89
|
+
contents.write "You need at least Acrobat Reader 8 to use this document.",
|
90
|
+
x: 50, y: 80, size: 12, rendering: Text::Rendering::FILL
|
91
|
+
|
92
|
+
contents.write "\nGenerated with Origami #{Origami::VERSION}.",
|
93
|
+
color: Graphics::Color::RGB.new(0, 0, 255)
|
94
|
+
|
95
|
+
contents.draw_rectangle(45, 35, 320, 60,
|
96
|
+
line_width: 2.0, dash: Graphics::DashPattern.new([3]),
|
97
|
+
fill: false, stroke: true, stroke_color: Graphics::Color::GrayScale.new(0.7))
|
98
|
+
|
99
|
+
page.Contents = contents
|
100
|
+
|
101
|
+
ml = Template::MultiLineEdit.new('TextField1[0]', x: 50, y: 280, width: 500, height: 400)
|
102
|
+
button = Template::Button.new('Send!', id: 'Button1[0]', x: 490, y: 240, width: 60, height: 30)
|
103
|
+
|
104
|
+
page.add_annotation(ml, button)
|
105
|
+
|
106
|
+
form1 = Field::Subform.new(T: "form1[0]")
|
107
|
+
form1.add_fields(subform = Field::Subform.new(T: "#subform[0]"))
|
108
|
+
subform.add_fields(ml, button)
|
109
|
+
|
110
|
+
xdp = SampleXDP.new('Eval(Ref(form1[0].#subform[0].TextField1[0]))').to_s
|
111
|
+
pdf.create_xfa_form(xdp, form1)
|
112
|
+
|
113
|
+
pdf.save(OUTPUT_FILE)
|
114
|
+
|
115
|
+
puts "PDF file saved as #{OUTPUT_FILE}."
|
@@ -0,0 +1,22 @@
|
|
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
|
+
# Displays a message box when the document is opened.
|
13
|
+
#
|
14
|
+
|
15
|
+
OUTPUT_FILE = "#{File.basename(__FILE__, ".rb")}.pdf"
|
16
|
+
|
17
|
+
# Creating a new file
|
18
|
+
PDF.new
|
19
|
+
.onDocumentOpen(Action::JavaScript 'app.alert("Hello world");')
|
20
|
+
.save(OUTPUT_FILE)
|
21
|
+
|
22
|
+
puts "PDF file saved as #{OUTPUT_FILE}."
|
@@ -0,0 +1,54 @@
|
|
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
|
+
# Emulating JavaScript inside a PDF object.
|
13
|
+
#
|
14
|
+
|
15
|
+
if defined?(PDF::JavaScript::Engine)
|
16
|
+
|
17
|
+
# Creating a new file
|
18
|
+
pdf = PDF.new
|
19
|
+
|
20
|
+
# Embedding the file into the PDF.
|
21
|
+
pdf.attach_file(DATA,
|
22
|
+
name: "README.txt",
|
23
|
+
filter: :ASCIIHexDecode
|
24
|
+
)
|
25
|
+
|
26
|
+
# Example of JS payload
|
27
|
+
pdf.onDocumentOpen Action::JavaScript <<-JS
|
28
|
+
if ( app.viewerVersion == 8 )
|
29
|
+
eval("this.exportDataObject({cName:'README.txt', nLaunch:2});");
|
30
|
+
this.closeDoc();
|
31
|
+
JS
|
32
|
+
|
33
|
+
# Tweaking the engine options
|
34
|
+
pdf.js_engine.options[:log_method_calls] = true
|
35
|
+
pdf.js_engine.options[:viewerVersion] = 10
|
36
|
+
|
37
|
+
# Hooking eval()
|
38
|
+
pdf.js_engine.hook 'eval' do |eval, expr|
|
39
|
+
puts "Hook: eval(#{expr.inspect})"
|
40
|
+
eval.call(expr) # calling the real eval method
|
41
|
+
end
|
42
|
+
|
43
|
+
# Example of inline JS evaluation
|
44
|
+
pdf.eval_js 'console.println(util.stringFromStream(this.getDataObjectContents("README.txt")))'
|
45
|
+
|
46
|
+
# Executes the string as a JS script
|
47
|
+
pdf.Catalog.OpenAction[:JS].eval_js
|
48
|
+
|
49
|
+
else
|
50
|
+
abort "JavaScript support not found. You need to install therubyracer gem."
|
51
|
+
end
|
52
|
+
|
53
|
+
__END__
|
54
|
+
** THIS IS THE EMBEDDED FILE **
|
@@ -0,0 +1,32 @@
|
|
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
|
+
pdf = PDF.new
|
14
|
+
|
15
|
+
50.times do |n|
|
16
|
+
pdf.append_page do |page|
|
17
|
+
contents = ContentStream.new
|
18
|
+
contents.write "page #{n+1}",
|
19
|
+
x: 250, y: 450, rendering: Text::Rendering::FILL, size: 30
|
20
|
+
|
21
|
+
page.Contents = contents
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
pages = pdf.pages
|
26
|
+
pages.each_with_index do |page, index|
|
27
|
+
page.onOpen Action::GoTo Destination::GlobalFit[pages[(index + 1) % pages.size]]
|
28
|
+
end
|
29
|
+
|
30
|
+
pdf.save(OUTPUT_FILE)
|
31
|
+
|
32
|
+
puts "PDF file saved as #{OUTPUT_FILE}."
|
@@ -0,0 +1,33 @@
|
|
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
|
+
pdf = PDF.new
|
14
|
+
|
15
|
+
50.times do |n|
|
16
|
+
pdf.append_page do |page|
|
17
|
+
contents = ContentStream.new
|
18
|
+
contents.write "page #{n+1}",
|
19
|
+
x: 250, y: 450, rendering: Text::Rendering::FILL, size: 30
|
20
|
+
|
21
|
+
page.Contents = contents
|
22
|
+
|
23
|
+
if n != 49
|
24
|
+
page.onOpen Action::Named::NEXT_PAGE
|
25
|
+
else
|
26
|
+
page.onOpen Action::Named::FIRST_PAGE
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
pdf.save(OUTPUT_FILE)
|
32
|
+
|
33
|
+
puts "PDF file saved as #{OUTPUT_FILE}."
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'openssl'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'origami'
|
7
|
+
rescue LoadError
|
8
|
+
$: << File.join(__dir__, "../../lib")
|
9
|
+
require 'origami'
|
10
|
+
end
|
11
|
+
include Origami
|
12
|
+
|
13
|
+
OUTPUT_FILE = "#{File.basename(__FILE__, ".rb")}.pdf"
|
14
|
+
|
15
|
+
puts "Generating a RSA key pair."
|
16
|
+
key = OpenSSL::PKey::RSA.new 2048
|
17
|
+
|
18
|
+
puts "Generating a self-signed certificate."
|
19
|
+
name = OpenSSL::X509::Name.parse 'CN=origami/DC=example'
|
20
|
+
|
21
|
+
cert = OpenSSL::X509::Certificate.new
|
22
|
+
cert.version = 2
|
23
|
+
cert.serial = 0
|
24
|
+
cert.not_before = Time.now
|
25
|
+
cert.not_after = Time.now + 3600
|
26
|
+
|
27
|
+
cert.public_key = key.public_key
|
28
|
+
cert.subject = name
|
29
|
+
|
30
|
+
extension_factory = OpenSSL::X509::ExtensionFactory.new nil, cert
|
31
|
+
|
32
|
+
cert.add_extension extension_factory.create_extension('basicConstraints', 'CA:TRUE', true)
|
33
|
+
cert.add_extension extension_factory.create_extension('keyUsage', 'digitalSignature')
|
34
|
+
cert.add_extension extension_factory.create_extension('subjectKeyIdentifier', 'hash')
|
35
|
+
|
36
|
+
cert.issuer = name
|
37
|
+
cert.sign key, OpenSSL::Digest::SHA256.new
|
38
|
+
|
39
|
+
# Create the PDF contents
|
40
|
+
contents = ContentStream.new.setFilter(:FlateDecode)
|
41
|
+
contents.write OUTPUT_FILE,
|
42
|
+
x: 350, y: 750, rendering: Text::Rendering::STROKE, size: 30
|
43
|
+
|
44
|
+
pdf = PDF.new
|
45
|
+
page = Page.new.setContents(contents)
|
46
|
+
pdf.append_page(page)
|
47
|
+
|
48
|
+
sig_annot = Annotation::Widget::Signature.new
|
49
|
+
sig_annot.Rect = Rectangle[llx: 89.0, lly: 386.0, urx: 190.0, ury: 353.0]
|
50
|
+
|
51
|
+
page.add_annotation(sig_annot)
|
52
|
+
|
53
|
+
# Sign the PDF with the specified keys
|
54
|
+
pdf.sign(cert, key,
|
55
|
+
method: 'adbe.pkcs7.detached',
|
56
|
+
annotation: sig_annot,
|
57
|
+
location: "France",
|
58
|
+
contact: "gdelugre@localhost",
|
59
|
+
reason: "Signature sample"
|
60
|
+
)
|
61
|
+
|
62
|
+
# Save the resulting file
|
63
|
+
pdf.save(OUTPUT_FILE)
|
64
|
+
|
65
|
+
puts "PDF file saved as #{OUTPUT_FILE}."
|
@@ -0,0 +1,56 @@
|
|
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
|
+
URL = "http://google.fr"
|
13
|
+
|
14
|
+
contents = ContentStream.new.setFilter(:FlateDecode)
|
15
|
+
contents.write OUTPUT_FILE,
|
16
|
+
:x => 200, :y => 750, :rendering => Text::Rendering::FILL, :size => 30
|
17
|
+
|
18
|
+
contents.write "The script first tries to run your browser using JavaScript.",
|
19
|
+
:x => 100, :y => 670, :size => 15
|
20
|
+
|
21
|
+
# A JS script to execute at the opening of the document
|
22
|
+
jscript = <<JS
|
23
|
+
try {
|
24
|
+
app.launchURL("#{URL}");
|
25
|
+
}
|
26
|
+
catch(e) {}
|
27
|
+
|
28
|
+
try {
|
29
|
+
this.submitForm(
|
30
|
+
{
|
31
|
+
cURL: "#{URL}",
|
32
|
+
bAnnotations: true,
|
33
|
+
bGet: true,
|
34
|
+
cSubmitAs: "XML"
|
35
|
+
});
|
36
|
+
}
|
37
|
+
catch(e) {}
|
38
|
+
JS
|
39
|
+
|
40
|
+
pdf = PDF.new
|
41
|
+
|
42
|
+
pdf.append_page do |page|
|
43
|
+
page.Contents = contents
|
44
|
+
end
|
45
|
+
|
46
|
+
# Create a new action based on the script, compressed with zlib
|
47
|
+
jsaction = Action::JavaScript Stream.new(jscript)#@ Filter: :FlateDecode)
|
48
|
+
|
49
|
+
# Add the script into the document names dictionary.
|
50
|
+
# Any scripts registered here will be executed at the document opening (with no OpenAction implied).
|
51
|
+
pdf.register(Names::JAVASCRIPT, "Update", jsaction)
|
52
|
+
|
53
|
+
# Save the resulting file
|
54
|
+
pdf.save(OUTPUT_FILE)
|
55
|
+
|
56
|
+
puts "PDF file saved as #{OUTPUT_FILE}."
|
@@ -0,0 +1,21 @@
|
|
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
|
+
URL = "http://google.fr"
|
13
|
+
|
14
|
+
pdf = PDF.new
|
15
|
+
|
16
|
+
# Trigger an URI action when the document is opened.
|
17
|
+
pdf.onDocumentOpen Action::URI[URL]
|
18
|
+
|
19
|
+
pdf.save(OUTPUT_FILE)
|
20
|
+
|
21
|
+
puts "PDF file saved as #{OUTPUT_FILE}."
|
@@ -0,0 +1,47 @@
|
|
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
|
+
URL = "http://mydomain/calc.pdf"
|
13
|
+
|
14
|
+
pdf = PDF.new
|
15
|
+
|
16
|
+
contents = ContentStream.new
|
17
|
+
contents.write OUTPUT_FILE,
|
18
|
+
x: 210, y: 750, rendering: Text::Rendering::FILL, size: 30
|
19
|
+
|
20
|
+
contents.write "When opened, this PDF connects to \"home\"",
|
21
|
+
x: 156, y: 690, rendering: Text::Rendering::FILL, size: 15
|
22
|
+
|
23
|
+
contents.write "Click \"Allow\" to connect to #{URL} through your current Reader.",
|
24
|
+
x: 106, y: 670, size: 12
|
25
|
+
|
26
|
+
contents.write "Comments:",
|
27
|
+
x: 75, y: 600, rendering: Text::Rendering::FILL_AND_STROKE, size: 12
|
28
|
+
|
29
|
+
comment = <<-EOS
|
30
|
+
Adobe Reader will render the PDF file returned by the remote server.
|
31
|
+
EOS
|
32
|
+
|
33
|
+
contents.write comment,
|
34
|
+
x: 75, y: 580, rendering: Text::Rendering::FILL, size: 12
|
35
|
+
|
36
|
+
pdf.append_page Page.new.setContents(contents)
|
37
|
+
|
38
|
+
# Submit flags.
|
39
|
+
flags = Action::SubmitForm::Flags::EXPORTFORMAT|Action::SubmitForm::Flags::GETMETHOD
|
40
|
+
|
41
|
+
# Sends the form at the document opening.
|
42
|
+
pdf.onDocumentOpen Action::SubmitForm[URL, [], flags]
|
43
|
+
|
44
|
+
# Save the resulting file.
|
45
|
+
pdf.save(OUTPUT_FILE)
|
46
|
+
|
47
|
+
puts "PDF file saved as #{OUTPUT_FILE}."
|