origami 2.0.1 → 2.0.2
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/lib/origami/acroform.rb +31 -5
- data/lib/origami/actions.rb +13 -0
- data/lib/origami/catalog.rb +1 -1
- data/lib/origami/graphics/xobject.rb +1 -1
- data/lib/origami/optionalcontent.rb +183 -0
- data/lib/origami/page.rb +1 -1
- data/lib/origami/pdf.rb +1 -0
- data/lib/origami/template/widgets.rb +2 -2
- data/lib/origami/version.rb +1 -1
- data/lib/origami/xfa.rb +23 -2971
- data/lib/origami/xfa/config.rb +558 -0
- data/lib/origami/xfa/connectionset.rb +187 -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 +2059 -0
- data/lib/origami/xfa/xdc.rb +42 -0
- data/lib/origami/xfa/xfa.rb +78 -0
- data/lib/origami/xfa/xfdf.rb +43 -0
- data/lib/origami/xfa/xmpmeta.rb +43 -0
- data/test/test_forms.rb +30 -0
- data/test/test_pages.rb +7 -0
- data/test/test_pdf.rb +2 -0
- data/test/test_pdf_parse.rb +2 -2
- data/test/test_pdf_parse_lazy.rb +69 -0
- metadata +19 -2
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
|
|
3
|
+
This file is part of Origami, PDF manipulation framework for Ruby
|
|
4
|
+
Copyright (C) 2017 Guillaume Delugré.
|
|
5
|
+
|
|
6
|
+
Origami is free software: you can redistribute it and/or modify
|
|
7
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
(at your option) any later version.
|
|
10
|
+
|
|
11
|
+
Origami is distributed in the hope that it will be useful,
|
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
GNU Lesser General Public License for more details.
|
|
15
|
+
|
|
16
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
+
along with Origami. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
|
|
19
|
+
=end
|
|
20
|
+
|
|
21
|
+
module Origami
|
|
22
|
+
|
|
23
|
+
module XDP
|
|
24
|
+
|
|
25
|
+
module Packet
|
|
26
|
+
|
|
27
|
+
#
|
|
28
|
+
# The _xdc_ packet encloses application-specific XFA driver configuration instruction.
|
|
29
|
+
#
|
|
30
|
+
class XDC < XFA::Element
|
|
31
|
+
mime_type ''
|
|
32
|
+
|
|
33
|
+
def initialize
|
|
34
|
+
super("xsl:xdc")
|
|
35
|
+
|
|
36
|
+
add_attribute 'xmlns:xdc', 'http://www.xfa.org/schema/xdc/1.0/'
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
|
|
3
|
+
This file is part of Origami, PDF manipulation framework for Ruby
|
|
4
|
+
Copyright (C) 2017 Guillaume Delugré.
|
|
5
|
+
|
|
6
|
+
Origami is free software: you can redistribute it and/or modify
|
|
7
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
(at your option) any later version.
|
|
10
|
+
|
|
11
|
+
Origami is distributed in the hope that it will be useful,
|
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
GNU Lesser General Public License for more details.
|
|
15
|
+
|
|
16
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
+
along with Origami. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
|
|
19
|
+
=end
|
|
20
|
+
|
|
21
|
+
require 'rexml/element'
|
|
22
|
+
|
|
23
|
+
module Origami
|
|
24
|
+
|
|
25
|
+
module XFA
|
|
26
|
+
class XFAError < Error #:nodoc:
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
module ClassMethods
|
|
30
|
+
|
|
31
|
+
def xfa_attribute(name)
|
|
32
|
+
# Attribute getter.
|
|
33
|
+
attr_getter = "attr_#{name}"
|
|
34
|
+
remove_method(attr_getter) rescue NameError
|
|
35
|
+
define_method(attr_getter) do
|
|
36
|
+
self.attributes[name.to_s]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Attribute setter.
|
|
40
|
+
attr_setter = "attr_#{name}="
|
|
41
|
+
remove_method(attr_setter) rescue NameError
|
|
42
|
+
define_method(attr_setter) do |value|
|
|
43
|
+
self.attributes[names.to_s] = value
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def xfa_node(name, type, _range = (0..Float::INFINITY))
|
|
48
|
+
|
|
49
|
+
adder = "add_#{name}"
|
|
50
|
+
remove_method(adder) rescue NameError
|
|
51
|
+
define_method(adder) do |*attr|
|
|
52
|
+
elt = self.add_element(type.new)
|
|
53
|
+
|
|
54
|
+
unless attr.empty?
|
|
55
|
+
attr.first.each do |k,v|
|
|
56
|
+
elt.attributes[k.to_s] = v
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
elt
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def mime_type(type)
|
|
65
|
+
define_method("mime_type") { return type }
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def self.included(receiver)
|
|
70
|
+
receiver.extend(ClassMethods)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
class Element < REXML::Element
|
|
74
|
+
include XFA
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
|
|
3
|
+
This file is part of Origami, PDF manipulation framework for Ruby
|
|
4
|
+
Copyright (C) 2017 Guillaume Delugré.
|
|
5
|
+
|
|
6
|
+
Origami is free software: you can redistribute it and/or modify
|
|
7
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
(at your option) any later version.
|
|
10
|
+
|
|
11
|
+
Origami is distributed in the hope that it will be useful,
|
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
GNU Lesser General Public License for more details.
|
|
15
|
+
|
|
16
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
+
along with Origami. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
|
|
19
|
+
=end
|
|
20
|
+
|
|
21
|
+
module Origami
|
|
22
|
+
|
|
23
|
+
module XDP
|
|
24
|
+
|
|
25
|
+
module Packet
|
|
26
|
+
|
|
27
|
+
#
|
|
28
|
+
# The _xfdf_ (annotations) packet enclosed collaboration annotations placed upon a PDF document.
|
|
29
|
+
#
|
|
30
|
+
class XFDF < XFA::Element
|
|
31
|
+
mime_type 'application/vnd.adobe.xfdf'
|
|
32
|
+
|
|
33
|
+
def initialize
|
|
34
|
+
super("xfdf")
|
|
35
|
+
|
|
36
|
+
add_attribute 'xmlns', 'http://ns.adobe.com/xfdf/'
|
|
37
|
+
add_attribute 'xml:space', 'preserve'
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
|
|
3
|
+
This file is part of Origami, PDF manipulation framework for Ruby
|
|
4
|
+
Copyright (C) 2017 Guillaume Delugré.
|
|
5
|
+
|
|
6
|
+
Origami is free software: you can redistribute it and/or modify
|
|
7
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
(at your option) any later version.
|
|
10
|
+
|
|
11
|
+
Origami is distributed in the hope that it will be useful,
|
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
GNU Lesser General Public License for more details.
|
|
15
|
+
|
|
16
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
+
along with Origami. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
|
|
19
|
+
=end
|
|
20
|
+
|
|
21
|
+
module Origami
|
|
22
|
+
|
|
23
|
+
module XDP
|
|
24
|
+
|
|
25
|
+
module Packet
|
|
26
|
+
|
|
27
|
+
#
|
|
28
|
+
# An _XMP_ packet contains XML representation of PDF metadata.
|
|
29
|
+
#
|
|
30
|
+
class XMPMeta < XFA::Element
|
|
31
|
+
mime_type 'application/rdf+xml'
|
|
32
|
+
|
|
33
|
+
def initialize
|
|
34
|
+
super("xmpmeta")
|
|
35
|
+
|
|
36
|
+
add_attribute 'xmlns', 'http://ns.adobe.com/xmpmeta/'
|
|
37
|
+
add_attribute 'xml:space', 'preserve'
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
data/test/test_forms.rb
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'minitest/autorun'
|
|
2
|
+
|
|
3
|
+
class TestForms < Minitest::Test
|
|
4
|
+
def setup
|
|
5
|
+
@target = PDF.new
|
|
6
|
+
@target.append_page
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def test_create_acroform
|
|
10
|
+
fields = [
|
|
11
|
+
Annotation::Widget::Text.new.set_name('text'),
|
|
12
|
+
Annotation::Widget::PushButton.new.set_name('button')
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
@target.create_form(*fields)
|
|
16
|
+
|
|
17
|
+
assert @target.form?
|
|
18
|
+
assert_kind_of InteractiveForm, @target.Catalog.AcroForm
|
|
19
|
+
assert_equal @target.fields.length, fields.length
|
|
20
|
+
|
|
21
|
+
@target.each_field do |field|
|
|
22
|
+
assert_kind_of Field, field
|
|
23
|
+
assert %w{text button}.include?(field.name)
|
|
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')
|
|
29
|
+
end
|
|
30
|
+
end
|
data/test/test_pages.rb
CHANGED
|
@@ -28,4 +28,11 @@ class TestPages < Minitest::Test
|
|
|
28
28
|
|
|
29
29
|
assert_equal @target.Catalog.Pages.Count, 3
|
|
30
30
|
end
|
|
31
|
+
|
|
32
|
+
def test_example_write_page
|
|
33
|
+
@target.append_page
|
|
34
|
+
@target.pages.first.write 'Hello, world!', size: 30
|
|
35
|
+
@target.save(@output)
|
|
36
|
+
assert_equal @target.Catalog.Pages.Count, 1
|
|
37
|
+
end
|
|
31
38
|
end
|
data/test/test_pdf.rb
CHANGED
|
@@ -5,6 +5,7 @@ require 'origami'
|
|
|
5
5
|
include Origami
|
|
6
6
|
|
|
7
7
|
require_relative 'test_pdf_parse'
|
|
8
|
+
require_relative 'test_pdf_parse_lazy'
|
|
8
9
|
require_relative 'test_pdf_create'
|
|
9
10
|
require_relative 'test_streams'
|
|
10
11
|
require_relative 'test_pdf_encrypt'
|
|
@@ -13,4 +14,5 @@ require_relative 'test_pdf_attachment'
|
|
|
13
14
|
require_relative 'test_pages'
|
|
14
15
|
require_relative 'test_actions'
|
|
15
16
|
require_relative 'test_annotations'
|
|
17
|
+
require_relative 'test_forms'
|
|
16
18
|
require_relative 'test_xrefs'
|
data/test/test_pdf_parse.rb
CHANGED
|
@@ -2,7 +2,7 @@ require 'minitest/autorun'
|
|
|
2
2
|
|
|
3
3
|
class TestPDFParser < Minitest::Test
|
|
4
4
|
def setup
|
|
5
|
-
@
|
|
5
|
+
@files =
|
|
6
6
|
%w{
|
|
7
7
|
dataset/empty.pdf
|
|
8
8
|
dataset/calc.pdf
|
|
@@ -22,7 +22,7 @@ class TestPDFParser < Minitest::Test
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def test_parse_pdf
|
|
25
|
-
@
|
|
25
|
+
@files.each do |file|
|
|
26
26
|
pdf = PDF.read(File.join(__dir__, file), ignore_errors: false, verbosity: Parser::VERBOSE_QUIET)
|
|
27
27
|
|
|
28
28
|
assert_instance_of PDF, pdf
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require 'minitest/autorun'
|
|
2
|
+
require 'stringio'
|
|
3
|
+
|
|
4
|
+
class TestPDFLazyParser < Minitest::Test
|
|
5
|
+
|
|
6
|
+
def setup
|
|
7
|
+
@files =
|
|
8
|
+
%w{
|
|
9
|
+
dataset/empty.pdf
|
|
10
|
+
dataset/calc.pdf
|
|
11
|
+
dataset/crypto.pdf
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_parse_pdf_lazy
|
|
17
|
+
@files.each do |file|
|
|
18
|
+
pdf = PDF.read(File.join(__dir__, file),
|
|
19
|
+
ignore_errors: false,
|
|
20
|
+
lazy: true,
|
|
21
|
+
verbosity: Parser::VERBOSE_QUIET)
|
|
22
|
+
|
|
23
|
+
assert_instance_of PDF, pdf
|
|
24
|
+
|
|
25
|
+
pdf.each_object do |object|
|
|
26
|
+
assert_kind_of Origami::Object, object
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
assert_instance_of Catalog, pdf.Catalog
|
|
30
|
+
|
|
31
|
+
pdf.each_page do |page|
|
|
32
|
+
assert_kind_of Page, page
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_save_pdf_lazy
|
|
38
|
+
@files.each do |file|
|
|
39
|
+
pdf = PDF.read(File.join(__dir__, file),
|
|
40
|
+
ignore_errors: false,
|
|
41
|
+
lazy: true,
|
|
42
|
+
verbosity: Parser::VERBOSE_QUIET)
|
|
43
|
+
|
|
44
|
+
pdf.save(StringIO.new)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_random_access
|
|
49
|
+
io = StringIO.new
|
|
50
|
+
stream = Stream.new("abc")
|
|
51
|
+
|
|
52
|
+
PDF.create(io) do |pdf|
|
|
53
|
+
pdf.insert(stream)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
io = io.reopen(io.string, 'r')
|
|
57
|
+
|
|
58
|
+
pdf = PDF.read(io, ignore_errors: false,
|
|
59
|
+
lazy: true,
|
|
60
|
+
verbosity: Parser::VERBOSE_QUIET)
|
|
61
|
+
|
|
62
|
+
non_existent = pdf[42]
|
|
63
|
+
existent = pdf[stream.reference]
|
|
64
|
+
|
|
65
|
+
assert_nil non_existent
|
|
66
|
+
assert_instance_of Stream, existent
|
|
67
|
+
assert_equal stream.data, existent.data
|
|
68
|
+
end
|
|
69
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: origami
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Guillaume Delugré
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-
|
|
11
|
+
date: 2017-04-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: colorize
|
|
@@ -151,6 +151,7 @@ files:
|
|
|
151
151
|
- lib/origami/numeric.rb
|
|
152
152
|
- lib/origami/obfuscation.rb
|
|
153
153
|
- lib/origami/object.rb
|
|
154
|
+
- lib/origami/optionalcontent.rb
|
|
154
155
|
- lib/origami/outline.rb
|
|
155
156
|
- lib/origami/outputintents.rb
|
|
156
157
|
- lib/origami/page.rb
|
|
@@ -172,18 +173,34 @@ files:
|
|
|
172
173
|
- lib/origami/version.rb
|
|
173
174
|
- lib/origami/webcapture.rb
|
|
174
175
|
- lib/origami/xfa.rb
|
|
176
|
+
- lib/origami/xfa/config.rb
|
|
177
|
+
- lib/origami/xfa/connectionset.rb
|
|
178
|
+
- lib/origami/xfa/datasets.rb
|
|
179
|
+
- lib/origami/xfa/localeset.rb
|
|
180
|
+
- lib/origami/xfa/package.rb
|
|
181
|
+
- lib/origami/xfa/pdf.rb
|
|
182
|
+
- lib/origami/xfa/signature.rb
|
|
183
|
+
- lib/origami/xfa/sourceset.rb
|
|
184
|
+
- lib/origami/xfa/stylesheet.rb
|
|
185
|
+
- lib/origami/xfa/template.rb
|
|
186
|
+
- lib/origami/xfa/xdc.rb
|
|
187
|
+
- lib/origami/xfa/xfa.rb
|
|
188
|
+
- lib/origami/xfa/xfdf.rb
|
|
189
|
+
- lib/origami/xfa/xmpmeta.rb
|
|
175
190
|
- lib/origami/xreftable.rb
|
|
176
191
|
- test/dataset/calc.pdf
|
|
177
192
|
- test/dataset/crypto.pdf
|
|
178
193
|
- test/dataset/empty.pdf
|
|
179
194
|
- test/test_actions.rb
|
|
180
195
|
- test/test_annotations.rb
|
|
196
|
+
- test/test_forms.rb
|
|
181
197
|
- test/test_pages.rb
|
|
182
198
|
- test/test_pdf.rb
|
|
183
199
|
- test/test_pdf_attachment.rb
|
|
184
200
|
- test/test_pdf_create.rb
|
|
185
201
|
- test/test_pdf_encrypt.rb
|
|
186
202
|
- test/test_pdf_parse.rb
|
|
203
|
+
- test/test_pdf_parse_lazy.rb
|
|
187
204
|
- test/test_pdf_sign.rb
|
|
188
205
|
- test/test_streams.rb
|
|
189
206
|
- test/test_xrefs.rb
|