Class: PdfOxide::PdfPage
- Inherits:
-
Object
- Object
- PdfOxide::PdfPage
- Defined in:
- lib/pdf_oxide/pdf_page.rb
Overview
A page within a PdfDocument, identified by 0-based page index.
Mirrors ‘fyi.oxide.pdf.PdfPage`. Lightweight view — holds no native handle of its own; it borrows from its parent document. Operations after the parent’s ‘#close` raise `InvalidStateError`.
Construct via PdfOxide::PdfDocument#page or PdfOxide::PdfDocument#pages.
Instance Attribute Summary collapse
-
#index ⇒ Integer
readonly
0-based page index.
-
#parent ⇒ PdfDocument
readonly
The owning document.
Instance Method Summary collapse
-
#crop_box ⇒ Hash
{ x:, y:, width:, height: } — crop box, falling back to #media_box when /CropBox is absent (Java parity).
-
#height ⇒ Float
Page height in PDF user-space units.
-
#initialize(parent, index) ⇒ PdfPage
constructor
A new instance of PdfPage.
-
#media_box ⇒ Hash
{ x:, y:, width:, height: } in PDF user-space.
-
#rotation ⇒ Integer
Page rotation in degrees.
-
#text ⇒ String
Extract this page’s text.
-
#to_s ⇒ String
(also: #inspect)
Short inspection-style label (‘#<PdfOxide::PdfPage index=N>`).
-
#width ⇒ Float
Page width in PDF user-space units.
Constructor Details
#initialize(parent, index) ⇒ PdfPage
Returns a new instance of PdfPage.
19 20 21 22 23 24 |
# File 'lib/pdf_oxide/pdf_page.rb', line 19 def initialize(parent, index) raise ::PdfOxide::ArgumentError, 'parent cannot be nil' if parent.nil? @parent = parent @index = index end |
Instance Attribute Details
#index ⇒ Integer (readonly)
Returns 0-based page index.
16 17 18 |
# File 'lib/pdf_oxide/pdf_page.rb', line 16 def index @index end |
#parent ⇒ PdfDocument (readonly)
Returns the owning document.
13 14 15 |
# File 'lib/pdf_oxide/pdf_page.rb', line 13 def parent @parent end |
Instance Method Details
#crop_box ⇒ Hash
Returns { x:, y:, width:, height: } — crop box, falling back to #media_box when /CropBox is absent (Java parity).
48 49 50 |
# File 'lib/pdf_oxide/pdf_page.rb', line 48 def crop_box media_box end |
#height ⇒ Float
Returns page height in PDF user-space units.
32 33 34 |
# File 'lib/pdf_oxide/pdf_page.rb', line 32 def height media_box[:height] end |
#media_box ⇒ Hash
Returns { x:, y:, width:, height: } in PDF user-space. v0.3.55 limitation: pdf_oxide doesn’t yet expose a public per-page media-box accessor through the C ABI; the canonical route is ‘pdf_render_page_fit`’s implicit dimensions. Returns a zero-rect placeholder for now — mirrors PdfPage::cropBox() in Java which also currently defers crop-box access.
42 43 44 |
# File 'lib/pdf_oxide/pdf_page.rb', line 42 def media_box { x: 0.0, y: 0.0, width: 0.0, height: 0.0 } end |
#rotation ⇒ Integer
Returns page rotation in degrees. v0.3.55: the C ABI doesn’t yet expose a per-page rotation accessor — returns 0.
54 55 56 |
# File 'lib/pdf_oxide/pdf_page.rb', line 54 def rotation 0 end |
#text ⇒ String
Extract this page’s text. Equivalent to ‘parent.extract_text(index)`.
60 61 62 |
# File 'lib/pdf_oxide/pdf_page.rb', line 60 def text @parent.extract_text(@index) end |
#to_s ⇒ String Also known as: inspect
Returns short inspection-style label (‘#<PdfOxide::PdfPage index=N>`). Use #text to get the extracted page text.
66 67 68 |
# File 'lib/pdf_oxide/pdf_page.rb', line 66 def to_s "#<PdfOxide::PdfPage index=#{@index}>" end |
#width ⇒ Float
Returns page width in PDF user-space units.
27 28 29 |
# File 'lib/pdf_oxide/pdf_page.rb', line 27 def width media_box[:width] end |