A page object, it also creates a contents object to hold its contents
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 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
# File lib/pdf/writer/object/page.rb, line 52 def add_annotation(a) @annotations << a end
# 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
Generated with the Darkfish Rdoc Generator 2.