Class: Pdfrb::Model::Type::Page
Overview
Page object (s7.7.3.3). Fields: /Type, /Parent, /LastModified,
/Resources, /MediaBox, /CropBox, /BleedBox, /TrimBox, /ArtBox,
/BoxColorInfo, /Contents, /Rotate, /Group, /Thumb, /B, /Dur,
/Trans, /Annots, /AA, /Metadata, /PieceInfo, /StructParents,
/ID, /PZ, /SeparationInfo, /Tabs, /TemplateInstantiated,
/PresSteps, /UserUnit, /VP, /AF, /OutputIntents, /DPart.
Instance Attribute Summary
Attributes inherited from Object
#document, #gen, #oid, #value
Instance Method Summary
collapse
#[], #[]=, arlington_available?, arlington_default, arlington_key_to_symbol, arlington_loaded_for?, arlington_mark_loaded, arlington_object, arlington_one_type_to_ruby, arlington_required?, arlington_types_to_ruby, arlington_version, define_field, define_field_from_arlington, #delete, #each, each_field, #each_raw, #empty?, field, #initialize, #key?, #keys, lookup_type, own_fields, #pdf_type, register_type, type_map, #validate
Methods inherited from Object
#==, define_type, #deref, #indirect?, #initialize, #must_be_indirect?, #pdf_type, pdf_type
Instance Method Details
#annotations ⇒ Object
107
108
109
|
# File 'lib/pdfrb/model/type/page.rb', line 107
def annotations
self[:Annots]
end
|
92
93
94
|
# File 'lib/pdfrb/model/type/page.rb', line 92
def art_box
value[:ArtBox]
end
|
#art_box=(box) ⇒ Object
76
77
78
|
# File 'lib/pdfrb/model/type/page.rb', line 76
def art_box=(box)
value[:ArtBox] = box
end
|
#associated_files ⇒ Object
143
144
145
|
# File 'lib/pdfrb/model/type/page.rb', line 143
def associated_files
self[:AF]
end
|
#bleed_box ⇒ Object
84
85
86
|
# File 'lib/pdfrb/model/type/page.rb', line 84
def bleed_box
value[:BleedBox]
end
|
#bleed_box=(box) ⇒ Object
68
69
70
|
# File 'lib/pdfrb/model/type/page.rb', line 68
def bleed_box=(box)
value[:BleedBox] = box
end
|
Returns a Content::Canvas bound to this page's /Contents
stream. Auto-creates a Contents stream if the page has
none. Memoised per page instance.
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/pdfrb/model/type/page.rb', line 19
def canvas
@canvas ||= begin
ref = value[:Contents]
stream =
if ref.nil?
new_stream = document.add({}, type: Pdfrb::Model::Cos::Stream)
new_stream.stream = ""
value[:Contents] = Pdfrb::Model::Reference.new(new_stream.oid, 0)
new_stream
else
ref.is_a?(Pdfrb::Model::Reference) ? document.object(ref) : ref
end
Pdfrb::Content::Canvas.new(stream, document: document)
end
end
|
56
57
58
|
# File 'lib/pdfrb/model/type/page.rb', line 56
def crop_box
inheritable(:CropBox) || media_box
end
|
#crop_box=(box) ⇒ Object
80
81
82
|
# File 'lib/pdfrb/model/type/page.rb', line 80
def crop_box=(box)
value[:CropBox] = box
end
|
#decoded_content ⇒ Object
Resolve and concatenate the page's content-stream bytes.
/Contents is either a single Stream or an array of Streams.
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/pdfrb/model/type/page.rb', line 37
def decoded_content
contents = value[:Contents]
return "".b if contents.nil?
streams = contents.is_a?(::Array) ? contents : [contents]
streams.each_with_object(+"".b) do |ref_or_stream, buf|
stream = ref_or_stream.is_a?(Pdfrb::Model::Reference) ?
document&.object(ref_or_stream) : ref_or_stream
next unless stream.is_a?(Pdfrb::Model::Cos::Stream)
buf << stream.decoded_stream
end
end
|
119
120
121
|
# File 'lib/pdfrb/model/type/page.rb', line 119
def duration
self[:Dur]
end
|
#each_annotation ⇒ Object
181
182
183
184
185
186
187
188
189
190
191
192
193
|
# File 'lib/pdfrb/model/type/page.rb', line 181
def each_annotation
return enum_for(:each_annotation) unless block_given?
return unless annotations && document
arr = annotations.is_a?(Pdfrb::Model::Reference) ?
document.object(annotations) : annotations
return unless arr.is_a?(Array) || arr.is_a?(Pdfrb::Model::PdfArray)
arr.each do |entry|
obj = entry.is_a?(Pdfrb::Model::Reference) ? document.object(entry) : entry
yield obj if obj
end
end
|
151
152
153
|
# File 'lib/pdfrb/model/type/page.rb', line 151
def group
self[:Group]
end
|
#has_annotations? ⇒ Boolean
111
112
113
|
# File 'lib/pdfrb/model/type/page.rb', line 111
def has_annotations?
!!annotations
end
|
#has_group? ⇒ Boolean
155
156
157
|
# File 'lib/pdfrb/model/type/page.rb', line 155
def has_group?
!!group
end
|
#landscape? ⇒ Boolean
163
164
165
166
167
168
169
170
|
# File 'lib/pdfrb/model/type/page.rb', line 163
def landscape?
mb = media_box
return false unless mb.is_a?(Array) && mb.size >= 4
width = mb[2].to_f - mb[0].to_f
height = mb[3].to_f - mb[1].to_f
width > height
end
|
Resolve inheritable /MediaBox by walking up the page tree.
52
53
54
|
# File 'lib/pdfrb/model/type/page.rb', line 52
def media_box
inheritable(:MediaBox)
end
|
64
65
66
|
# File 'lib/pdfrb/model/type/page.rb', line 64
def media_box=(box)
value[:MediaBox] = box
end
|
139
140
141
|
# File 'lib/pdfrb/model/type/page.rb', line 139
def metadata
self[:Metadata]
end
|
#output_intents ⇒ Object
147
148
149
|
# File 'lib/pdfrb/model/type/page.rb', line 147
def output_intents
self[:OutputIntents]
end
|
100
101
102
103
104
105
|
# File 'lib/pdfrb/model/type/page.rb', line 100
def parent
ref = value[:Parent]
return nil unless ref && document
document.object(ref)
end
|
#portrait? ⇒ Boolean
172
173
174
175
176
177
178
179
|
# File 'lib/pdfrb/model/type/page.rb', line 172
def portrait?
mb = media_box
return false unless mb.is_a?(Array) && mb.size >= 4
width = mb[2].to_f - mb[0].to_f
height = mb[3].to_f - mb[1].to_f
height > width
end
|
#resources ⇒ Object
60
61
62
|
# File 'lib/pdfrb/model/type/page.rb', line 60
def resources
inheritable(:Resources)
end
|
96
97
98
|
# File 'lib/pdfrb/model/type/page.rb', line 96
def rotate
inheritable(:Rotate) || 0
end
|
#rotated? ⇒ Boolean
159
160
161
|
# File 'lib/pdfrb/model/type/page.rb', line 159
def rotated?
rotate != 0
end
|
#structural_parent ⇒ Object
135
136
137
|
# File 'lib/pdfrb/model/type/page.rb', line 135
def structural_parent
self[:StructParents]
end
|
#tab_order ⇒ Object
131
132
133
|
# File 'lib/pdfrb/model/type/page.rb', line 131
def tab_order
self[:Tabs]&.to_sym
end
|
#thumbnail ⇒ Object
127
128
129
|
# File 'lib/pdfrb/model/type/page.rb', line 127
def thumbnail
self[:Thumb]
end
|
#transition ⇒ Object
123
124
125
|
# File 'lib/pdfrb/model/type/page.rb', line 123
def transition
self[:Trans]
end
|
88
89
90
|
# File 'lib/pdfrb/model/type/page.rb', line 88
def trim_box
value[:TrimBox]
end
|
#trim_box=(box) ⇒ Object
72
73
74
|
# File 'lib/pdfrb/model/type/page.rb', line 72
def trim_box=(box)
value[:TrimBox] = box
end
|
#user_unit ⇒ Object
115
116
117
|
# File 'lib/pdfrb/model/type/page.rb', line 115
def user_unit
self[:UserUnit] || 1.0
end
|