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.

Parameters:

  • text (String)
  • options (Hash{Symbol => any})

Options Hash (options):

  • :at (Array(Number, Number))

    Required. The position at which to start the text.

  • :kerning (Boolean) — default: value of default_kerning?

    Whether or not to use kerning (if it is available with the current font).

  • :size (Number) — default: current font size

    The font size to use.

  • :style (Symbol) — default: current style

    The style to use. The requested style must be part of the current font family.

  • :rotate (Number)

    The angle to which to rotate text.

Raises:

  • (ArgumentError)

    If ‘:at` option is omitted or `:align</tt> option is included.



345
346
347
348
349
350
351
352
353
354
355
# File 'lib/prawn/text.rb', line 345

def draw_text(text, options)
  options = inspect_options_for_draw_text(options.dup)

  # dup because normalize_encoding changes the string
  text = text.to_s.dup
  save_font do
    process_text_options(options)
    text = font.normalize_encoding(text)
    font_size(options[:size]) { draw_text!(text, options) }
  end
end