Class: PDF::Core::Page
- Inherits:
-
Object
- Object
- PDF::Core::Page
- Defined in:
- lib/pdf/core/page.rb
Overview
:nodoc:
Instance Attribute Summary collapse
- #content ⇒ Object
- #dictionary ⇒ Object
-
#document ⇒ Object
Returns the value of attribute document.
-
#margins ⇒ Object
Returns the value of attribute margins.
-
#stack ⇒ Object
Returns the value of attribute stack.
Instance Method Summary collapse
- #dimensions ⇒ Object
- #ext_gstates ⇒ Object
- #finalize ⇒ Object
- #fonts ⇒ Object
- #graphic_state ⇒ Object
- #imported_page? ⇒ Boolean
- #in_stamp_stream? ⇒ Boolean
-
#initialize(document, options = {}) ⇒ Page
constructor
A new instance of Page.
- #layout ⇒ Object
-
#new_content_stream ⇒ Object
As per the PDF spec, each page can have multiple content streams.
- #resources ⇒ Object
- #size ⇒ Object
- #stamp_stream(dictionary) ⇒ Object
- #xobjects ⇒ Object
Constructor Details
#initialize(document, options = {}) ⇒ Page
Returns a new instance of Page.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/pdf/core/page.rb', line 18 def initialize(document, ={}) @document = document @margins = [:margins] || { :left => 36, :right => 36, :top => 36, :bottom => 36 } @stack = GraphicStateStack.new([:graphic_state]) if [:object_id] init_from_object() else init_new_page() end end |
Instance Attribute Details
#content ⇒ Object
74 75 76 |
# File 'lib/pdf/core/page.rb', line 74 def content @stamp_stream || document.state.store[@content] end |
#dictionary ⇒ Object
93 94 95 |
# File 'lib/pdf/core/page.rb', line 93 def dictionary defined?(@stamp_dictionary) && @stamp_dictionary || document.state.store[@dictionary] end |
#document ⇒ Object
Returns the value of attribute document.
15 16 17 |
# File 'lib/pdf/core/page.rb', line 15 def document @document end |
#margins ⇒ Object
Returns the value of attribute margins.
15 16 17 |
# File 'lib/pdf/core/page.rb', line 15 def margins @margins end |
#stack ⇒ Object
Returns the value of attribute stack.
15 16 17 |
# File 'lib/pdf/core/page.rb', line 15 def stack @stack end |
Instance Method Details
#dimensions ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/pdf/core/page.rb', line 143 def dimensions return inherited_dictionary_value(:MediaBox) if imported_page? coords = PDF::Core::PageGeometry::SIZES[size] || size [0,0] + case(layout) when :portrait coords when :landscape coords.reverse else raise PDF::Core::Errors::InvalidPageLayout, "Layout must be either :portrait or :landscape" end end |
#ext_gstates ⇒ Object
121 122 123 124 125 126 127 |
# File 'lib/pdf/core/page.rb', line 121 def ext_gstates if resources[:ExtGState] document.deref(resources[:ExtGState]) else resources[:ExtGState] = {} end end |
#finalize ⇒ Object
129 130 131 132 133 134 135 136 137 |
# File 'lib/pdf/core/page.rb', line 129 def finalize if dictionary.data[:Contents].is_a?(Array) dictionary.data[:Contents].each do |stream| stream.stream.compress! if document.compression_enabled? end else content.stream.compress! if document.compression_enabled? end end |
#fonts ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/pdf/core/page.rb', line 105 def fonts if resources[:Font] document.deref(resources[:Font]) else resources[:Font] = {} end end |
#graphic_state ⇒ Object
32 33 34 |
# File 'lib/pdf/core/page.rb', line 32 def graphic_state stack.current_state end |
#imported_page? ⇒ Boolean
139 140 141 |
# File 'lib/pdf/core/page.rb', line 139 def imported_page? @imported_page end |
#in_stamp_stream? ⇒ Boolean
51 52 53 |
# File 'lib/pdf/core/page.rb', line 51 def in_stamp_stream? !!@stamp_stream end |
#layout ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/pdf/core/page.rb', line 36 def layout return @layout if defined?(@layout) && @layout mb = dictionary.data[:MediaBox] if mb[3] > mb[2] :portrait else :landscape end end |
#new_content_stream ⇒ Object
As per the PDF spec, each page can have multiple content streams. This will add a fresh, empty content stream this the page, mainly for use in loading template files.
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/pdf/core/page.rb', line 82 def new_content_stream return if in_stamp_stream? unless dictionary.data[:Contents].is_a?(Array) dictionary.data[:Contents] = [content] end @content = document.ref({}) dictionary.data[:Contents] << document.state.store[@content] document.open_graphics_state end |
#resources ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/pdf/core/page.rb', line 97 def resources if dictionary.data[:Resources] document.deref(dictionary.data[:Resources]) else dictionary.data[:Resources] = {} end end |
#size ⇒ Object
47 48 49 |
# File 'lib/pdf/core/page.rb', line 47 def size defined?(@size) && @size || dimensions[2,2] end |
#stamp_stream(dictionary) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/pdf/core/page.rb', line 55 def stamp_stream(dictionary) @stamp_stream = "" @stamp_dictionary = dictionary graphic_stack_size = stack.stack.size document.save_graphics_state document.send(:freeze_stamp_graphics) yield if block_given? until graphic_stack_size == stack.stack.size document.restore_graphics_state end @stamp_dictionary << @stamp_stream @stamp_stream = nil @stamp_dictionary = nil end |
#xobjects ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/pdf/core/page.rb', line 113 def xobjects if resources[:XObject] document.deref(resources[:XObject]) else resources[:XObject] = {} end end |