Class | PDF::Writer::Object::Page |
In: |
lib/pdf/writer/object/page.rb
|
Parent: | PDF::Writer::Object |
A page object, it also creates a contents object to hold its contents
contents | [RW] | |
page_number | [R] |
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.
# File lib/pdf/writer/object/page.rb, line 16 16: def initialize(parent, relative = nil) 17: super(parent) 18: 19: @parent.current_page = self 20: @owner = @parent.instance_variable_get('@current_node') 21: @page_number = @parent.pages.size 22: @contents = [] 23: 24: if relative.nil? 25: @parent.pages << self 26: else 27: relative[:page] = self 28: @parent.pages.add(relative) 29: end 30: 31: # make a contents object to go with this page 32: @contents << PDF::Writer::Object::Contents.new(@parent, self) 33: @parent.instance_variable_set('@current_contents', @contents[-1]) 34: match = (@parent.pages.size % 2 == 0 ? :even_pages : :odd_pages) 35: # Cheat here. I don't want to add an unnecessary attribute. 36: @parent.instance_variable_get('@add_loose_objects').each do |obj, target| 37: @contents << obj if target == :all_pages or match == target 38: end 39: 40: @annotations = [] 41: 42: @media_box = nil 43: @crop_box = nil 44: @bleed_box = nil 45: @trim_box = nil 46: @art_box = nil 47: end
# File lib/pdf/writer/object/page.rb, line 52 52: def add_annotation(a) 53: @annotations << a 54: end
# File lib/pdf/writer/object/page.rb, line 56 56: def to_s 57: res = "\n#{@oid} 0 obj\n<< /Type /Page\n/Parent #{@owner.oid} 0 R" 58: unless @annotations.empty? 59: res << "\n/Annots [" 60: @annotations.each { |e| res << " #{e.oid} 0 R"} 61: res << "]" 62: end 63: 64: if @contents.size == 1 65: res << "\n/Contents #{@contents[0].oid} 0 R" 66: else 67: res << "\n/Contents [\n" 68: @contents.each { |c| res << "#{c.oid} 0 R\n" } 69: res << "]" 70: end 71: 72: # MediaBox:: rectangle (Required; inheritable). A rectangle (see 73: # Section 3.8.4, “Rectangles”), expressed in default user 74: # space units, defining the boundaries of the physical 75: # medium on which the page is intended to be displayed or 76: # printed (see Section 10.10.1, “Page Boundaries”). 77: res << "\n/MediaBox [#{@media_box.join(' ')}]" unless @media_box.nil? or @media_box.empty? 78: # CropBox:: rectangle (Optional; inheritable) A rectangle, expressed 79: # in default user space units, defining the visible region 80: # of default user space. When the page is displayed or 81: # printed, its contents are to be clipped (cropped) to 82: # this rectangle and then imposed on the output medium in 83: # some implementation-defined manner (see Section 10.10.1, 84: # “Page Boundaries”). Default value: the value of MediaBox. 85: res << "\n/CropBox [#{@crop_box.join(' ')}]" unless @crop_box.nil? or @crop_box.empty? 86: # BleedBox:: rectangle (Optional; PDF 1.3) A rectangle, expressed in 87: # default user space units, defining the region to which 88: # the contents of the page should be clipped when output 89: # in a production environment (see Section 10.10.1, “Page 90: # Boundaries”). Default value: the value of CropBox. 91: res << "\n/BleedBox [#{@bleed_box.join(' ')}]" unless @bleed_box.nil? or @bleed_box.empty? 92: # TrimBox:: rectangle (Optional; PDF 1.3) A rectangle, expressed in 93: # default user space units, defining the intended 94: # dimensions of the finished page after trimming (see 95: # Section 10.10.1, “Page Boundaries”). Default value: the 96: # value of CropBox. 97: res << "\n/TrimBox [#{@trim_box.join(' ')}]" unless @trim_box.nil? or @trim_box.empty? 98: # ArtBox:: rectangle (Optional; PDF 1.3) A rectangle, expressed in 99: # default user space units, defining the extent of the 100: # page’s meaningful content (including potential white 101: # space) as intended by the page’s creator (see Section 102: # 10.10.1, “Page Boundaries”). Default value: the value of 103: # CropBox. 104: res << "\n/ArtBox [#{@art_box.join(' ')}]" unless @art_box.nil? or @art_box.empty? 105: 106: res << "\n>>\nendobj" 107: end