Format html content from database using prawn

1.1k views Asked by At

How can render HTML content from database in a prawn document

class PdfReport < Prawn::Document
  def initialize user
    super()
    text user.description #=> "<p>It's an html content</p>"
  end
end

The output i am getting from the above code is a string with HTML tags. I want something like html_safe. Is it possible in Prawn?

1

There are 1 answers

2
adg On

The html paragraph tag doesn't work in prawn. If you're looking for how to create a separation between paragraphs, see https://stackoverflow.com/a/49683036 which shows how to vertically measure text boxes (and formatted text boxes) and move the cursor accordingly.

But prawn can interpret some html tags such as bold:

s = "<b>It's an html content</b>"

text s # "<b>It's an html content</b>"

text s, :inline_format => true # It's an html content