How can I do inline formatting (bold and underline) for PDF created by Prawnto in Rails?

I am creating a PDF file using the shrimp and the Prawnto plugin in my rails application.

I create a standard form with a standard text box and present it as the body of a PDF file.

However, I need to be able to format words and sentences with:

  • bold
  • underline
  • different font sizes possible

I want to be able to do this from the textarea input field. Right now, because I use prawnto, I basically generate a view that outputs what is in the text box.

But if I put, say, bold in the text area, it is not formatted, it just displays.

How to do it?

+7
source share
2 answers

we may have similar applications ...

Shrimp can do basic inline formatting based on (simple) HTML - see the example text / inline_format.rb on github. In fact, look at the gallery of shrimp samples , if you donโ€™t have one, this is one of the best I've seen.

To get the HTML code you need, you can type HTML directly into the text box (a bit ugly - maybe not a good idea if anyone else is entering text) or use something like Markdown to interpret more user-friendly "stylish codes" like StackOverflow. I think BlueCloth is Ruby's most famous implementation, but I never used it myself.

Bold and underline? No problems. The font size can be tricky - I think it would be difficult to get BlueCloth to emit something like the (obsolete) font> that they use in the shrimp example ...

Hope this helps - greetings!

+6
source

In response to the bold text ...

In the controller:

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

Then in the pdf.prawn file you can use:

in the text box:

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

or in a separate line of text:

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

As I understand it, but have not tried - emphasize what you need to do:

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

confirm this link for more

This is not a function of version 0.8.4, but version 0.10.2 - you donโ€™t know how you will emphasize in 0.8.4. I am not currently using 0.10.2, so I cannot confirm that this works.

Based on what you said, I think this is what you want for bold:

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

+1
source

All Articles