Class: Pdf::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf/renderer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRenderer

Returns a new instance of Renderer.



13
14
15
16
# File 'lib/pdf/renderer.rb', line 13

def initialize
  @pdf = nil
  @footer_callback = nil
end

Instance Attribute Details

#pdfObject (readonly)

Returns the value of attribute pdf.



11
12
13
# File 'lib/pdf/renderer.rb', line 11

def pdf
  @pdf
end

Instance Method Details

#bounding_box(point, **options, &block) ⇒ Object



62
63
64
# File 'lib/pdf/renderer.rb', line 62

def bounding_box(point, **options, &block)
  @pdf.bounding_box(point, **options, &block)
end

#boundsObject



58
59
60
# File 'lib/pdf/renderer.rb', line 58

def bounds
  @pdf.bounds
end

#canvas(&block) ⇒ Object



66
67
68
# File 'lib/pdf/renderer.rb', line 66

def canvas(&block)
  @pdf.canvas(&block)
end

#cursorObject



54
55
56
# File 'lib/pdf/renderer.rb', line 54

def cursor
  @pdf.cursor
end

#draw_text(content, at:, **options) ⇒ Object



102
103
104
# File 'lib/pdf/renderer.rb', line 102

def draw_text(content, at:, **options)
  @pdf.draw_text content.to_s, at: at, **options
end

#fill_and_stroke_rounded_rectangle(point, width, height, radius) ⇒ Object



98
99
100
# File 'lib/pdf/renderer.rb', line 98

def fill_and_stroke_rounded_rectangle(point, width, height, radius)
  @pdf.fill_and_stroke_rounded_rectangle point, width, height, radius
end

#fill_color(color) ⇒ Object



86
87
88
# File 'lib/pdf/renderer.rb', line 86

def fill_color(color)
  @pdf.fill_color color
end

#finalizeObject



27
28
29
30
# File 'lib/pdf/renderer.rb', line 27

def finalize
  apply_footer if @footer_callback
  @pdf.render
end

#float(&block) ⇒ Object



70
71
72
# File 'lib/pdf/renderer.rb', line 70

def float(&block)
  @pdf.float(&block)
end

#height_of(content, **options) ⇒ Object



110
111
112
# File 'lib/pdf/renderer.rb', line 110

def height_of(content, **options)
  @pdf.height_of content.to_s, **options
end

#image(path, **options) ⇒ Object

Image embedding - raises if file not found (no silent failures)



75
76
77
78
79
# File 'lib/pdf/renderer.rb', line 75

def image(path, **options)
  raise Pdf::FileNotFoundError, "Image not found: #{path}" unless File.exist?(path)

  @pdf.image path, **options
end

#image_data(data, **options) ⇒ Object

Image from string data (for generated images like QR codes)



82
83
84
# File 'lib/pdf/renderer.rb', line 82

def image_data(data, **options)
  @pdf.image StringIO.new(data), **options
end

#line_width(width) ⇒ Object



94
95
96
# File 'lib/pdf/renderer.rb', line 94

def line_width(width)
  @pdf.line_width width
end

#move_down(amount) ⇒ Object



42
43
44
# File 'lib/pdf/renderer.rb', line 42

def move_down(amount)
  @pdf.move_down amount
end

#page_countObject



122
123
124
# File 'lib/pdf/renderer.rb', line 122

def page_count
  @pdf.page_count
end

#page_numberObject



118
119
120
# File 'lib/pdf/renderer.rb', line 118

def page_number
  @pdf.page_number
end

#raw {|@pdf| ... } ⇒ Object

— Escape hatch for direct Prawn access —

Yields:



132
133
134
# File 'lib/pdf/renderer.rb', line 132

def raw(&block)
  yield @pdf
end

#repeat(page_filter, options = {}, &block) ⇒ Object



126
127
128
# File 'lib/pdf/renderer.rb', line 126

def repeat(page_filter, options = {}, &block)
  @pdf.repeat(page_filter, options, &block)
end

#setup(margins: {}) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/pdf/renderer.rb', line 18

def setup(margins: {})
  m = Pdf::DEFAULT_MARGINS.merge(margins)
  @pdf = Prawn::Document.new(
    margin: [m[:top], m[:right], m[:bottom], m[:left]]
  )
  setup_fonts
  self
end

— Footer setup (deferred) —



138
139
140
# File 'lib/pdf/renderer.rb', line 138

def setup_footer(&block)
  @footer_callback = block
end

#start_new_pageObject



50
51
52
# File 'lib/pdf/renderer.rb', line 50

def start_new_page
  @pdf.start_new_page
end

#stroke_color(color) ⇒ Object



90
91
92
# File 'lib/pdf/renderer.rb', line 90

def stroke_color(color)
  @pdf.stroke_color color
end

#stroke_horizontal_ruleObject



46
47
48
# File 'lib/pdf/renderer.rb', line 46

def stroke_horizontal_rule
  @pdf.stroke_horizontal_rule
end

#table(data, **options, &block) ⇒ Object



114
115
116
# File 'lib/pdf/renderer.rb', line 114

def table(data, **options, &block)
  @pdf.table(data, **options, &block)
end

#text(content, **options) ⇒ Object

— Primitives —



34
35
36
# File 'lib/pdf/renderer.rb', line 34

def text(content, **options)
  @pdf.text content.to_s, **options
end

#text_box(content, at:, **options) ⇒ Object



38
39
40
# File 'lib/pdf/renderer.rb', line 38

def text_box(content, at:, **options)
  @pdf.text_box content.to_s, at: at, **options
end

#width_of(content, **options) ⇒ Object



106
107
108
# File 'lib/pdf/renderer.rb', line 106

def width_of(content, **options)
  @pdf.width_of content.to_s, **options
end