Class: CorpPdf::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/corp_pdf/page.rb

Overview

Represents a page in a PDF document

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#documentObject (readonly)

Returns the value of attribute document.



6
7
8
# File 'lib/corp_pdf/page.rb', line 6

def document
  @document
end

#heightObject (readonly)

Returns the value of attribute height.



6
7
8
# File 'lib/corp_pdf/page.rb', line 6

def height
  @height
end

#metadataObject (readonly)

Returns the value of attribute metadata.



6
7
8
# File 'lib/corp_pdf/page.rb', line 6

def 
  
end

#pageObject (readonly)

Returns the value of attribute page.



6
7
8
# File 'lib/corp_pdf/page.rb', line 6

def page
  @page
end

#refObject (readonly)

Returns the value of attribute ref.



6
7
8
# File 'lib/corp_pdf/page.rb', line 6

def ref
  @ref
end

#widthObject (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, options = {})
  # Automatically set the page number to this page
  options_with_page = options.merge(page: @page)
  @document.add_field(name, options_with_page)
end

#art_boxObject

Get ArtBox dimensions



56
57
58
# File 'lib/corp_pdf/page.rb', line 56

def art_box
  [:art_box]
end

#bleed_boxObject

Get BleedBox dimensions



61
62
63
# File 'lib/corp_pdf/page.rb', line 61

def bleed_box
  [:bleed_box]
end

#crop_boxObject

Get CropBox dimensions



51
52
53
# File 'lib/corp_pdf/page.rb', line 51

def crop_box
  [:crop_box]
end

#media_boxObject

Get MediaBox dimensions



46
47
48
# File 'lib/corp_pdf/page.rb', line 46

def media_box
  [:media_box]
end

#page_numberObject

Get the page number



26
27
28
# File 'lib/corp_pdf/page.rb', line 26

def page_number
  @page
end

#page_refObject

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

Returns:

  • (Boolean)


36
37
38
# File 'lib/corp_pdf/page.rb', line 36

def rotated?
  ![:rotate].nil? && [:rotate] != 0
end

#rotationObject

Get rotation angle (0, 90, 180, 270)



41
42
43
# File 'lib/corp_pdf/page.rb', line 41

def rotation
  [:rotate] || 0
end

#to_hObject

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_sObject 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_boxObject

Get TrimBox dimensions



66
67
68
# File 'lib/corp_pdf/page.rb', line 66

def trim_box
  [:trim_box]
end