Class: PdfOxide::PdfPage

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#indexInteger (readonly)

Returns 0-based page index.

Returns:

  • (Integer)

    0-based page index.



16
17
18
# File 'lib/pdf_oxide/pdf_page.rb', line 16

def index
  @index
end

#parentPdfDocument (readonly)

Returns the owning document.

Returns:



13
14
15
# File 'lib/pdf_oxide/pdf_page.rb', line 13

def parent
  @parent
end

Instance Method Details

#crop_boxHash

Returns { x:, y:, width:, height: } — crop box, falling back to #media_box when /CropBox is absent (Java parity).

Returns:

  • (Hash)

    { 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

#heightFloat

Returns page height in PDF user-space units.

Returns:

  • (Float)

    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_boxHash

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.

Returns:

  • (Hash)

    { 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

#rotationInteger

Returns page rotation in degrees. v0.3.55: the C ABI doesn’t yet expose a per-page rotation accessor — returns 0.

Returns:

  • (Integer)

    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

#textString

Extract this page’s text. Equivalent to ‘parent.extract_text(index)`.

Returns:

  • (String)


60
61
62
# File 'lib/pdf_oxide/pdf_page.rb', line 60

def text
  @parent.extract_text(@index)
end

#to_sString Also known as: inspect

Returns short inspection-style label (‘#<PdfOxide::PdfPage index=N>`). Use #text to get the extracted page text.

Returns:

  • (String)

    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

#widthFloat

Returns page width in PDF user-space units.

Returns:

  • (Float)

    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