Method: Prawn::Text#draw_text
- Defined in:
- lib/prawn/text.rb
#draw_text(text, options) ⇒ void
This method returns an undefined value.
Draws text on the page, beginning at the point specified by the ‘:at` option the string is assumed to be pre-formatted to properly fit the page.
“‘ruby pdf.draw_text “Hello World”, at: [100, 100] pdf.draw_text “Goodbye World”, at: [50,50], size: 16 “`
If your font contains kerning pair data that Prawn can parse, the text will be kerned by default. You can disable kerning by including a ‘false` `:kerning` option. If you want to disable kerning on an entire document, set `default_kerning = false` for that document
#### Text Positioning Details
Prawn will position your text by the left-most edge of its baseline, and flow along a single line. (This means that ‘:align` will not work)
#### Rotation
Text can be rotated before it is placed on the canvas by specifying the ‘:rotate` option with a given angle. Rotation occurs counter-clockwise.
#### Encoding
Note that strings passed to this function should be encoded as UTF-8. If you get unexpected characters appearing in your rendered document, check this.
If the current font is a built-in one, although the string must be encoded as UTF-8, only characters that are available in WinAnsi are allowed.
If an empty box is rendered to your PDF instead of the character you wanted it usually means the current font doesn’t include that character.
345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/prawn/text.rb', line 345 def draw_text(text, ) = (.dup) # dup because normalize_encoding changes the string text = text.to_s.dup save_font do () text = font.normalize_encoding(text) font_size([:size]) { draw_text!(text, ) } end end |