origami-docspring 2.2.0 → 2.3.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 +4 -4
- data/CHANGELOG.md +18 -0
- data/examples/attachments/attachment.rb +7 -8
- data/examples/attachments/nested_document.rb +6 -5
- data/examples/encryption/encryption.rb +5 -4
- data/examples/events/events.rb +7 -6
- data/examples/flash/flash.rb +10 -9
- data/examples/forms/javascript.rb +14 -13
- data/examples/forms/xfa.rb +67 -66
- data/examples/javascript/hello_world.rb +6 -5
- data/examples/javascript/js_emulation.rb +26 -26
- data/examples/loop/goto.rb +12 -11
- data/examples/loop/named.rb +17 -16
- data/examples/signature/signature.rb +11 -11
- data/examples/uri/javascript.rb +25 -24
- data/examples/uri/open-uri.rb +5 -4
- data/examples/uri/submitform.rb +11 -10
- data/lib/origami/3d.rb +330 -334
- data/lib/origami/acroform.rb +267 -268
- data/lib/origami/actions.rb +266 -278
- data/lib/origami/annotations.rb +659 -670
- data/lib/origami/array.rb +192 -196
- data/lib/origami/boolean.rb +66 -70
- data/lib/origami/catalog.rb +360 -363
- data/lib/origami/collections.rb +132 -133
- data/lib/origami/compound.rb +125 -129
- data/lib/origami/destinations.rb +226 -237
- data/lib/origami/dictionary.rb +155 -154
- data/lib/origami/encryption.rb +967 -923
- data/lib/origami/extensions/fdf.rb +270 -275
- data/lib/origami/extensions/ppklite.rb +323 -328
- data/lib/origami/filespec.rb +170 -173
- data/lib/origami/filters/ascii.rb +162 -167
- data/lib/origami/filters/ccitt/tables.rb +248 -252
- data/lib/origami/filters/ccitt.rb +309 -312
- data/lib/origami/filters/crypt.rb +31 -34
- data/lib/origami/filters/dct.rb +47 -50
- data/lib/origami/filters/flate.rb +57 -60
- data/lib/origami/filters/jbig2.rb +50 -53
- data/lib/origami/filters/jpx.rb +40 -43
- data/lib/origami/filters/lzw.rb +151 -155
- data/lib/origami/filters/predictors.rb +250 -255
- data/lib/origami/filters/runlength.rb +111 -115
- data/lib/origami/filters.rb +319 -325
- data/lib/origami/font.rb +173 -177
- data/lib/origami/functions.rb +62 -66
- data/lib/origami/graphics/colors.rb +203 -208
- data/lib/origami/graphics/instruction.rb +79 -81
- data/lib/origami/graphics/path.rb +141 -144
- data/lib/origami/graphics/patterns.rb +156 -160
- data/lib/origami/graphics/render.rb +51 -47
- data/lib/origami/graphics/state.rb +144 -142
- data/lib/origami/graphics/text.rb +185 -188
- data/lib/origami/graphics/xobject.rb +818 -804
- data/lib/origami/graphics.rb +25 -26
- data/lib/origami/header.rb +63 -65
- data/lib/origami/javascript.rb +718 -651
- data/lib/origami/linearization.rb +284 -285
- data/lib/origami/metadata.rb +156 -135
- data/lib/origami/name.rb +98 -100
- data/lib/origami/null.rb +49 -51
- data/lib/origami/numeric.rb +133 -135
- data/lib/origami/obfuscation.rb +180 -182
- data/lib/origami/object.rb +634 -631
- data/lib/origami/optionalcontent.rb +147 -149
- data/lib/origami/outline.rb +46 -48
- data/lib/origami/outputintents.rb +76 -77
- data/lib/origami/page.rb +637 -596
- data/lib/origami/parser.rb +214 -221
- data/lib/origami/parsers/fdf.rb +44 -45
- data/lib/origami/parsers/pdf/lazy.rb +147 -154
- data/lib/origami/parsers/pdf/linear.rb +104 -109
- data/lib/origami/parsers/pdf.rb +109 -107
- data/lib/origami/parsers/ppklite.rb +44 -46
- data/lib/origami/pdf.rb +886 -896
- data/lib/origami/reference.rb +116 -120
- data/lib/origami/signature.rb +617 -625
- data/lib/origami/stream.rb +560 -558
- data/lib/origami/string.rb +366 -368
- data/lib/origami/template/patterns.rb +50 -52
- data/lib/origami/template/widgets.rb +111 -114
- data/lib/origami/trailer.rb +153 -157
- data/lib/origami/tree.rb +55 -57
- data/lib/origami/version.rb +19 -19
- data/lib/origami/webcapture.rb +87 -90
- data/lib/origami/xfa/config.rb +409 -414
- data/lib/origami/xfa/connectionset.rb +113 -117
- data/lib/origami/xfa/datasets.rb +38 -42
- data/lib/origami/xfa/localeset.rb +33 -37
- data/lib/origami/xfa/package.rb +49 -52
- data/lib/origami/xfa/pdf.rb +54 -59
- data/lib/origami/xfa/signature.rb +33 -37
- data/lib/origami/xfa/sourceset.rb +34 -38
- data/lib/origami/xfa/stylesheet.rb +35 -39
- data/lib/origami/xfa/template.rb +1630 -1634
- data/lib/origami/xfa/xdc.rb +33 -37
- data/lib/origami/xfa/xfa.rb +132 -123
- data/lib/origami/xfa/xfdf.rb +34 -38
- data/lib/origami/xfa/xmpmeta.rb +34 -38
- data/lib/origami/xfa.rb +50 -53
- data/lib/origami/xreftable.rb +462 -462
- data/lib/origami.rb +37 -38
- data/test/test_actions.rb +22 -20
- data/test/test_annotations.rb +54 -52
- data/test/test_forms.rb +23 -21
- data/test/test_native_types.rb +82 -78
- data/test/test_object_tree.rb +25 -24
- data/test/test_pages.rb +43 -41
- data/test/test_pdf.rb +2 -0
- data/test/test_pdf_attachment.rb +23 -21
- data/test/test_pdf_create.rb +16 -15
- data/test/test_pdf_encrypt.rb +69 -66
- data/test/test_pdf_parse.rb +131 -129
- data/test/test_pdf_parse_lazy.rb +53 -53
- data/test/test_pdf_sign.rb +67 -67
- data/test/test_streams.rb +145 -143
- data/test/test_xrefs.rb +46 -45
- metadata +64 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae3ff49d9ddd3a7ea7b42cfbf3af3c21ee83b98e33616333295498b9ce7e2f32
|
4
|
+
data.tar.gz: '095f51d19f7cf41a277b091d6e9355debd5f8e196559b1becb1341a4e51875d6'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02f1753212e4683f000ab1233a568c34e05a20ef7710169c39b016d2fbbb8d4b9fe6e340dff9c42aa9870fe533cac7e0e135ef2578781955d429554f60c33c56
|
7
|
+
data.tar.gz: 3add5450605ad469e08e8dda66302740c68697fb657652b17bce747e77aa6ee98e5126f5e9847986fd5c899ef03879d8c7e512fe52a6ef5e417cebec21825bb4
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
2.3.0 (2025-03-25)
|
2
|
+
-----
|
3
|
+
* Updated to support Ruby 3.2, 3.3, and 3.4
|
4
|
+
* Migrated from Travis CI to GitHub Actions
|
5
|
+
* Added missing dependencies (rexml, matrix)
|
6
|
+
* Fixed issues with frozen string literals
|
7
|
+
* Added pure Ruby RC4 implementation for compatibility with OpenSSL security levels
|
8
|
+
* Improved IO handling in tests
|
9
|
+
* Fixed various RuboCop warnings and updated code style
|
10
|
+
|
11
|
+
2.2.0 (2025-03-25)
|
12
|
+
-----
|
13
|
+
* Bumped version to 2.2.0
|
14
|
+
* Fixed Ruby 2.7 keyword arguments warnings
|
15
|
+
* Renamed gem to origami-docspring
|
16
|
+
* Fixed bug with hybrid xrefs
|
17
|
+
* Updated pdfmetadata to output JSON
|
18
|
+
|
1
19
|
2.1.0
|
2
20
|
-----
|
3
21
|
* Moved pdfwalker to a separate gem
|
@@ -1,10 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
begin
|
4
|
-
|
5
|
+
require 'origami'
|
5
6
|
rescue LoadError
|
6
|
-
|
7
|
-
|
7
|
+
$: << File.join(__dir__, "../../lib")
|
8
|
+
require 'origami'
|
8
9
|
end
|
9
10
|
include Origami
|
10
11
|
|
@@ -15,13 +16,12 @@ pdf = PDF.new
|
|
15
16
|
|
16
17
|
# Embedding the file into the PDF.
|
17
18
|
pdf.attach_file(DATA,
|
18
|
-
|
19
|
-
|
20
|
-
)
|
19
|
+
name: "README.txt",
|
20
|
+
filter: :ASCIIHexDecode)
|
21
21
|
|
22
22
|
contents = ContentStream.new
|
23
23
|
contents.write "File attachment sample",
|
24
|
-
|
24
|
+
x: 150, y: 750, rendering: Text::Rendering::FILL, size: 30
|
25
25
|
|
26
26
|
pdf.append_page Page.new.setContents(contents)
|
27
27
|
|
@@ -29,7 +29,6 @@ pdf.onDocumentOpen Action::JavaScript <<JS
|
|
29
29
|
this.exportDataObject({cName:"README.txt", nLaunch:2});
|
30
30
|
JS
|
31
31
|
|
32
|
-
|
33
32
|
pdf.save(OUTPUT_FILE)
|
34
33
|
|
35
34
|
puts "PDF file saved as #{OUTPUT_FILE}."
|
@@ -1,17 +1,18 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
begin
|
4
|
-
|
5
|
+
require 'origami'
|
5
6
|
rescue LoadError
|
6
|
-
|
7
|
-
|
7
|
+
$: << File.join(__dir__, '../../lib')
|
8
|
+
require 'origami'
|
8
9
|
end
|
9
10
|
include Origami
|
10
11
|
|
11
12
|
require 'stringio'
|
12
13
|
|
13
14
|
OUTPUT_FILE = "#{File.basename(__FILE__, ".rb")}.pdf"
|
14
|
-
EMBEDDED_NAME = "#{(
|
15
|
+
EMBEDDED_NAME = "#{("a".."z").to_a.sample(8).join}.pdf"
|
15
16
|
|
16
17
|
#
|
17
18
|
# Creates the nested document.
|
@@ -19,7 +20,7 @@ EMBEDDED_NAME = "#{('a'..'z').to_a.sample(8).join}.pdf"
|
|
19
20
|
#
|
20
21
|
output_str = StringIO.new
|
21
22
|
PDF.write(output_str) do |pdf|
|
22
|
-
|
23
|
+
pdf.onDocumentOpen Action::JavaScript "app.alert('Hello world!');"
|
23
24
|
end
|
24
25
|
|
25
26
|
output_str.rewind
|
@@ -1,10 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
begin
|
4
|
-
|
5
|
+
require 'origami'
|
5
6
|
rescue LoadError
|
6
|
-
|
7
|
-
|
7
|
+
$: << File.join(__dir__, "../../lib")
|
8
|
+
require 'origami'
|
8
9
|
end
|
9
10
|
include Origami
|
10
11
|
|
@@ -19,7 +20,7 @@ pdf = PDF.new.encrypt(cipher: 'aes', key_size: 256)
|
|
19
20
|
|
20
21
|
contents = ContentStream.new
|
21
22
|
contents.write "Encrypted document sample",
|
22
|
-
|
23
|
+
x: 100, y: 750, rendering: Text::Rendering::STROKE, size: 30
|
23
24
|
|
24
25
|
pdf.append_page Page.new.setContents(contents)
|
25
26
|
|
data/examples/events/events.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
begin
|
4
|
-
|
5
|
+
require 'origami'
|
5
6
|
rescue LoadError
|
6
|
-
|
7
|
-
|
7
|
+
$: << File.join(__dir__, "../../lib")
|
8
|
+
require 'origami'
|
8
9
|
end
|
9
10
|
include Origami
|
10
11
|
|
@@ -16,9 +17,9 @@ page = Page.new
|
|
16
17
|
|
17
18
|
contents = ContentStream.new
|
18
19
|
contents.write "Pass your mouse over the square",
|
19
|
-
|
20
|
+
x: 180, y: 750, size: 15
|
20
21
|
|
21
|
-
page.setContents(
|
22
|
+
page.setContents(contents)
|
22
23
|
|
23
24
|
onpageopen = Action::JavaScript "app.alert('Page Opened');"
|
24
25
|
onpageclose = Action::JavaScript "app.alert('Page Closed');"
|
@@ -45,7 +46,7 @@ rect_coord = Rectangle[llx: 270, lly: 700, urx: 330, ury: 640]
|
|
45
46
|
# Just draw a yellow rectangle.
|
46
47
|
rect = Annotation::Square.new
|
47
48
|
rect.Rect = rect_coord
|
48
|
-
rect.IC = [
|
49
|
+
rect.IC = [255, 255, 0]
|
49
50
|
|
50
51
|
# Creates a new annotation which will catch mouse actions.
|
51
52
|
annot = Annotation::Screen.new
|
data/examples/flash/flash.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
begin
|
4
|
-
|
5
|
+
require 'origami'
|
5
6
|
rescue LoadError
|
6
|
-
|
7
|
-
|
7
|
+
$: << File.join(__dir__, "../../lib")
|
8
|
+
require 'origami'
|
8
9
|
end
|
9
10
|
include Origami
|
10
11
|
|
@@ -23,13 +24,13 @@ swf = pdf.attach_file(SWF_PATH)
|
|
23
24
|
|
24
25
|
# Creating a Flash annotation on the page.
|
25
26
|
pdf.append_page do |page|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
annot = page.add_flash_application(swf,
|
28
|
+
windowed: true,
|
29
|
+
navigation_pane: true,
|
30
|
+
toolbar: true)
|
30
31
|
|
31
|
-
|
32
|
-
|
32
|
+
# Setting the player position on the page.
|
33
|
+
annot.Rect = Rectangle.new [204, 573, 403, 718]
|
33
34
|
end
|
34
35
|
|
35
36
|
pdf.save(OUTPUT_FILE)
|
@@ -1,10 +1,11 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
begin
|
4
|
-
|
5
|
+
require 'origami'
|
5
6
|
rescue LoadError
|
6
|
-
|
7
|
-
|
7
|
+
$: << File.join(__dir__, "../../lib")
|
8
|
+
require 'origami'
|
8
9
|
end
|
9
10
|
include Origami
|
10
11
|
|
@@ -21,26 +22,26 @@ pdf = PDF.new.append_page(page = Page.new)
|
|
21
22
|
contents = ContentStream.new.setFilter(:FlateDecode)
|
22
23
|
|
23
24
|
contents.write "Write your JavaScript below and run it",
|
24
|
-
|
25
|
-
|
25
|
+
x: 100, y: 750, size: 24, rendering: Text::Rendering::FILL,
|
26
|
+
fill_color: Graphics::Color::RGB.new(0xFF, 0x80, 0x80)
|
26
27
|
|
27
28
|
contents.write "You need at least Acrobat Reader 8 to use this document.",
|
28
|
-
|
29
|
+
x: 50, y: 80, size: 12, rendering: Text::Rendering::FILL
|
29
30
|
|
30
31
|
contents.write "\nGenerated with Origami #{Origami::VERSION}.",
|
31
|
-
|
32
|
+
color: Graphics::Color::RGB.new(0, 0, 255)
|
32
33
|
|
33
34
|
contents.draw_rectangle(45, 35, 320, 60,
|
34
|
-
|
35
|
-
|
35
|
+
line_width: 2.0, dash: Graphics::DashPattern.new([3]),
|
36
|
+
fill: false, stroke: true, stroke_color: Graphics::Color::GrayScale.new(0.7))
|
36
37
|
|
37
38
|
page.Contents = contents
|
38
39
|
|
39
40
|
ml = Template::MultiLineEdit.new('scriptedit', x: 50, y: 280, width: 500, height: 400)
|
40
|
-
ml.V =
|
41
|
-
console.show();
|
42
|
-
console.println('Script entry point');
|
43
|
-
app.alert("Hello");
|
41
|
+
ml.V = <<~JS
|
42
|
+
console.show();
|
43
|
+
console.println('Script entry point');
|
44
|
+
app.alert("Hello");
|
44
45
|
JS
|
45
46
|
|
46
47
|
button = Template::Button.new("Run!", x: 490, y: 240, width: 60, height: 30)
|
data/examples/forms/xfa.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
begin
|
4
|
-
|
5
|
+
require 'origami'
|
5
6
|
rescue LoadError
|
6
|
-
|
7
|
-
|
7
|
+
$: << File.join(__dir__, "../../lib")
|
8
|
+
require 'origami'
|
8
9
|
end
|
9
10
|
include Origami
|
10
11
|
|
@@ -20,62 +21,62 @@ OUTPUT_FILE = "#{File.basename(__FILE__, ".rb")}.pdf"
|
|
20
21
|
# XDP Packet holding the Form.
|
21
22
|
#
|
22
23
|
class SampleXDP < XDP::Package
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
24
|
+
def initialize(script = "")
|
25
|
+
super()
|
26
|
+
|
27
|
+
root.add_element(create_config_packet)
|
28
|
+
root.add_element(create_template_packet(script))
|
29
|
+
root.add_element(create_datasets_packet)
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_config_packet
|
33
|
+
config = XDP::Packet::Config.new
|
34
|
+
|
35
|
+
present = config.add_element(XFA::Element.new("present"))
|
36
|
+
pdf = present.add_element(XFA::Element.new("pdf"))
|
37
|
+
interactive = pdf.add_element(XFA::Element.new("interactive"))
|
38
|
+
interactive.text = 1
|
39
|
+
|
40
|
+
config
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_template_packet(script)
|
44
|
+
template = XDP::Packet::Template.new
|
45
|
+
|
46
|
+
form1 = template.add_subform(layout: 'tb', name: 'form1')
|
47
|
+
form1.add_pageSet
|
48
|
+
form1.add_event(activity: 'initialize', name: 'event__ready')
|
49
|
+
.add_script(contentType: 'application/x-formcalc')
|
50
|
+
.text = script
|
51
|
+
|
52
|
+
subform = form1.add_subform
|
53
|
+
|
54
|
+
button = subform.add_field(name: 'Button1')
|
55
|
+
button.add_ui.add_button(highlight: 'inverted')
|
56
|
+
btncaption = button.add_caption
|
57
|
+
btncaption.add_value.add_text.text = "Send!"
|
58
|
+
btncaption.add_para(vAlign: 'middle', hAlign: 'center')
|
59
|
+
button.add_bind(match: 'none')
|
60
|
+
button.add_event(activity: 'click', name: 'event__click')
|
61
|
+
.add_script(contentType: 'application/x-formcalc')
|
62
|
+
.text = script
|
63
|
+
|
64
|
+
txtfield = subform.add_field(name: 'TextField1')
|
65
|
+
txtfield.add_ui.add_textEdit.add_border.add_edge(stroke: 'lowered')
|
66
|
+
|
67
|
+
template
|
68
|
+
end
|
69
|
+
|
70
|
+
def create_datasets_packet
|
71
|
+
datasets = XDP::Packet::Datasets.new
|
72
|
+
data = datasets.add_element(XDP::Packet::Datasets::Data.new)
|
73
|
+
|
74
|
+
data.add_element(XFA::Element.new('form1'))
|
75
|
+
.add_element(XFA::Element.new('TextField1'))
|
76
|
+
.text = '$host.messageBox("Hello from FormCalc!")'
|
77
|
+
|
78
|
+
datasets
|
79
|
+
end
|
79
80
|
end
|
80
81
|
|
81
82
|
pdf = PDF.new.append_page(page = Page.new)
|
@@ -83,18 +84,18 @@ pdf = PDF.new.append_page(page = Page.new)
|
|
83
84
|
contents = ContentStream.new.setFilter(:FlateDecode)
|
84
85
|
|
85
86
|
contents.write "Write your FormCalc below and run it",
|
86
|
-
|
87
|
-
|
87
|
+
x: 100, y: 750, size: 24, rendering: Text::Rendering::FILL,
|
88
|
+
fill_color: Graphics::Color::RGB.new(0xFF, 0x80, 0x80)
|
88
89
|
|
89
90
|
contents.write "You need at least Acrobat Reader 8 to use this document.",
|
90
|
-
|
91
|
+
x: 50, y: 80, size: 12, rendering: Text::Rendering::FILL
|
91
92
|
|
92
93
|
contents.write "\nGenerated with Origami #{Origami::VERSION}.",
|
93
|
-
|
94
|
+
color: Graphics::Color::RGB.new(0, 0, 255)
|
94
95
|
|
95
96
|
contents.draw_rectangle(45, 35, 320, 60,
|
96
|
-
|
97
|
-
|
97
|
+
line_width: 2.0, dash: Graphics::DashPattern.new([3]),
|
98
|
+
fill: false, stroke: true, stroke_color: Graphics::Color::GrayScale.new(0.7))
|
98
99
|
|
99
100
|
page.Contents = contents
|
100
101
|
|
@@ -1,10 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
begin
|
4
|
-
|
5
|
+
require 'origami'
|
5
6
|
rescue LoadError
|
6
|
-
|
7
|
-
|
7
|
+
$: << File.join(__dir__, "/../../lib")
|
8
|
+
require 'origami'
|
8
9
|
end
|
9
10
|
include Origami
|
10
11
|
|
@@ -16,7 +17,7 @@ OUTPUT_FILE = "#{File.basename(__FILE__, ".rb")}.pdf"
|
|
16
17
|
|
17
18
|
# Creating a new file
|
18
19
|
PDF.new
|
19
|
-
|
20
|
-
|
20
|
+
.onDocumentOpen(Action::JavaScript('app.alert("Hello world");'))
|
21
|
+
.save(OUTPUT_FILE)
|
21
22
|
|
22
23
|
puts "PDF file saved as #{OUTPUT_FILE}."
|
@@ -1,10 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
begin
|
4
|
-
|
5
|
+
require 'origami'
|
5
6
|
rescue LoadError
|
6
|
-
|
7
|
-
|
7
|
+
$: << File.join(__dir__, "/../../lib")
|
8
|
+
require 'origami'
|
8
9
|
end
|
9
10
|
include Origami
|
10
11
|
|
@@ -14,40 +15,39 @@ include Origami
|
|
14
15
|
|
15
16
|
if defined?(PDF::JavaScript::Engine)
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
# Creating a new file
|
19
|
+
pdf = PDF.new
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
)
|
21
|
+
# Embedding the file into the PDF.
|
22
|
+
pdf.attach_file(DATA,
|
23
|
+
name: "README.txt",
|
24
|
+
filter: :ASCIIHexDecode)
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
# Example of JS payload
|
27
|
+
pdf.onDocumentOpen Action::JavaScript <<-JS
|
28
28
|
if ( app.viewerVersion == 8 )
|
29
29
|
eval("this.exportDataObject({cName:'README.txt', nLaunch:2});");
|
30
30
|
this.closeDoc();
|
31
|
-
|
31
|
+
JS
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
# Tweaking the engine options
|
34
|
+
pdf.js_engine.options[:log_method_calls] = true
|
35
|
+
pdf.js_engine.options[:viewerVersion] = 10
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
42
|
|
43
|
-
|
44
|
-
|
43
|
+
# Example of inline JS evaluation
|
44
|
+
pdf.eval_js 'console.println(util.stringFromStream(this.getDataObjectContents("README.txt")))'
|
45
45
|
|
46
|
-
|
47
|
-
|
46
|
+
# Executes the string as a JS script
|
47
|
+
pdf.Catalog.OpenAction[:JS].eval_js
|
48
48
|
|
49
49
|
else
|
50
|
-
|
50
|
+
abort "JavaScript support not found. You need to install therubyracer gem."
|
51
51
|
end
|
52
52
|
|
53
53
|
__END__
|
data/examples/loop/goto.rb
CHANGED
@@ -1,30 +1,31 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
begin
|
4
|
-
|
5
|
+
require 'origami'
|
5
6
|
rescue LoadError
|
6
|
-
|
7
|
-
|
7
|
+
$: << File.join(__dir__, "../../lib")
|
8
|
+
require 'origami'
|
8
9
|
end
|
9
10
|
include Origami
|
10
11
|
|
11
|
-
OUTPUT_FILE = "#{File.basename(__FILE__,
|
12
|
+
OUTPUT_FILE = "#{File.basename(__FILE__, ".rb")}.pdf"
|
12
13
|
|
13
14
|
pdf = PDF.new
|
14
15
|
|
15
16
|
50.times do |n|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
pdf.append_page do |page|
|
18
|
+
contents = ContentStream.new
|
19
|
+
contents.write "page #{n + 1}",
|
20
|
+
x: 250, y: 450, rendering: Text::Rendering::FILL, size: 30
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
page.Contents = contents
|
23
|
+
end
|
23
24
|
end
|
24
25
|
|
25
26
|
pages = pdf.pages
|
26
27
|
pages.each_with_index do |page, index|
|
27
|
-
|
28
|
+
page.onOpen Action::GoTo Destination::GlobalFit[pages[(index + 1) % pages.size]]
|
28
29
|
end
|
29
30
|
|
30
31
|
pdf.save(OUTPUT_FILE)
|
data/examples/loop/named.rb
CHANGED
@@ -1,31 +1,32 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
begin
|
4
|
-
|
5
|
+
require 'origami'
|
5
6
|
rescue LoadError
|
6
|
-
|
7
|
-
|
7
|
+
$: << File.join(__dir__, "../../lib")
|
8
|
+
require 'origami'
|
8
9
|
end
|
9
10
|
include Origami
|
10
11
|
|
11
|
-
OUTPUT_FILE = "#{File.basename(__FILE__,
|
12
|
+
OUTPUT_FILE = "#{File.basename(__FILE__, ".rb")}.pdf"
|
12
13
|
|
13
14
|
pdf = PDF.new
|
14
15
|
|
15
16
|
50.times do |n|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
17
|
+
pdf.append_page do |page|
|
18
|
+
contents = ContentStream.new
|
19
|
+
contents.write "page #{n + 1}",
|
20
|
+
x: 250, y: 450, rendering: Text::Rendering::FILL, size: 30
|
21
|
+
|
22
|
+
page.Contents = contents
|
23
|
+
|
24
|
+
if n != 49
|
25
|
+
page.onOpen Action::Named::NEXT_PAGE
|
26
|
+
else
|
27
|
+
page.onOpen Action::Named::FIRST_PAGE
|
28
28
|
end
|
29
|
+
end
|
29
30
|
end
|
30
31
|
|
31
32
|
pdf.save(OUTPUT_FILE)
|
@@ -1,12 +1,13 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'openssl'
|
4
5
|
|
5
6
|
begin
|
6
|
-
|
7
|
+
require 'origami'
|
7
8
|
rescue LoadError
|
8
|
-
|
9
|
-
|
9
|
+
$: << File.join(__dir__, "../../lib")
|
10
|
+
require 'origami'
|
10
11
|
end
|
11
12
|
include Origami
|
12
13
|
|
@@ -34,12 +35,12 @@ cert.add_extension extension_factory.create_extension('keyUsage', 'digitalSignat
|
|
34
35
|
cert.add_extension extension_factory.create_extension('subjectKeyIdentifier', 'hash')
|
35
36
|
|
36
37
|
cert.issuer = name
|
37
|
-
cert.sign key, OpenSSL::Digest
|
38
|
+
cert.sign key, OpenSSL::Digest.new('SHA256')
|
38
39
|
|
39
40
|
# Create the PDF contents
|
40
41
|
contents = ContentStream.new.setFilter(:FlateDecode)
|
41
42
|
contents.write OUTPUT_FILE,
|
42
|
-
|
43
|
+
x: 350, y: 750, rendering: Text::Rendering::STROKE, size: 30
|
43
44
|
|
44
45
|
pdf = PDF.new
|
45
46
|
page = Page.new.setContents(contents)
|
@@ -52,12 +53,11 @@ page.add_annotation(sig_annot)
|
|
52
53
|
|
53
54
|
# Sign the PDF with the specified keys
|
54
55
|
pdf.sign(cert, key,
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
)
|
56
|
+
method: 'adbe.pkcs7.detached',
|
57
|
+
annotation: sig_annot,
|
58
|
+
location: "France",
|
59
|
+
contact: "gdelugre@localhost",
|
60
|
+
reason: "Signature sample")
|
61
61
|
|
62
62
|
# Save the resulting file
|
63
63
|
pdf.save(OUTPUT_FILE)
|