Prawn: text() supresses leading whitespace

Created on 11 Feb 2010  ·  6Comments  ·  Source: prawnpdf/prawn

Prawn::Document.generate('x.pdf") do
   text "    x"
   text "          x"
end

Contrast to:

Prawn::Document.generate('x.pdf") do
   text "|    x"
   text "|         x"
end

Most helpful comment

@thbar your example breaks if you have multiple newlines. Use this instead:

content = content.gsub(/^([^\S\r\n]+)/m) { |m| "\xC2\xA0" * m.size }

From http://stackoverflow.com/a/17752989/165673

All 6 comments

Not a bug. Intentional behavior change by Daniel. See:
http://groups.google.com/group/prawn-ruby/browse_thread/thread/836c1349ec76c720

Ok, but how i can render this indentation:

   Prawn::Document.generate('x.pdf") do 
   text "              xxxxxx
               xxxxxx      
                   xxxxxxxxxxxxx"
   end

:indent_paragraphs property couldn`t help me with this.

Here's an example of how to do this using non-breaking spaces (here to display some code):

content = "def function(param)\n  puts 'this'\nend"
content = content.gsub(/^(\s+)/m) { |m| "\xC2\xA0" * m.size }
font "courier" do
  text content
end

@thbar your example breaks if you have multiple newlines. Use this instead:

content = content.gsub(/^([^\S\r\n]+)/m) { |m| "\xC2\xA0" * m.size }

From http://stackoverflow.com/a/17752989/165673

content = content.gsub(/^([^\S\r\n]+)/m) { |m| "\xC2\xA0" * m.size }
after doing this I got

PDF's built-in fonts have very limited support for internationalized text.
If you need full UTF-8 support, consider using a TTF font instead.

To disable this warning, add the following line to your code:
Prawn::Font::AFM.hide_m17n_warning = true

Then downloaded a font and it works.
Thank you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gioele picture gioele  ·  3Comments

robzolkos picture robzolkos  ·  16Comments

adhsharad picture adhsharad  ·  10Comments

mojavelinux picture mojavelinux  ·  3Comments

timokleemann picture timokleemann  ·  4Comments