Class: CorpPdf::Page
- Inherits:
-
Object
- Object
- CorpPdf::Page
- Defined in:
- lib/corp_pdf/page.rb
Overview
Represents a page in a PDF document
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#ref ⇒ Object
readonly
Returns the value of attribute ref.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
-
#add_field(name, options = {}) ⇒ Object
Add a field to this page Options are the same as Document#add_field, but :page is automatically set.
-
#art_box ⇒ Object
Get ArtBox dimensions.
-
#bleed_box ⇒ Object
Get BleedBox dimensions.
-
#crop_box ⇒ Object
Get CropBox dimensions.
-
#initialize(page, width, height, ref, metadata, document) ⇒ Page
constructor
A new instance of Page.
-
#media_box ⇒ Object
Get MediaBox dimensions.
-
#page_number ⇒ Object
Get the page number.
-
#page_ref ⇒ Object
Get the page reference [obj_num, gen_num].
-
#rotated? ⇒ Boolean
Check if page has rotation.
-
#rotation ⇒ Object
Get rotation angle (0, 90, 180, 270).
-
#to_h ⇒ Object
Convert to hash for backward compatibility.
-
#to_s ⇒ Object
(also: #inspect)
String representation for debugging.
-
#trim_box ⇒ Object
Get TrimBox dimensions.
Constructor Details
#initialize(page, width, height, ref, metadata, document) ⇒ Page
Returns a new instance of Page.
8 9 10 11 12 13 14 15 |
# File 'lib/corp_pdf/page.rb', line 8 def initialize(page, width, height, ref, , document) @page = page # Page number (1-indexed) @width = width @height = height @ref = ref # [obj_num, gen_num] = # Hash with :rotate, :media_box, :crop_box, etc. @document = document end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
6 7 8 |
# File 'lib/corp_pdf/page.rb', line 6 def document @document end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
6 7 8 |
# File 'lib/corp_pdf/page.rb', line 6 def height @height end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
6 7 8 |
# File 'lib/corp_pdf/page.rb', line 6 def end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
6 7 8 |
# File 'lib/corp_pdf/page.rb', line 6 def page @page end |
#ref ⇒ Object (readonly)
Returns the value of attribute ref.
6 7 8 |
# File 'lib/corp_pdf/page.rb', line 6 def ref @ref end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
6 7 8 |
# File 'lib/corp_pdf/page.rb', line 6 def width @width end |
Instance Method Details
#add_field(name, options = {}) ⇒ Object
Add a field to this page Options are the same as Document#add_field, but :page is automatically set
19 20 21 22 23 |
# File 'lib/corp_pdf/page.rb', line 19 def add_field(name, = {}) # Automatically set the page number to this page = .merge(page: @page) @document.add_field(name, ) end |
#art_box ⇒ Object
Get ArtBox dimensions
56 57 58 |
# File 'lib/corp_pdf/page.rb', line 56 def art_box [:art_box] end |
#bleed_box ⇒ Object
Get BleedBox dimensions
61 62 63 |
# File 'lib/corp_pdf/page.rb', line 61 def bleed_box [:bleed_box] end |
#crop_box ⇒ Object
Get CropBox dimensions
51 52 53 |
# File 'lib/corp_pdf/page.rb', line 51 def crop_box [:crop_box] end |
#media_box ⇒ Object
Get MediaBox dimensions
46 47 48 |
# File 'lib/corp_pdf/page.rb', line 46 def media_box [:media_box] end |
#page_number ⇒ Object
Get the page number
26 27 28 |
# File 'lib/corp_pdf/page.rb', line 26 def page_number @page end |
#page_ref ⇒ Object
Get the page reference [obj_num, gen_num]
31 32 33 |
# File 'lib/corp_pdf/page.rb', line 31 def page_ref @ref end |
#rotated? ⇒ Boolean
Check if page has rotation
36 37 38 |
# File 'lib/corp_pdf/page.rb', line 36 def rotated? ![:rotate].nil? && [:rotate] != 0 end |
#rotation ⇒ Object
Get rotation angle (0, 90, 180, 270)
41 42 43 |
# File 'lib/corp_pdf/page.rb', line 41 def rotation [:rotate] || 0 end |
#to_h ⇒ Object
Convert to hash for backward compatibility
80 81 82 83 84 85 86 87 88 |
# File 'lib/corp_pdf/page.rb', line 80 def to_h { page: @page, width: @width, height: @height, ref: @ref, metadata: } end |
#to_s ⇒ Object Also known as: inspect
String representation for debugging
71 72 73 74 75 |
# File 'lib/corp_pdf/page.rb', line 71 def to_s dims = width && height ? " #{width}x#{height}" : "" rot = rotated? ? " (rotated #{rotation}°)" : "" "#<CorpPdf::Page page=#{page}#{dims}#{rot} ref=#{ref.inspect}>" end |
#trim_box ⇒ Object
Get TrimBox dimensions
66 67 68 |
# File 'lib/corp_pdf/page.rb', line 66 def trim_box [:trim_box] end |