Class: Pdf::Renderer
- Inherits:
-
Object
- Object
- Pdf::Renderer
- Defined in:
- lib/pdf/renderer.rb
Instance Attribute Summary collapse
-
#pdf ⇒ Object
readonly
Returns the value of attribute pdf.
Instance Method Summary collapse
- #bounding_box(point, **options, &block) ⇒ Object
- #bounds ⇒ Object
- #canvas(&block) ⇒ Object
- #cursor ⇒ Object
- #draw_text(content, at:, **options) ⇒ Object
- #fill_and_stroke_rounded_rectangle(point, width, height, radius) ⇒ Object
- #fill_color(color) ⇒ Object
- #finalize ⇒ Object
- #float(&block) ⇒ Object
- #height_of(content, **options) ⇒ Object
-
#image(path, **options) ⇒ Object
Image embedding - raises if file not found (no silent failures).
-
#image_data(data, **options) ⇒ Object
Image from string data (for generated images like QR codes).
-
#initialize ⇒ Renderer
constructor
A new instance of Renderer.
- #line_width(width) ⇒ Object
- #move_down(amount) ⇒ Object
- #page_count ⇒ Object
- #page_number ⇒ Object
-
#raw {|@pdf| ... } ⇒ Object
— Escape hatch for direct Prawn access —.
- #repeat(page_filter, options = {}, &block) ⇒ Object
- #setup(margins: {}) ⇒ Object
-
#setup_footer(&block) ⇒ Object
— Footer setup (deferred) —.
- #start_new_page ⇒ Object
- #stroke_color(color) ⇒ Object
- #stroke_horizontal_rule ⇒ Object
- #table(data, **options, &block) ⇒ Object
-
#text(content, **options) ⇒ Object
— Primitives —.
- #text_box(content, at:, **options) ⇒ Object
- #width_of(content, **options) ⇒ Object
Constructor Details
#initialize ⇒ Renderer
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
#pdf ⇒ Object (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, **, &block) @pdf.bounding_box(point, **, &block) end |
#bounds ⇒ Object
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 |
#cursor ⇒ Object
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:, **) @pdf.draw_text content.to_s, at: at, ** 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 |
#finalize ⇒ Object
27 28 29 30 |
# File 'lib/pdf/renderer.rb', line 27 def finalize 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, **) @pdf.height_of content.to_s, ** 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, **) raise Pdf::FileNotFoundError, "Image not found: #{path}" unless File.exist?(path) @pdf.image path, ** 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, **) @pdf.image StringIO.new(data), ** 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_count ⇒ Object
122 123 124 |
# File 'lib/pdf/renderer.rb', line 122 def page_count @pdf.page_count end |
#page_number ⇒ Object
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 —
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, = {}, &block) @pdf.repeat(page_filter, , &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 |
#setup_footer(&block) ⇒ Object
— Footer setup (deferred) —
138 139 140 |
# File 'lib/pdf/renderer.rb', line 138 def (&block) @footer_callback = block end |
#start_new_page ⇒ Object
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_rule ⇒ Object
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, **, &block) @pdf.table(data, **, &block) end |
#text(content, **options) ⇒ Object
— Primitives —
34 35 36 |
# File 'lib/pdf/renderer.rb', line 34 def text(content, **) @pdf.text content.to_s, ** end |
#text_box(content, at:, **options) ⇒ Object
38 39 40 |
# File 'lib/pdf/renderer.rb', line 38 def text_box(content, at:, **) @pdf.text_box content.to_s, at: at, ** end |
#width_of(content, **options) ⇒ Object
106 107 108 |
# File 'lib/pdf/renderer.rb', line 106 def width_of(content, **) @pdf.width_of content.to_s, ** end |