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
data/lib/origami.rb
CHANGED
@@ -1,46 +1,45 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# This file is part of Origami, PDF manipulation framework for Ruby
|
5
|
+
# Copyright (C) 2016 Guillaume Delugré.
|
6
|
+
#
|
7
|
+
# Origami is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# Origami is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with Origami. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
20
|
|
21
21
|
module Origami
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
OPTIONS =
|
22
|
+
#
|
23
|
+
# Common Exception class for Origami errors.
|
24
|
+
#
|
25
|
+
class Error < StandardError
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# Global options for Origami.
|
30
|
+
#
|
31
|
+
OPTIONS =
|
33
32
|
{
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
enable_type_checking: true, # set to false to disable type consistency checks during compilation.
|
34
|
+
enable_type_guessing: true, # set to false to prevent the parser to guess the type of special dictionary and streams (not recommended).
|
35
|
+
enable_type_propagation: true, # set to false to prevent the parser to propagate type from parents to children.
|
36
|
+
ignore_bad_references: false, # set to interpret invalid references as Null objects, instead of raising an exception.
|
37
|
+
ignore_zlib_errors: false, # set to true to ignore exceptions on invalid Flate streams.
|
38
|
+
ignore_png_errors: false, # set to true to ignore exceptions on invalid PNG predictors.
|
40
39
|
}
|
41
40
|
|
42
|
-
|
43
|
-
|
41
|
+
autoload :FDF, 'origami/extensions/fdf'
|
42
|
+
autoload :PPKLite, 'origami/extensions/ppklite'
|
44
43
|
end
|
45
44
|
|
46
45
|
require 'origami/version'
|
data/test/test_actions.rb
CHANGED
@@ -1,27 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'minitest/autorun'
|
2
4
|
|
3
|
-
class TestActions <
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
class TestActions < Minitest::Test
|
6
|
+
def setup
|
7
|
+
@target = PDF.new
|
8
|
+
@page = Page.new
|
9
|
+
@action = Action::JavaScript "app.alert(null);"
|
10
|
+
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def test_pdf_actions
|
13
|
+
@target.onDocumentOpen @action
|
14
|
+
@target.onDocumentClose @action
|
15
|
+
@target.onDocumentPrint @action
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
assert_equal @target.Catalog.OpenAction, @action
|
18
|
+
assert_equal @target.Catalog.AA.WC, @action
|
19
|
+
assert_equal @target.Catalog.AA.WP, @action
|
20
|
+
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
def test_page_actions
|
23
|
+
@page.onOpen @action
|
24
|
+
@page.onClose @action
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
assert_equal @page.AA.O, @action
|
27
|
+
assert_equal @page.AA.C, @action
|
28
|
+
end
|
27
29
|
end
|
data/test/test_annotations.rb
CHANGED
@@ -1,68 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'minitest/autorun'
|
2
4
|
require 'stringio'
|
3
5
|
|
4
6
|
class TestAnnotations < Minitest::Test
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
def setup
|
8
|
+
@target = PDF.new
|
9
|
+
@page = Page.new
|
10
|
+
@action = Action::JavaScript["app.alert(null);"]
|
11
|
+
@output = StringIO.new
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
13
|
+
@types = [
|
14
|
+
Annotation::Circle, Annotation::Square,
|
15
|
+
Annotation::Text, Annotation::Link,
|
16
|
+
Annotation::FileAttachment, Annotation::Screen,
|
17
|
+
Annotation::Sound, Annotation::Widget::CheckBox,
|
18
|
+
Annotation::Widget::Radio, Annotation::Widget::Text,
|
19
|
+
Annotation::Widget::ComboBox, Annotation::Widget::ListBox,
|
20
|
+
Annotation::Widget::Signature
|
21
|
+
]
|
22
|
+
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
+
def test_annotations
|
25
|
+
@target.append_page @page
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
annotations = @types.map(&:new)
|
28
|
+
annotations.each do |annotation|
|
29
|
+
@page.add_annotation(annotation)
|
30
|
+
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
+
@page.each_annotation do |annotation|
|
33
|
+
assert_kind_of Annotation, annotation
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
+
assert annotations.include?(annotation)
|
36
|
+
end
|
35
37
|
|
36
|
-
|
38
|
+
assert_equal @page.annotations.size, annotations.size
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
+
@target.save(@output)
|
41
|
+
end
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
+
def test_annotation_actions
|
44
|
+
screen = Annotation::Screen.new
|
43
45
|
|
44
|
-
|
46
|
+
@page.add_annotation screen
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
48
|
+
screen.onMouseOver @action
|
49
|
+
screen.onMouseOut @action
|
50
|
+
screen.onMouseDown @action
|
51
|
+
screen.onMouseUp @action
|
52
|
+
screen.onFocus @action
|
53
|
+
screen.onBlur @action
|
54
|
+
screen.onPageOpen @action
|
55
|
+
screen.onPageClose @action
|
56
|
+
screen.onPageVisible @action
|
57
|
+
screen.onPageInvisible @action
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
59
|
+
assert_equal screen.AA.E, @action
|
60
|
+
assert_equal screen.AA.X, @action
|
61
|
+
assert_equal screen.AA.D, @action
|
62
|
+
assert_equal screen.AA.U, @action
|
63
|
+
assert_equal screen.AA.Fo, @action
|
64
|
+
assert_equal screen.AA.Bl, @action
|
65
|
+
assert_equal screen.AA.PO, @action
|
66
|
+
assert_equal screen.AA.PC, @action
|
67
|
+
assert_equal screen.AA.PV, @action
|
68
|
+
assert_equal screen.AA.PI, @action
|
69
|
+
end
|
68
70
|
end
|
data/test/test_forms.rb
CHANGED
@@ -1,30 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'minitest/autorun'
|
2
4
|
|
3
5
|
class TestForms < Minitest::Test
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
def setup
|
7
|
+
@target = PDF.new
|
8
|
+
@target.append_page
|
9
|
+
end
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
def test_create_acroform
|
12
|
+
fields = [
|
13
|
+
Annotation::Widget::Text.new.set_name('text'),
|
14
|
+
Annotation::Widget::PushButton.new.set_name('button')
|
15
|
+
]
|
14
16
|
|
15
|
-
|
17
|
+
@target.create_form(*fields)
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
|
19
|
+
assert @target.form?
|
20
|
+
assert_kind_of InteractiveForm, @target.Catalog.AcroForm
|
21
|
+
assert_equal @target.fields.length, fields.length
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
assert_nil @target.get_field('not_existent_field')
|
27
|
-
assert_kind_of Field, @target.get_field('button')
|
28
|
-
assert_kind_of Field, @target.get_field('text')
|
23
|
+
@target.each_field do |field|
|
24
|
+
assert_kind_of Field, field
|
25
|
+
assert %w[text button].include?(field.name)
|
29
26
|
end
|
27
|
+
|
28
|
+
assert_nil @target.get_field('not_existent_field')
|
29
|
+
assert_kind_of Field, @target.get_field('button')
|
30
|
+
assert_kind_of Field, @target.get_field('text')
|
31
|
+
end
|
30
32
|
end
|
data/test/test_native_types.rb
CHANGED
@@ -1,83 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'minitest/autorun'
|
2
4
|
require 'strscan'
|
5
|
+
require 'origami'
|
3
6
|
|
4
7
|
class TestPDFCreate < Minitest::Test
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
8
|
+
include Origami
|
9
|
+
using Origami::TypeConversion
|
10
|
+
|
11
|
+
def test_type_string
|
12
|
+
assert_kind_of Origami::String, "".to_o
|
13
|
+
assert_kind_of ::String, "".to_o.value
|
14
|
+
|
15
|
+
assert_equal "<616263>", HexaString.new("abc").to_s
|
16
|
+
assert_equal "(test)", LiteralString.new("test").to_s
|
17
|
+
assert_equal '(\(\(\(\)\)\)\))', LiteralString.new("((())))").to_s
|
18
|
+
assert_equal "abc", "abc".to_o
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_string_encoding
|
22
|
+
str = LiteralString.new("test")
|
23
|
+
|
24
|
+
assert_equal Origami::String::Encoding::PDFDocEncoding, str.encoding
|
25
|
+
assert_equal "UTF-8", str.to_utf8.encoding.to_s
|
26
|
+
|
27
|
+
assert_equal "\xFE\xFF\x00t\x00e\x00s\x00t".b, str.to_utf16be
|
28
|
+
assert_equal Origami::String::Encoding::UTF16BE, str.to_utf16be.to_o.encoding
|
29
|
+
assert_equal str, str.to_utf16be.to_o.to_pdfdoc
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_type_null
|
33
|
+
assert_instance_of Null, nil.to_o
|
34
|
+
assert_nil Null.new.value
|
35
|
+
assert_equal Null.new.to_s, "null"
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_type_name
|
39
|
+
assert_instance_of Name, :test.to_o
|
40
|
+
assert_instance_of Symbol, :test.to_o.value
|
41
|
+
|
42
|
+
assert_equal "/test", Name.new(:test).to_s
|
43
|
+
assert_equal "/#20#23#09#0d#0a#00#5b#5d#3c#3e#28#29#25#2f", Name.new(" #\t\r\n\0[]<>()%/").to_s
|
44
|
+
assert_equal " #\t\r\n\0[]<>()%/", Name.new(" #\t\r\n\0[]<>()%/").value.to_s
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_type_boolean
|
48
|
+
assert_instance_of Boolean, true.to_o
|
49
|
+
assert_instance_of Boolean, false.to_o
|
50
|
+
assert Boolean.new(true).value
|
51
|
+
refute Boolean.new(false).value
|
52
|
+
assert_equal "true", true.to_o.to_s
|
53
|
+
assert_equal "false", false.to_o.to_s
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_type_numeric
|
57
|
+
assert_instance_of Origami::Real, Math::PI.to_o
|
58
|
+
assert_instance_of Origami::Integer, 1.to_o
|
59
|
+
|
60
|
+
assert_equal "1.8", Origami::Real.new(1.8).to_s
|
61
|
+
assert_equal "100", Origami::Integer.new(100).to_s
|
62
|
+
assert_equal 1.8, 1.8.to_o.value
|
63
|
+
assert_equal 100, 100.to_o.value
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_type_array
|
67
|
+
array = [1, "a", [], {}, :test, nil, true, 3.14]
|
68
|
+
|
69
|
+
assert_instance_of Origami::Array, [].to_o
|
70
|
+
assert_instance_of ::Array, [].to_o.value
|
71
|
+
|
72
|
+
assert_equal array, array.to_o.value
|
73
|
+
assert_equal "[1 (a) [] <<>> /test null true 3.14]", array.to_o.to_s
|
74
|
+
assert array.to_o.all? { |o| o.is_a? Origami::Object }
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_type_dictionary
|
78
|
+
assert_instance_of Origami::Dictionary, {}.to_o
|
79
|
+
assert_instance_of Hash, {}.to_o.value
|
80
|
+
|
81
|
+
dict = {a: 1, b: false, c: nil, d: "abc", e: :abc, f: []}
|
82
|
+
|
83
|
+
assert_equal "<</a 1/b false/c null/d (abc)/e /abc/f []>>", dict.to_o.to_s(indent: 0)
|
84
|
+
assert_equal dict, dict.to_o.value
|
85
|
+
assert dict.to_o.all? { |k, v| k.is_a?(Name) and v.is_a?(Origami::Object) }
|
86
|
+
end
|
83
87
|
end
|
data/test/test_object_tree.rb
CHANGED
@@ -1,33 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'minitest/autorun'
|
2
4
|
require 'stringio'
|
3
5
|
|
4
6
|
class TestPDFObjectTree < Minitest::Test
|
7
|
+
def setup
|
8
|
+
@pdf = PDF.new.append_page
|
9
|
+
@contents = ContentStream.new("abc")
|
10
|
+
@pdf.pages.first.Contents = @contents
|
11
|
+
@pdf.Catalog.Loop = @pdf.Catalog
|
12
|
+
@pdf.save StringIO.new
|
13
|
+
end
|
5
14
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@pdf.pages.first.Contents = @contents
|
10
|
-
@pdf.Catalog.Loop = @pdf.Catalog
|
11
|
-
@pdf.save StringIO.new
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_pdf_object_tree
|
15
|
-
assert_instance_of Catalog, @pdf.Catalog
|
16
|
-
assert_nil @pdf.Catalog.parent
|
15
|
+
def test_pdf_object_tree
|
16
|
+
assert_instance_of Catalog, @pdf.Catalog
|
17
|
+
assert_nil @pdf.Catalog.parent
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
@pdf.each_object(recursive: true) do |obj|
|
20
|
+
assert_kind_of Origami::Object, obj
|
21
|
+
assert_equal obj.document, @pdf
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
enum = @pdf.each_object(recursive: true)
|
29
|
-
assert_kind_of Enumerator, enum
|
30
|
-
assert enum.include?(@pdf.Catalog.Pages)
|
31
|
-
assert enum.include?(@contents.dictionary)
|
23
|
+
unless obj.indirect?
|
24
|
+
assert_kind_of Origami::Object, obj.parent
|
25
|
+
assert_equal obj.parent.document, @pdf
|
26
|
+
end
|
32
27
|
end
|
28
|
+
|
29
|
+
enum = @pdf.each_object(recursive: true)
|
30
|
+
assert_kind_of Enumerator, enum
|
31
|
+
assert enum.include?(@pdf.Catalog.Pages)
|
32
|
+
assert enum.include?(@contents.dictionary)
|
33
|
+
end
|
33
34
|
end
|
data/test/test_pages.rb
CHANGED
@@ -1,60 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'minitest/autorun'
|
2
4
|
require 'stringio'
|
3
5
|
|
4
6
|
class TestPages < Minitest::Test
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
def setup
|
8
|
+
@target = PDF.new
|
9
|
+
@output = StringIO.new
|
10
|
+
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
+
def test_append_page
|
13
|
+
p1, p2, p3 = Page.new, Page.new, Page.new
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
15
|
+
@target.append_page p1
|
16
|
+
@target.append_page p2
|
17
|
+
@target.append_page p3
|
16
18
|
|
17
|
-
|
19
|
+
assert_equal @target.pages.count, 3
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
assert_equal @target.get_page(1), p1
|
22
|
+
assert_equal @target.get_page(2), p2
|
23
|
+
assert_equal @target.get_page(3), p3
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
+
assert_raises(IndexError) { @target.get_page(0) }
|
26
|
+
assert_raises(IndexError) { @target.get_page(4) }
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
assert_equal @target.Catalog.Pages, p1.Parent
|
29
|
+
assert_equal @target.Catalog.Pages, p2.Parent
|
30
|
+
assert_equal @target.Catalog.Pages, p3.Parent
|
29
31
|
|
30
|
-
|
32
|
+
@target.save(@output)
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
assert_equal @target.Catalog.Pages.Count, 3
|
35
|
+
assert_equal @target.pages, [p1, p2, p3]
|
36
|
+
assert_equal @target.each_page.to_a, [p1, p2, p3]
|
37
|
+
end
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
+
def test_insert_page
|
40
|
+
pages = Array.new(10) { Page.new }
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
|
42
|
+
pages.each_with_index do |page, index|
|
43
|
+
@target.insert_page(index + 1, page)
|
44
|
+
end
|
43
45
|
|
44
|
-
|
46
|
+
assert_equal @target.pages, pages
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
new_page = Page.new
|
49
|
+
@target.insert_page(1, new_page)
|
50
|
+
assert_equal @target.get_page(1), new_page
|
49
51
|
|
50
|
-
|
51
|
-
|
52
|
-
|
52
|
+
assert_raises(IndexError) { @target.insert_page(0, Page.new) }
|
53
|
+
assert_raises(IndexError) { @target.insert_page(1000, Page.new) }
|
54
|
+
end
|
53
55
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
def test_example_write_page
|
57
|
+
@target.append_page
|
58
|
+
@target.pages.first.write 'Hello, world!', size: 30
|
59
|
+
@target.save(@output)
|
60
|
+
assert_equal @target.Catalog.Pages.Count, 1
|
61
|
+
end
|
60
62
|
end
|