Class | PDF::Writer::Object::Pages |
In: |
lib/pdf/writer/object/pages.rb
|
Parent: | PDF::Writer::Object |
bleed_box | [RW] | |
media_box | [RW] | Each of the following should be an array of 4 numbers, the x and y coordinates of the lower left and upper right bounds of the box. |
procset | [RW] | |
trim_box | [RW] |
# File lib/pdf/writer/object/pages.rb, line 13 13: def initialize(parent) 14: super(parent) 15: 16: @parent.catalog.pages = self 17: 18: @pages = [] 19: @procset = nil 20: @media_box = nil 21: @fonts = [] 22: @xObjects = [] 23: @bleed_box = nil 24: @trim_box = nil 25: end
Add the page ID to the end of the page list.
# File lib/pdf/writer/object/pages.rb, line 36 36: def <<(p) 37: if p.kind_of?(PDF::Writer::Object::Page) 38: @pages << p 39: elsif p.kind_of?(PDF::Writer::Object::Font) 40: @fonts << p 41: elsif p.kind_of?(PDF::Writer::External) 42: @xObjects << p 43: else 44: raise ArgumentError, PDF::Message[:req_FPXO] 45: end 46: end
Add a page to the page list. If p is just a Page, then it will be added to the page list. Otherwise, it will be treated as a Hash with keys :page, :pos, and :rpage. :page is the Page to be added to the list; :pos is :before or :after; :rpage is the Page to which the new Page will be added relative to.
# File lib/pdf/writer/object/pages.rb, line 53 53: def add(p) 54: if p.kind_of?(PDF::Writer::Object::Page) 55: @pages << p 56: elsif p.kind_of?(PDF::Writer::FontMetrics) 57: @fonts << p 58: elsif p.kind_of?(PDF::Writer::External) 59: @xObjects << p 60: elsif p.kind_of?(Hash) 61: # Find a match. 62: i = @pages.index(p[:rpage]) 63: unless i.nil? 64: # There is a match; insert the page. 65: case p[:pos] 66: when :before 67: @pages[i, 0] = p[:page] 68: when :after 69: @pages[i + 1, 0] = p[:page] 70: else 71: raise ArgumentError, PDF::Message[:invalid_pos] 72: end 73: end 74: else 75: raise ArgumentError, PDF::Message[:req_FPXOH] 76: end 77: end
# File lib/pdf/writer/object/pages.rb, line 86 86: def to_s 87: unless @pages.empty? 88: res = "\n#{@oid} 0 obj\n<< /Type /Pages\n/Kids [" 89: @pages.uniq! # uniqify the data... 90: @pages.each { |p| res << "#{p.oid} 0 R\n" } 91: res << "]\n/Count #{@pages.size}" 92: unless @fonts.empty? and @procset.nil? 93: res << "\n/Resources <<" 94: res << "\n/ProcSet #{@procset.oid} 0 R" unless @procset.nil? 95: unless @fonts.empty? 96: res << "\n/Font << " 97: @fonts.each { |f| res << "\n/F#{f.font_id} #{f.oid} 0 R" } 98: res << " >>" 99: end 100: unless @xObjects.empty? 101: res << "\n/XObject << " 102: @xObjects.each { |x| res << "\n/#{x.label} #{x.oid} 0 R" } 103: res << " >>" 104: end 105: res << "\n>>" 106: res << "\n/MediaBox [#{@media_box.join(' ')}]" unless @media_box.nil? or @media_box.empty? 107: res << "\n/BleedBox [#{@bleed_box.join(' ')}]" unless @bleed_box.nil? or @bleed_box.empty? 108: res << "\n/TrimBox [#{@trim_box.join(' ')}]" unless @trim_box.nil? or @trim_box.empty? 109: end 110: res << "\n >>\nendobj" 111: else 112: "\n#{@oid} 0 obj\n<< /Type /Pages\n/Count 0\n>>\nendobj" 113: end 114: end