[ACCEPTED]-How can I do inline formatting (bold and underline) for PDF generated by Prawnto in Rails?-prawn

Accepted answer
Score: 11

we may have similar apps...

Prawn can do 17 basic inline formatting based on (simple) HTML 16 - take a look at the text/inline_format.rb example on github. In 15 fact, take a look at the whole Prawn Example Gallery if you haven't 14 - it's one of the best I've seen.

To get 13 the HTML you need you can either type HTML 12 straight into the textarea (a bit ugly - might 11 not be a good idea if anyone besides you 10 will be entering text) or use something 9 like Markdown to interpret more user-friendly 8 "style codes" like StackOverflow 7 does. I think BlueCloth is the best-known ruby implementation, but 6 I've never used it myself.

Bold and underline? No 5 problem. Font size might be harder - I 4 imagine it would be tricky to get BlueCloth 3 to emit something like the (deprecated) < font 2 > tag they use in the Prawn example...

Hope 1 this helps - cheers!

Score: 3

In response to bold text...

In controller:

respond_to do |format|
  format.pdf  {render :layout => false}
  prawnto :filename => @current_project+".pdf", :prawn => {:font => 'Times-Roman'}, :inline=>false     

Then 10 in pdf.prawn file you can use:

in a text 9 box:

pdf.text_box "Document Revisions", :size => 16, :style => :bold, :at => [0.mm,10.mm], :width => 100.mm, :height => 15.mm;

or in a line of text on its own:

pdf.text "Document Contents", :size => 16, :style => :bold;

As I 8 understand it - but not tried it - to underline 7 you need to do:

:styles => [:bold, :underline];

reference this link for more

This is not a feature of 6 version 0.8.4 but version 0.10.2 - not sure 5 how you would do underline in 0.8.4. I am 4 not currently using 0.10.2 so can not confirm 3 that this is works.

Based on what you have 2 said I think this is what you want to for 1 bold:

pdf.text_box "#{@yourtext.text}", :size => 16, :style => :bold, :at => [0.mm,10.mm], :width => 100.mm, :height => 15.mm;

More Related questions