Method: Prawn::Text#text
- Defined in:
- lib/prawn/text.rb
#text(string, options = {}) ⇒ void
This method returns an undefined value.
Draws text on the page.
If you want text to flow onto a new page or between columns, this is the method to use. If, instead, you want to place bounded text outside of the flow of a document (for captions, labels, charts, etc.), use Box or its convenience method #text_box.
Prawn attempts to wrap the text to fit within your current bounding box (or ‘margin_box` if no bounding box is being used). Text will flow onto the next page when it reaches the bottom of the bounding box. Text wrap in Prawn does not re-flow line breaks, so if you want fully automated text wrapping, be sure to remove newlines before attempting to draw your string.
#### Examples
“‘ruby pdf.text “Will be wrapped when it hits the edge of your bounding box” pdf.text “This will be centered”, align: :center pdf.text “This will be right aligned”, align: :right pdf.text “This includes inline <font size=’24’>formatting</font>”, inline_format: true “‘
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
The text is positioned at ‘font.ascender` below the baseline, making it easy to use this method within bounding boxes and spans.
#### 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.
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/prawn/text.rb', line 151 def text(string, = {}) return false if string.nil? # we modify the options. don't change the user's hash = .dup p = [:inline_format] if p p = [] unless p.is_a?(Array) .delete(:inline_format) array = text_formatter.format(string, *p) else array = [{ text: string }] end formatted_text(array, ) end |