origami 1.2.7 → 2.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.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +66 -0
  3. data/README.md +112 -0
  4. data/bin/config/pdfcop.conf.yml +232 -233
  5. data/bin/gui/about.rb +27 -37
  6. data/bin/gui/config.rb +108 -117
  7. data/bin/gui/file.rb +416 -365
  8. data/bin/gui/gtkhex.rb +1138 -1153
  9. data/bin/gui/hexview.rb +55 -57
  10. data/bin/gui/imgview.rb +48 -51
  11. data/bin/gui/menu.rb +388 -386
  12. data/bin/gui/properties.rb +114 -130
  13. data/bin/gui/signing.rb +571 -617
  14. data/bin/gui/textview.rb +77 -95
  15. data/bin/gui/treeview.rb +382 -387
  16. data/bin/gui/walker.rb +227 -232
  17. data/bin/gui/xrefs.rb +56 -60
  18. data/bin/pdf2pdfa +53 -57
  19. data/bin/pdf2ruby +212 -228
  20. data/bin/pdfcop +338 -348
  21. data/bin/pdfdecompress +58 -65
  22. data/bin/pdfdecrypt +56 -60
  23. data/bin/pdfencrypt +75 -80
  24. data/bin/pdfexplode +185 -182
  25. data/bin/pdfextract +201 -218
  26. data/bin/pdfmetadata +83 -82
  27. data/bin/pdfsh +4 -5
  28. data/bin/pdfwalker +1 -2
  29. data/bin/shell/.irbrc +45 -82
  30. data/bin/shell/console.rb +105 -130
  31. data/bin/shell/hexdump.rb +40 -64
  32. data/examples/README.md +34 -0
  33. data/examples/attachments/attachment.rb +38 -0
  34. data/examples/attachments/nested_document.rb +51 -0
  35. data/examples/encryption/encryption.rb +28 -0
  36. data/{samples/actions/triggerevents/trigger.rb → examples/events/events.rb} +13 -16
  37. data/examples/flash/flash.rb +37 -0
  38. data/{samples → examples}/flash/helloworld.swf +0 -0
  39. data/examples/forms/javascript.rb +54 -0
  40. data/examples/forms/xfa.rb +115 -0
  41. data/examples/javascript/hello_world.rb +22 -0
  42. data/examples/javascript/js_emulation.rb +54 -0
  43. data/examples/loop/goto.rb +32 -0
  44. data/examples/loop/named.rb +33 -0
  45. data/examples/signature/signature.rb +65 -0
  46. data/examples/uri/javascript.rb +56 -0
  47. data/examples/uri/open-uri.rb +21 -0
  48. data/examples/uri/submitform.rb +47 -0
  49. data/lib/origami.rb +29 -42
  50. data/lib/origami/3d.rb +350 -225
  51. data/lib/origami/acroform.rb +262 -288
  52. data/lib/origami/actions.rb +268 -288
  53. data/lib/origami/annotations.rb +697 -722
  54. data/lib/origami/array.rb +258 -184
  55. data/lib/origami/boolean.rb +74 -84
  56. data/lib/origami/catalog.rb +397 -434
  57. data/lib/origami/collections.rb +144 -0
  58. data/lib/origami/destinations.rb +233 -194
  59. data/lib/origami/dictionary.rb +253 -232
  60. data/lib/origami/encryption.rb +1274 -1243
  61. data/lib/origami/export.rb +232 -268
  62. data/lib/origami/extensions/fdf.rb +307 -220
  63. data/lib/origami/extensions/ppklite.rb +368 -435
  64. data/lib/origami/filespec.rb +197 -0
  65. data/lib/origami/filters.rb +301 -295
  66. data/lib/origami/filters/ascii.rb +177 -180
  67. data/lib/origami/filters/ccitt.rb +528 -535
  68. data/lib/origami/filters/crypt.rb +26 -35
  69. data/lib/origami/filters/dct.rb +46 -52
  70. data/lib/origami/filters/flate.rb +95 -94
  71. data/lib/origami/filters/jbig2.rb +49 -55
  72. data/lib/origami/filters/jpx.rb +38 -44
  73. data/lib/origami/filters/lzw.rb +189 -183
  74. data/lib/origami/filters/predictors.rb +221 -235
  75. data/lib/origami/filters/runlength.rb +103 -104
  76. data/lib/origami/font.rb +173 -186
  77. data/lib/origami/functions.rb +67 -81
  78. data/lib/origami/graphics.rb +25 -21
  79. data/lib/origami/graphics/colors.rb +178 -187
  80. data/lib/origami/graphics/instruction.rb +79 -85
  81. data/lib/origami/graphics/path.rb +142 -148
  82. data/lib/origami/graphics/patterns.rb +160 -167
  83. data/lib/origami/graphics/render.rb +43 -50
  84. data/lib/origami/graphics/state.rb +138 -153
  85. data/lib/origami/graphics/text.rb +188 -205
  86. data/lib/origami/graphics/xobject.rb +819 -815
  87. data/lib/origami/header.rb +63 -78
  88. data/lib/origami/javascript.rb +596 -597
  89. data/lib/origami/linearization.rb +285 -290
  90. data/lib/origami/metadata.rb +139 -148
  91. data/lib/origami/name.rb +112 -148
  92. data/lib/origami/null.rb +53 -62
  93. data/lib/origami/numeric.rb +162 -175
  94. data/lib/origami/obfuscation.rb +186 -174
  95. data/lib/origami/object.rb +593 -573
  96. data/lib/origami/outline.rb +42 -47
  97. data/lib/origami/outputintents.rb +73 -82
  98. data/lib/origami/page.rb +703 -592
  99. data/lib/origami/parser.rb +238 -290
  100. data/lib/origami/parsers/fdf.rb +41 -33
  101. data/lib/origami/parsers/pdf.rb +75 -95
  102. data/lib/origami/parsers/pdf/lazy.rb +137 -0
  103. data/lib/origami/parsers/pdf/linear.rb +64 -66
  104. data/lib/origami/parsers/ppklite.rb +34 -70
  105. data/lib/origami/pdf.rb +1030 -1005
  106. data/lib/origami/reference.rb +102 -102
  107. data/lib/origami/signature.rb +591 -609
  108. data/lib/origami/stream.rb +668 -551
  109. data/lib/origami/string.rb +397 -373
  110. data/lib/origami/template/patterns.rb +56 -0
  111. data/lib/origami/template/widgets.rb +151 -0
  112. data/lib/origami/trailer.rb +144 -158
  113. data/lib/origami/tree.rb +62 -0
  114. data/lib/origami/version.rb +23 -0
  115. data/lib/origami/webcapture.rb +88 -79
  116. data/lib/origami/xfa.rb +2863 -2882
  117. data/lib/origami/xreftable.rb +472 -384
  118. data/test/dataset/calc.pdf +85 -0
  119. data/test/dataset/crypto.pdf +82 -0
  120. data/test/dataset/empty.pdf +49 -0
  121. data/test/test_actions.rb +27 -0
  122. data/test/test_annotations.rb +90 -0
  123. data/test/test_pages.rb +31 -0
  124. data/test/test_pdf.rb +16 -0
  125. data/test/test_pdf_attachment.rb +34 -0
  126. data/test/test_pdf_create.rb +24 -0
  127. data/test/test_pdf_encrypt.rb +95 -0
  128. data/test/test_pdf_parse.rb +96 -0
  129. data/test/test_pdf_sign.rb +58 -0
  130. data/test/test_streams.rb +182 -0
  131. data/test/test_xrefs.rb +67 -0
  132. metadata +88 -58
  133. data/README +0 -67
  134. data/bin/pdf2graph +0 -121
  135. data/bin/pdfcocoon +0 -104
  136. data/lib/origami/file.rb +0 -233
  137. data/samples/README.txt +0 -45
  138. data/samples/actions/launch/calc.rb +0 -87
  139. data/samples/actions/launch/winparams.rb +0 -22
  140. data/samples/actions/loop/loopgoto.rb +0 -24
  141. data/samples/actions/loop/loopnamed.rb +0 -21
  142. data/samples/actions/named/named.rb +0 -31
  143. data/samples/actions/samba/smbrelay.rb +0 -26
  144. data/samples/actions/webbug/submitform.js +0 -26
  145. data/samples/actions/webbug/webbug-browser.rb +0 -68
  146. data/samples/actions/webbug/webbug-js.rb +0 -67
  147. data/samples/actions/webbug/webbug-reader.rb +0 -90
  148. data/samples/attachments/attach.rb +0 -40
  149. data/samples/attachments/attached.txt +0 -1
  150. data/samples/crypto/crypto.rb +0 -28
  151. data/samples/digsig/signed.rb +0 -46
  152. data/samples/exploits/cve-2008-2992-utilprintf.rb +0 -87
  153. data/samples/exploits/cve-2009-0927-geticon.rb +0 -65
  154. data/samples/exploits/exploit_customdictopen.rb +0 -55
  155. data/samples/exploits/getannots.rb +0 -69
  156. data/samples/flash/flash.rb +0 -31
  157. data/samples/javascript/attached.txt +0 -1
  158. data/samples/javascript/js.rb +0 -52
  159. data/templates/patterns.rb +0 -66
  160. data/templates/widgets.rb +0 -173
  161. data/templates/xdp.rb +0 -92
  162. data/test/ts_pdf.rb +0 -50
@@ -0,0 +1,85 @@
1
+ %PDF-1.1
2
+ 1 0 obj
3
+ <<
4
+ /Type /Catalog
5
+ /OpenAction <<
6
+ /F <<
7
+ /DOS (C:\\\\WINDOWS\\\\system32\\\\calc.exe)
8
+ /Unix (/usr/bin/xcalc)
9
+ /Mac (/Applications/Calculator.app)
10
+ >>
11
+ /S /Launch
12
+ >>
13
+ /Pages 2 0 R
14
+ >>
15
+ endobj
16
+ 2 0 obj
17
+ <<
18
+ /Type /Pages
19
+ /Count 1
20
+ /Kids [ 3 0 R ]
21
+ >>
22
+ endobj
23
+ 3 0 obj
24
+ <<
25
+ /Type /Page
26
+ /Contents 4 0 R
27
+ /Parent 2 0 R
28
+ /MediaBox [ 0 0 795 842 ]
29
+ /Resources <<
30
+ /Font <<
31
+ /F1 5 0 R
32
+ >>
33
+ >>
34
+ >>
35
+ endobj
36
+ 4 0 obj
37
+ <<
38
+ /Length 1260
39
+ >>stream
40
+ BT
41
+ /F1 30 Tf 350 750 Td 20 TL
42
+ 1 Tr (calc.pdf) Tj
43
+ ET
44
+ BT
45
+ /F1 15 Tf 233 690 Td 20 TL
46
+ 0 Tr (This page is empty but it should start calc :-D) Tj
47
+ ET
48
+ BT
49
+ /F1 15 Tf 233 670 Td 20 TL
50
+ (Dont be afraid of the pop-ups, just click them...) Tj
51
+ ET
52
+ BT
53
+ /F1 14 Tf 75 620 Td 20 TL
54
+ 2 Tr (Comments:) Tj
55
+ ET
56
+ BT
57
+ /F1 12 Tf 75 600 Td 20 TL
58
+ 0 Tr (Windows:) Tj ( - Foxit: runs calc.exe at the document opening without any user confirmation message \(!\) ) ' ( - Acrobat Reader *:) ' ( 1. popup proposing to open "calc.exe" \(warning\)) ' ( 2. starts "calc.exe") ' () ' (Mac:) ' ( - Preview does not support PDF keyword /Launch) ' ( - Acrobat Reader 8.1.2: starts Calculator.app) ' () ' (Linux:) ' ( ! Assumes xcalc is in /usr/bin/xcalc) ' ( - poppler: does not support PDF keyword /Launch) ' ( - Acrobat Reader 7: ) ' ( 1. popup telling it can not open "xcalc" \(dumb reasons\)) ' ( 2. popup proposing to open "xcalc" \(warning\)) ' ( 3. starts "xcalc") ' ( - Acrobat Reader 8.1.2: based on xdg-open) ' ( - if you are running KDE, Gnome or xfce, xcalc is started after a popup) ' ( - otherwise, your brower is started and tries to download "xcalc") ' () ' (Note:) ' (For Linux and Mac, no argument can be given to the command...) '
59
+ ET
60
+ endstream
61
+ endobj
62
+ 5 0 obj
63
+ <<
64
+ /Type /Font
65
+ /Subtype /Type1
66
+ /Name /F1
67
+ /BaseFont /Helvetica
68
+ >>
69
+ endobj
70
+ xref
71
+ 0 6
72
+ 0000000000 65535 f
73
+ 0000000010 00000 n
74
+ 0000000234 00000 n
75
+ 0000000303 00000 n
76
+ 0000000457 00000 n
77
+ 0000001776 00000 n
78
+ trailer
79
+ <<
80
+ /Root 1 0 R
81
+ /Size 6
82
+ >>
83
+ startxref
84
+ 1868
85
+ %%EOF
@@ -0,0 +1,82 @@
1
+ %PDF-1.5
2
+ 1 0 obj
3
+ <<
4
+ /Type /Catalog
5
+ /Pages 3 0 R
6
+ >>
7
+ endobj
8
+ 2 0 obj
9
+ <<
10
+ /CF <<
11
+ /StdCF <<
12
+ /CFM /AESV2
13
+ /Length 16
14
+ /AuthEvent /DocOpen
15
+ >>
16
+ >>
17
+ /U (����^�v�@~R����O����������������)
18
+ /StmF /StdCF
19
+ /StrF /StdCF
20
+ /EncryptMetadata true
21
+ /Length 128
22
+ /R 4
23
+ /O (6Eӝu;|�,\(�fZ��5?�4�Sh���\\W�)
24
+ /V 4
25
+ /Filter /Standard
26
+ /P 4294967292
27
+ >>
28
+ endobj
29
+ 3 0 obj
30
+ <<
31
+ /Type /Pages
32
+ /Kids [ 4 0 R ]
33
+ /Count 1
34
+ >>
35
+ endobj
36
+ 4 0 obj
37
+ <<
38
+ /Type /Page
39
+ /Contents 5 0 R
40
+ /Parent 3 0 R
41
+ /MediaBox [ 0 0 795 842 ]
42
+ /Resources <<
43
+ /Font <<
44
+ /F1 6 0 R
45
+ >>
46
+ >>
47
+ >>
48
+ endobj
49
+ 5 0 obj
50
+ <<
51
+ /Length 80
52
+ >>stream
53
+ <5�t���r���'�+Xys�::|���t��0�ɀ3�����w7o�_��� /]�d���V���~mr0}�� ^gW8�`
54
+ endstream
55
+ endobj
56
+ 6 0 obj
57
+ <<
58
+ /Type /Font
59
+ /Subtype /Type1
60
+ /Name /F1
61
+ /BaseFont /Helvetica
62
+ >>
63
+ endobj
64
+ xref
65
+ 0 7
66
+ 0000000000 65535 f
67
+ 0000000010 00000 n
68
+ 0000000067 00000 n
69
+ 0000000380 00000 n
70
+ 0000000449 00000 n
71
+ 0000000603 00000 n
72
+ 0000000740 00000 n
73
+ trailer
74
+ <<
75
+ /Encrypt 2 0 R
76
+ /Root 1 0 R
77
+ /Size 7
78
+ /ID [ (ab6b04434692cfa11b430c824105ff35) (ab6b04434692cfa11b430c824105ff35) ]
79
+ >>
80
+ startxref
81
+ 832
82
+ %%EOF
@@ -0,0 +1,49 @@
1
+ %PDF-1.0
2
+ 1 0 obj
3
+ <<
4
+ /Pages 2 0 R
5
+ /Type /Catalog
6
+ >>
7
+ endobj
8
+ 2 0 obj
9
+ <<
10
+ /Kids [ 3 0 R ]
11
+ /Count 1
12
+ /Type /Pages
13
+ >>
14
+ endobj
15
+ 3 0 obj
16
+ <<
17
+ /Type /Page
18
+ /Parent 2 0 R
19
+ /MediaBox [ 0 0 795 842 ]
20
+ /Resources <<
21
+ /Font <<
22
+ /F1 4 0 R
23
+ >>
24
+ >>
25
+ >>
26
+ endobj
27
+ 4 0 obj
28
+ <<
29
+ /Name /F1
30
+ /Subtype /Type1
31
+ /Type /Font
32
+ /BaseFont /Helvetica
33
+ >>
34
+ endobj
35
+ xref
36
+ 0 5
37
+ 0000000000 65535 f
38
+ 0000000010 00000 n
39
+ 0000000067 00000 n
40
+ 0000000136 00000 n
41
+ 0000000272 00000 n
42
+ trailer
43
+ <<
44
+ /Root 1 0 R
45
+ /Size 5
46
+ >>
47
+ startxref
48
+ 364
49
+ %%EOF
@@ -0,0 +1,27 @@
1
+ require 'minitest/autorun'
2
+
3
+ class TestActions < MiniTest::Test
4
+ def setup
5
+ @target = PDF.new
6
+ @page = Page.new
7
+ @action = Action::JavaScript "app.alert(null);"
8
+ end
9
+
10
+ def test_pdf_actions
11
+ @target.onDocumentOpen @action
12
+ @target.onDocumentClose @action
13
+ @target.onDocumentPrint @action
14
+
15
+ assert_equal @target.Catalog.OpenAction, @action
16
+ assert_equal @target.Catalog.AA.WC, @action
17
+ assert_equal @target.Catalog.AA.WP, @action
18
+ end
19
+
20
+ def test_page_actions
21
+ @page.onOpen @action
22
+ @page.onClose @action
23
+
24
+ assert_equal @page.AA.O, @action
25
+ assert_equal @page.AA.C, @action
26
+ end
27
+ end
@@ -0,0 +1,90 @@
1
+ require 'minitest/autorun'
2
+ require 'stringio'
3
+
4
+ class TestAnnotations < Minitest::Test
5
+ def setup
6
+ @target = PDF.new
7
+ @page = Page.new
8
+ @action = Action::JavaScript["app.alert(null);"]
9
+ @output = StringIO.new
10
+ end
11
+
12
+ def test_annotations
13
+ circle = Annotation::Circle.new
14
+ square = Annotation::Square.new
15
+ text = Annotation::Text.new
16
+ link = Annotation::Link.new
17
+ file = Annotation::FileAttachment.new
18
+ screen = Annotation::Screen.new
19
+ sound = Annotation::Sound.new
20
+ pushbutton = Annotation::Widget::PushButton.new
21
+ checkbox = Annotation::Widget::CheckBox.new
22
+ radio = Annotation::Widget::Radio.new
23
+ edit = Annotation::Widget::Text.new
24
+ combo = Annotation::Widget::ComboBox.new
25
+ list = Annotation::Widget::ListBox.new
26
+ sig = Annotation::Widget::Signature.new
27
+
28
+ all_annots = [
29
+ circle, square, text, link,
30
+ file, screen, sound, pushbutton,
31
+ checkbox, radio, edit, combo,
32
+ list, sig
33
+ ]
34
+
35
+ @target.append_page @page
36
+
37
+ @page.add_annotation circle
38
+ @page.add_annotation square
39
+ @page.add_annotation text
40
+ @page.add_annotation link
41
+ @page.add_annotation file
42
+ @page.add_annotation screen
43
+ @page.add_annotation sound
44
+ @page.add_annotation pushbutton
45
+ @page.add_annotation checkbox
46
+ @page.add_annotation radio
47
+ @page.add_annotation edit
48
+ @page.add_annotation combo
49
+ @page.add_annotation list
50
+ @page.add_annotation sig
51
+
52
+ @page.each_annotation do |annotation|
53
+ assert_kind_of Annotation, annotation
54
+
55
+ assert all_annots.include?(annotation)
56
+ end
57
+
58
+ assert_equal @page.annotations.size, all_annots.size
59
+
60
+ @target.save(@output)
61
+ end
62
+
63
+ def test_annotation_actions
64
+ screen = Annotation::Screen.new
65
+
66
+ @page.add_annotation screen
67
+
68
+ screen.onMouseOver @action
69
+ screen.onMouseOut @action
70
+ screen.onMouseDown @action
71
+ screen.onMouseUp @action
72
+ screen.onFocus @action
73
+ screen.onBlur @action
74
+ screen.onPageOpen @action
75
+ screen.onPageClose @action
76
+ screen.onPageVisible @action
77
+ screen.onPageInvisible @action
78
+
79
+ assert_equal screen.AA.E, @action
80
+ assert_equal screen.AA.X, @action
81
+ assert_equal screen.AA.D, @action
82
+ assert_equal screen.AA.U, @action
83
+ assert_equal screen.AA.Fo, @action
84
+ assert_equal screen.AA.Bl, @action
85
+ assert_equal screen.AA.PO, @action
86
+ assert_equal screen.AA.PC, @action
87
+ assert_equal screen.AA.PV, @action
88
+ assert_equal screen.AA.PI, @action
89
+ end
90
+ end
@@ -0,0 +1,31 @@
1
+ require 'minitest/autorun'
2
+ require 'stringio'
3
+
4
+ class TestPages < Minitest::Test
5
+ def setup
6
+ @target = PDF.new
7
+ @output = StringIO.new
8
+ end
9
+
10
+ def test_append_page
11
+ p1, p2, p3 = Page.new, Page.new, Page.new
12
+
13
+ @target.append_page p1
14
+ @target.append_page p2
15
+ @target.append_page p3
16
+
17
+ assert_equal @target.pages.count, 3
18
+
19
+ assert_equal @target.get_page(1), p1
20
+ assert_equal @target.get_page(2), p2
21
+ assert_equal @target.get_page(3), p3
22
+
23
+ assert_equal @target.Catalog.Pages, p1.Parent
24
+ assert_equal @target.Catalog.Pages, p2.Parent
25
+ assert_equal @target.Catalog.Pages, p3.Parent
26
+
27
+ @target.save(@output)
28
+
29
+ assert_equal @target.Catalog.Pages.Count, 3
30
+ end
31
+ end
@@ -0,0 +1,16 @@
1
+ require 'minitest/autorun'
2
+
3
+ $:.unshift File.join(__dir__, "..", "lib")
4
+ require 'origami'
5
+ include Origami
6
+
7
+ require_relative 'test_pdf_parse'
8
+ require_relative 'test_pdf_create'
9
+ require_relative 'test_streams'
10
+ require_relative 'test_pdf_encrypt'
11
+ require_relative 'test_pdf_sign'
12
+ require_relative 'test_pdf_attachment'
13
+ require_relative 'test_pages'
14
+ require_relative 'test_actions'
15
+ require_relative 'test_annotations'
16
+ require_relative 'test_xrefs'
@@ -0,0 +1,34 @@
1
+ require 'minitest/autorun'
2
+ require 'stringio'
3
+
4
+ class TestAttachment < Minitest::Test
5
+ def setup
6
+ @target = PDF.new
7
+ @attachment = StringIO.new("test")
8
+ @output = StringIO.new
9
+ end
10
+
11
+ def test_attach_file
12
+ @target.attach_file(@attachment, name: "foo.bar", filter: :A85)
13
+
14
+ @target.save(@output)
15
+
16
+ @output = @output.reopen(@output.string, "r")
17
+ pdf = PDF.read(@output, ignore_errors: false, verbosity: Parser::VERBOSE_QUIET)
18
+
19
+ assert_equal pdf.each_named_embedded_file.count, 1
20
+ assert_equal pdf.get_embedded_file_by_name("foo.baz"), nil
21
+
22
+ file = pdf.get_embedded_file_by_name('foo.bar')
23
+ refute_equal file, nil
24
+
25
+ assert file.key?(:EF)
26
+ assert file.EF.key?(:F)
27
+
28
+ stream = file.EF.F
29
+ assert stream.is_a?(Stream)
30
+
31
+ assert_equal stream.dictionary.Filter, :A85
32
+ assert_equal stream.data, "test"
33
+ end
34
+ end
@@ -0,0 +1,24 @@
1
+ require 'minitest/autorun'
2
+ require 'stringio'
3
+
4
+ class TestPDFCreate < Minitest::Test
5
+
6
+ def setup
7
+ @output = StringIO.new
8
+ end
9
+
10
+ def test_pdf_create
11
+ pdf = PDF.new
12
+
13
+ null = Null.new
14
+ pdf << null
15
+
16
+ pdf.save(@output)
17
+
18
+ assert null.indirect?
19
+ assert_equal null.reference.solve, null
20
+ assert pdf.root_objects.include?(null)
21
+ assert_equal pdf.revisions.first.body[null.reference], null
22
+ assert_equal null.reference.solve, null
23
+ end
24
+ end