Class: PDF::Writer::Object::Page
- Inherits:
-
PDF::Writer::Object
- Object
- PDF::Writer::Object
- PDF::Writer::Object::Page
- Defined in:
- lib/pdf/writer/object/page.rb
Overview
A page object, it also creates a contents object to hold its contents
Instance Attribute Summary collapse
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#page_number ⇒ Object
readonly
Returns the value of attribute page_number.
Attributes inherited from PDF::Writer::Object
Instance Method Summary collapse
- #add_annotation(a) ⇒ Object
-
#initialize(parent, relative = nil) ⇒ Page
constructor
Create a page.
- #to_s ⇒ Object
Constructor Details
#initialize(parent, relative = nil) ⇒ Page
Create a page. The optional relative
is a Hash with keys :pos => :before|:after and :rpage, the page to which this new page will be added relative.
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 |
# File 'lib/pdf/writer/object/page.rb', line 16 def initialize(parent, relative = nil) super(parent) @parent.current_page = self @owner = @parent.instance_variable_get('@current_node') @page_number = @parent.pages.size @contents = [] if relative.nil? @parent.pages << self else relative[:page] = self @parent.pages.add(relative) end # make a contents object to go with this page @contents << PDF::Writer::Object::Contents.new(@parent, self) @parent.instance_variable_set('@current_contents', @contents[-1]) match = (@parent.pages.size % 2 == 0 ? :even_pages : :odd_pages) # Cheat here. I don't want to add an unnecessary attribute. @parent.instance_variable_get('@add_loose_objects').each do |obj, target| @contents << obj if target == :all_pages or match == target end @annotations = [] @media_box = nil @crop_box = nil @bleed_box = nil @trim_box = nil @art_box = nil end |
Instance Attribute Details
#contents ⇒ Object
Returns the value of attribute contents.
49 50 51 |
# File 'lib/pdf/writer/object/page.rb', line 49 def contents @contents end |
#page_number ⇒ Object (readonly)
Returns the value of attribute page_number.
50 51 52 |
# File 'lib/pdf/writer/object/page.rb', line 50 def page_number @page_number end |
Instance Method Details
#add_annotation(a) ⇒ Object
52 53 54 |
# File 'lib/pdf/writer/object/page.rb', line 52 def add_annotation(a) @annotations << a end |
#to_s ⇒ Object
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/pdf/writer/object/page.rb', line 56 def to_s res = "\n#{@oid} 0 obj\n<< /Type /Page\n/Parent #{@owner.oid} 0 R" unless @annotations.empty? res << "\n/Annots [" @annotations.each { |e| res << " #{e.oid} 0 R"} res << "]" end if @contents.size == 1 res << "\n/Contents #{@contents[0].oid} 0 R" else res << "\n/Contents [\n" @contents.each { |c| res << "#{c.oid} 0 R\n" } res << "]" end # MediaBox:: rectangle (Required; inheritable). A rectangle (see # Section 3.8.4, "Rectangles"), expressed in default user # space units, defining the boundaries of the physical # medium on which the page is intended to be displayed or # printed (see Section 10.10.1, "Page Boundaries"). res << "\n/MediaBox [#{@media_box.join(' ')}]" unless @media_box.nil? or @media_box.empty? # CropBox:: rectangle (Optional; inheritable) A rectangle, expressed # in default user space units, defining the visible region # of default user space. When the page is displayed or # printed, its contents are to be clipped (cropped) to # this rectangle and then imposed on the output medium in # some implementation-defined manner (see Section 10.10.1, # "Page Boundaries"). Default value: the value of MediaBox. res << "\n/CropBox [#{@crop_box.join(' ')}]" unless @crop_box.nil? or @crop_box.empty? # BleedBox:: rectangle (Optional; PDF 1.3) A rectangle, expressed in # default user space units, defining the region to which # the contents of the page should be clipped when output # in a production environment (see Section 10.10.1, "Page # Boundaries"). Default value: the value of CropBox. res << "\n/BleedBox [#{@bleed_box.join(' ')}]" unless @bleed_box.nil? or @bleed_box.empty? # TrimBox:: rectangle (Optional; PDF 1.3) A rectangle, expressed in # default user space units, defining the intended # dimensions of the finished page after trimming (see # Section 10.10.1, "Page Boundaries"). Default value: the # value of CropBox. res << "\n/TrimBox [#{@trim_box.join(' ')}]" unless @trim_box.nil? or @trim_box.empty? # ArtBox:: rectangle (Optional; PDF 1.3) A rectangle, expressed in # default user space units, defining the extent of the # page's meaningful content (including potential white # space) as intended by the page's creator (see Section # 10.10.1, "Page Boundaries"). Default value: the value of # CropBox. res << "\n/ArtBox [#{@art_box.join(' ')}]" unless @art_box.nil? or @art_box.empty? res << "\n>>\nendobj" end |