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.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -0
  3. data/examples/attachments/attachment.rb +7 -8
  4. data/examples/attachments/nested_document.rb +6 -5
  5. data/examples/encryption/encryption.rb +5 -4
  6. data/examples/events/events.rb +7 -6
  7. data/examples/flash/flash.rb +10 -9
  8. data/examples/forms/javascript.rb +14 -13
  9. data/examples/forms/xfa.rb +67 -66
  10. data/examples/javascript/hello_world.rb +6 -5
  11. data/examples/javascript/js_emulation.rb +26 -26
  12. data/examples/loop/goto.rb +12 -11
  13. data/examples/loop/named.rb +17 -16
  14. data/examples/signature/signature.rb +11 -11
  15. data/examples/uri/javascript.rb +25 -24
  16. data/examples/uri/open-uri.rb +5 -4
  17. data/examples/uri/submitform.rb +11 -10
  18. data/lib/origami/3d.rb +330 -334
  19. data/lib/origami/acroform.rb +267 -268
  20. data/lib/origami/actions.rb +266 -278
  21. data/lib/origami/annotations.rb +659 -670
  22. data/lib/origami/array.rb +192 -196
  23. data/lib/origami/boolean.rb +66 -70
  24. data/lib/origami/catalog.rb +360 -363
  25. data/lib/origami/collections.rb +132 -133
  26. data/lib/origami/compound.rb +125 -129
  27. data/lib/origami/destinations.rb +226 -237
  28. data/lib/origami/dictionary.rb +155 -154
  29. data/lib/origami/encryption.rb +967 -923
  30. data/lib/origami/extensions/fdf.rb +270 -275
  31. data/lib/origami/extensions/ppklite.rb +323 -328
  32. data/lib/origami/filespec.rb +170 -173
  33. data/lib/origami/filters/ascii.rb +162 -167
  34. data/lib/origami/filters/ccitt/tables.rb +248 -252
  35. data/lib/origami/filters/ccitt.rb +309 -312
  36. data/lib/origami/filters/crypt.rb +31 -34
  37. data/lib/origami/filters/dct.rb +47 -50
  38. data/lib/origami/filters/flate.rb +57 -60
  39. data/lib/origami/filters/jbig2.rb +50 -53
  40. data/lib/origami/filters/jpx.rb +40 -43
  41. data/lib/origami/filters/lzw.rb +151 -155
  42. data/lib/origami/filters/predictors.rb +250 -255
  43. data/lib/origami/filters/runlength.rb +111 -115
  44. data/lib/origami/filters.rb +319 -325
  45. data/lib/origami/font.rb +173 -177
  46. data/lib/origami/functions.rb +62 -66
  47. data/lib/origami/graphics/colors.rb +203 -208
  48. data/lib/origami/graphics/instruction.rb +79 -81
  49. data/lib/origami/graphics/path.rb +141 -144
  50. data/lib/origami/graphics/patterns.rb +156 -160
  51. data/lib/origami/graphics/render.rb +51 -47
  52. data/lib/origami/graphics/state.rb +144 -142
  53. data/lib/origami/graphics/text.rb +185 -188
  54. data/lib/origami/graphics/xobject.rb +818 -804
  55. data/lib/origami/graphics.rb +25 -26
  56. data/lib/origami/header.rb +63 -65
  57. data/lib/origami/javascript.rb +718 -651
  58. data/lib/origami/linearization.rb +284 -285
  59. data/lib/origami/metadata.rb +156 -135
  60. data/lib/origami/name.rb +98 -100
  61. data/lib/origami/null.rb +49 -51
  62. data/lib/origami/numeric.rb +133 -135
  63. data/lib/origami/obfuscation.rb +180 -182
  64. data/lib/origami/object.rb +634 -631
  65. data/lib/origami/optionalcontent.rb +147 -149
  66. data/lib/origami/outline.rb +46 -48
  67. data/lib/origami/outputintents.rb +76 -77
  68. data/lib/origami/page.rb +637 -596
  69. data/lib/origami/parser.rb +214 -221
  70. data/lib/origami/parsers/fdf.rb +44 -45
  71. data/lib/origami/parsers/pdf/lazy.rb +147 -154
  72. data/lib/origami/parsers/pdf/linear.rb +104 -109
  73. data/lib/origami/parsers/pdf.rb +109 -107
  74. data/lib/origami/parsers/ppklite.rb +44 -46
  75. data/lib/origami/pdf.rb +886 -896
  76. data/lib/origami/reference.rb +116 -120
  77. data/lib/origami/signature.rb +617 -625
  78. data/lib/origami/stream.rb +560 -558
  79. data/lib/origami/string.rb +366 -368
  80. data/lib/origami/template/patterns.rb +50 -52
  81. data/lib/origami/template/widgets.rb +111 -114
  82. data/lib/origami/trailer.rb +153 -157
  83. data/lib/origami/tree.rb +55 -57
  84. data/lib/origami/version.rb +19 -19
  85. data/lib/origami/webcapture.rb +87 -90
  86. data/lib/origami/xfa/config.rb +409 -414
  87. data/lib/origami/xfa/connectionset.rb +113 -117
  88. data/lib/origami/xfa/datasets.rb +38 -42
  89. data/lib/origami/xfa/localeset.rb +33 -37
  90. data/lib/origami/xfa/package.rb +49 -52
  91. data/lib/origami/xfa/pdf.rb +54 -59
  92. data/lib/origami/xfa/signature.rb +33 -37
  93. data/lib/origami/xfa/sourceset.rb +34 -38
  94. data/lib/origami/xfa/stylesheet.rb +35 -39
  95. data/lib/origami/xfa/template.rb +1630 -1634
  96. data/lib/origami/xfa/xdc.rb +33 -37
  97. data/lib/origami/xfa/xfa.rb +132 -123
  98. data/lib/origami/xfa/xfdf.rb +34 -38
  99. data/lib/origami/xfa/xmpmeta.rb +34 -38
  100. data/lib/origami/xfa.rb +50 -53
  101. data/lib/origami/xreftable.rb +462 -462
  102. data/lib/origami.rb +37 -38
  103. data/test/test_actions.rb +22 -20
  104. data/test/test_annotations.rb +54 -52
  105. data/test/test_forms.rb +23 -21
  106. data/test/test_native_types.rb +82 -78
  107. data/test/test_object_tree.rb +25 -24
  108. data/test/test_pages.rb +43 -41
  109. data/test/test_pdf.rb +2 -0
  110. data/test/test_pdf_attachment.rb +23 -21
  111. data/test/test_pdf_create.rb +16 -15
  112. data/test/test_pdf_encrypt.rb +69 -66
  113. data/test/test_pdf_parse.rb +131 -129
  114. data/test/test_pdf_parse_lazy.rb +53 -53
  115. data/test/test_pdf_sign.rb +67 -67
  116. data/test/test_streams.rb +145 -143
  117. data/test/test_xrefs.rb +46 -45
  118. metadata +64 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19f9e88c0a715dfbcb8343816f50e90ec38dc34736798b915414a9e159cf242d
4
- data.tar.gz: 31116ae16c58437b48a4f2a9a0e072cd5c17c040183691ae77444aa0e8ee7247
3
+ metadata.gz: ae3ff49d9ddd3a7ea7b42cfbf3af3c21ee83b98e33616333295498b9ce7e2f32
4
+ data.tar.gz: '095f51d19f7cf41a277b091d6e9355debd5f8e196559b1becb1341a4e51875d6'
5
5
  SHA512:
6
- metadata.gz: b829b1b0c184b66307f0553e5760d81389305affafe3c0f75d4836e157bf2af1a063311bb8ef6e71c9cc77bcb4948f6210001b567f27cceba88f7cb7db0ee64d
7
- data.tar.gz: 14406599d653682d4b584297296ed625de80ea415e8655d560a499a58c9404a4f2fd0c227ab68843bf592b1b5c4c13a01605045c3566b4f401270bb10063080e
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
- require 'origami'
5
+ require 'origami'
5
6
  rescue LoadError
6
- $: << File.join(__dir__, "../../lib")
7
- require 'origami'
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
- name: "README.txt",
19
- filter: :ASCIIHexDecode
20
- )
19
+ name: "README.txt",
20
+ filter: :ASCIIHexDecode)
21
21
 
22
22
  contents = ContentStream.new
23
23
  contents.write "File attachment sample",
24
- x: 150, y: 750, rendering: Text::Rendering::FILL, size: 30
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
- require 'origami'
5
+ require 'origami'
5
6
  rescue LoadError
6
- $: << File.join(__dir__, '../../lib')
7
- require 'origami'
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 = "#{('a'..'z').to_a.sample(8).join}.pdf"
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
- pdf.onDocumentOpen Action::JavaScript "app.alert('Hello world!');"
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
- require 'origami'
5
+ require 'origami'
5
6
  rescue LoadError
6
- $: << File.join(__dir__, "../../lib")
7
- require 'origami'
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
- x: 100, y: 750, rendering: Text::Rendering::STROKE, size: 30
23
+ x: 100, y: 750, rendering: Text::Rendering::STROKE, size: 30
23
24
 
24
25
  pdf.append_page Page.new.setContents(contents)
25
26
 
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  begin
4
- require 'origami'
5
+ require 'origami'
5
6
  rescue LoadError
6
- $: << File.join(__dir__, "../../lib")
7
- require 'origami'
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
- x: 180, y: 750, size: 15
20
+ x: 180, y: 750, size: 15
20
21
 
21
- page.setContents( contents )
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 = [ 255, 255, 0 ]
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
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  begin
4
- require 'origami'
5
+ require 'origami'
5
6
  rescue LoadError
6
- $: << File.join(__dir__, "../../lib")
7
- require 'origami'
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
- annot = page.add_flash_application(swf,
27
- windowed: true,
28
- navigation_pane: true,
29
- toolbar: true)
27
+ annot = page.add_flash_application(swf,
28
+ windowed: true,
29
+ navigation_pane: true,
30
+ toolbar: true)
30
31
 
31
- # Setting the player position on the page.
32
- annot.Rect = Rectangle.new [204, 573, 403, 718]
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
- require 'origami'
5
+ require 'origami'
5
6
  rescue LoadError
6
- $: << File.join(__dir__, "../../lib")
7
- require 'origami'
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
- x: 100, y: 750, size: 24, rendering: Text::Rendering::FILL,
25
- fill_color: Graphics::Color::RGB.new(0xFF, 0x80, 0x80)
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
- x: 50, y: 80, size: 12, rendering: Text::Rendering::FILL
29
+ x: 50, y: 80, size: 12, rendering: Text::Rendering::FILL
29
30
 
30
31
  contents.write "\nGenerated with Origami #{Origami::VERSION}.",
31
- color: Graphics::Color::RGB.new(0, 0, 255)
32
+ color: Graphics::Color::RGB.new(0, 0, 255)
32
33
 
33
34
  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))
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 = <<JS
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)
@@ -1,10 +1,11 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  begin
4
- require 'origami'
5
+ require 'origami'
5
6
  rescue LoadError
6
- $: << File.join(__dir__, "../../lib")
7
- require 'origami'
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
- 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
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
- x: 100, y: 750, size: 24, rendering: Text::Rendering::FILL,
87
- fill_color: Graphics::Color::RGB.new(0xFF, 0x80, 0x80)
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
- x: 50, y: 80, size: 12, rendering: Text::Rendering::FILL
91
+ x: 50, y: 80, size: 12, rendering: Text::Rendering::FILL
91
92
 
92
93
  contents.write "\nGenerated with Origami #{Origami::VERSION}.",
93
- color: Graphics::Color::RGB.new(0, 0, 255)
94
+ color: Graphics::Color::RGB.new(0, 0, 255)
94
95
 
95
96
  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))
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
- require 'origami'
5
+ require 'origami'
5
6
  rescue LoadError
6
- $: << File.join(__dir__, "/../../lib")
7
- require 'origami'
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
- .onDocumentOpen(Action::JavaScript 'app.alert("Hello world");')
20
- .save(OUTPUT_FILE)
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
- require 'origami'
5
+ require 'origami'
5
6
  rescue LoadError
6
- $: << File.join(__dir__, "/../../lib")
7
- require 'origami'
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
- # Creating a new file
18
- pdf = PDF.new
18
+ # Creating a new file
19
+ pdf = PDF.new
19
20
 
20
- # Embedding the file into the PDF.
21
- pdf.attach_file(DATA,
22
- name: "README.txt",
23
- filter: :ASCIIHexDecode
24
- )
21
+ # Embedding the file into the PDF.
22
+ pdf.attach_file(DATA,
23
+ name: "README.txt",
24
+ filter: :ASCIIHexDecode)
25
25
 
26
- # Example of JS payload
27
- pdf.onDocumentOpen Action::JavaScript <<-JS
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
- JS
31
+ JS
32
32
 
33
- # Tweaking the engine options
34
- pdf.js_engine.options[:log_method_calls] = true
35
- pdf.js_engine.options[:viewerVersion] = 10
33
+ # Tweaking the engine options
34
+ pdf.js_engine.options[:log_method_calls] = true
35
+ pdf.js_engine.options[:viewerVersion] = 10
36
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
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
- # Example of inline JS evaluation
44
- pdf.eval_js 'console.println(util.stringFromStream(this.getDataObjectContents("README.txt")))'
43
+ # Example of inline JS evaluation
44
+ pdf.eval_js 'console.println(util.stringFromStream(this.getDataObjectContents("README.txt")))'
45
45
 
46
- # Executes the string as a JS script
47
- pdf.Catalog.OpenAction[:JS].eval_js
46
+ # Executes the string as a JS script
47
+ pdf.Catalog.OpenAction[:JS].eval_js
48
48
 
49
49
  else
50
- abort "JavaScript support not found. You need to install therubyracer gem."
50
+ abort "JavaScript support not found. You need to install therubyracer gem."
51
51
  end
52
52
 
53
53
  __END__
@@ -1,30 +1,31 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  begin
4
- require 'origami'
5
+ require 'origami'
5
6
  rescue LoadError
6
- $: << File.join(__dir__, "../../lib")
7
- require 'origami'
7
+ $: << File.join(__dir__, "../../lib")
8
+ require 'origami'
8
9
  end
9
10
  include Origami
10
11
 
11
- OUTPUT_FILE = "#{File.basename(__FILE__, '.rb')}.pdf"
12
+ OUTPUT_FILE = "#{File.basename(__FILE__, ".rb")}.pdf"
12
13
 
13
14
  pdf = PDF.new
14
15
 
15
16
  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
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
- page.Contents = contents
22
- end
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
- page.onOpen Action::GoTo Destination::GlobalFit[pages[(index + 1) % pages.size]]
28
+ page.onOpen Action::GoTo Destination::GlobalFit[pages[(index + 1) % pages.size]]
28
29
  end
29
30
 
30
31
  pdf.save(OUTPUT_FILE)
@@ -1,31 +1,32 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  begin
4
- require 'origami'
5
+ require 'origami'
5
6
  rescue LoadError
6
- $: << File.join(__dir__, "../../lib")
7
- require 'origami'
7
+ $: << File.join(__dir__, "../../lib")
8
+ require 'origami'
8
9
  end
9
10
  include Origami
10
11
 
11
- OUTPUT_FILE = "#{File.basename(__FILE__, '.rb')}.pdf"
12
+ OUTPUT_FILE = "#{File.basename(__FILE__, ".rb")}.pdf"
12
13
 
13
14
  pdf = PDF.new
14
15
 
15
16
  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
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
- require 'origami'
7
+ require 'origami'
7
8
  rescue LoadError
8
- $: << File.join(__dir__, "../../lib")
9
- require 'origami'
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::SHA256.new
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
- x: 350, y: 750, rendering: Text::Rendering::STROKE, size: 30
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
- method: 'adbe.pkcs7.detached',
56
- annotation: sig_annot,
57
- location: "France",
58
- contact: "gdelugre@localhost",
59
- reason: "Signature sample"
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)