Class: Pdfrb::Model::Type::Page
- Inherits:
-
Cos::Dictionary
- Object
- Object
- Cos::Dictionary
- Pdfrb::Model::Type::Page
- Defined in:
- lib/pdfrb/model/type/page.rb
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
Instance Method Summary collapse
-
#canvas ⇒ Object
Returns a
Content::Canvasbound to this page's /Contents stream. - #crop_box ⇒ Object
-
#decoded_content ⇒ Object
Resolve and concatenate the page's content-stream bytes.
-
#media_box ⇒ Object
Resolve inheritable /MediaBox by walking up the page tree.
- #resources ⇒ Object
- #rotate ⇒ Object
Methods inherited from Cos::Dictionary
#[], #[]=, 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
Constructor Details
This class inherits a constructor from Pdfrb::Model::Cos::Dictionary
Instance Method Details
#canvas ⇒ Object
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 |
#crop_box ⇒ Object
56 57 58 |
# File 'lib/pdfrb/model/type/page.rb', line 56 def crop_box inheritable(:CropBox) || media_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 |
#media_box ⇒ Object
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 |
#resources ⇒ Object
60 61 62 |
# File 'lib/pdfrb/model/type/page.rb', line 60 def resources inheritable(:Resources) end |
#rotate ⇒ Object
64 65 66 |
# File 'lib/pdfrb/model/type/page.rb', line 64 def rotate inheritable(:Rotate) || 0 end |