I generate a PDF file using Prawn and the Prawnto plugin in my rails application.
我使用Prawn和我的rails应用程序中的Prawnto插件生成PDF文件。
I create a standard form with a standard textarea, and submit that as the body of the PDF file.
我使用标准文本区域创建标准表单,并将其作为PDF文件的正文提交。
However, I need to be able to format words and sentences with:
但是,我需要能够使用以下内容格式化单词和句子:
- bold
- underline
- maybe different type sizes
可能是不同的类型
I want to be able to do it from within the textarea input box. Right now, because I use prawnto, I basically am genering a view which outputs what is in the textarea.
我希望能够在textarea输入框中执行此操作。现在,因为我使用prawnto,我基本上正在产生一个视图,它输出textarea中的内容。
But if I put, say, bold in the text area, it doesn't format, it just renders.
但是,如果我在文本区域中添加粗体,它不会格式化,只会渲染。
How do I do this?
我该怎么做呢?
2 个解决方案
#1
8
we may have similar apps...
我们可能有类似的应用...
Prawn can do basic inline formatting based on (simple) HTML - take a look at the text/inline_format.rb example on github. In fact, take a look at the whole Prawn Example Gallery if you haven't - it's one of the best I've seen.
Prawn可以基于(简单)HTML进行基本的内联格式化 - 看一下github上的text / inline_format.rb示例。事实上,看看整个Prawn示例库,如果你还没有 - 这是我见过的最好的之一。
To get the HTML you need you can either type HTML straight into the textarea (a bit ugly - might not be a good idea if anyone besides you will be entering text) or use something like Markdown to interpret more user-friendly "style codes" like * does. I think BlueCloth is the best-known ruby implementation, but I've never used it myself.
要获得所需的HTML,您可以直接在textarea中输入HTML(有点难看 - 如果除了你之外的任何人都会输入文本可能不是一个好主意)或使用像Markdown这样的东西来解释更加用户友好的“样式代码”像*那样。我认为BlueCloth是最着名的ruby实现,但我自己从未使用它。
Bold and underline? No problem. Font size might be harder - I imagine it would be tricky to get BlueCloth to emit something like the (deprecated) < font > tag they use in the Prawn example...
大胆并强调?没问题。字体大小可能更难 - 我想让BlueCloth发出类似他们在Prawn示例中使用的(不赞成的)标签会很棘手......
Hope this helps - cheers!
希望这会有所帮助 - 干杯!
#2
1
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
end
respond_to do | format | format.pdf {render:layout => false} prawnto:filename => @current_project +“。pdf”,:prawn => {:font =>'Times-Roman'},:inline => false end
Then in pdf.prawn file you can use:
然后在pdf.prawn文件中你可以使用:
in a text box:
在文本框中:
pdf.text_box "Document Revisions", :size => 16, :style => :bold, :at => [0.mm,10.mm], :width => 100.mm, :height => 15.mm;
pdf.text_box“文档修订版”,: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;
pdf.text“文档内容”,:size => 16,:style =>:bold;
As I understand it - but not tried it - to underline you need to do:
据我了解 - 但没试过 - 强调你需要这样做:
:styles => [:bold, :underline];
:styles => [:bold,:underline];
反驳此链接以获取更多信息
This is not a feature of version 0.8.4 but version 0.10.2 - not sure how you would do underline in 0.8.4. I am not currently using 0.10.2 so can not confirm that this is works.
这不是0.8.4版本的功能,但是版本0.10.2 - 不确定如何在0.8.4中进行下划线。我目前没有使用0.10.2因此无法确认这是否有效。
Based on what you have said I think this is what you want to for bold:
根据你所说的,我认为这是你想要大胆的:
pdf.text_box "#{@yourtext.text}", :size => 16, :style => :bold, :at => [0.mm,10.mm], :width => 100.mm, :height => 15.mm;
pdf.text_box“#{@yourtext.text}”,:size => 16,:style =>:bold,:at => [0.mm,10.mm],:width => 100.mm,:height => 15.mm;
#1
8
we may have similar apps...
我们可能有类似的应用...
Prawn can do basic inline formatting based on (simple) HTML - take a look at the text/inline_format.rb example on github. In fact, take a look at the whole Prawn Example Gallery if you haven't - it's one of the best I've seen.
Prawn可以基于(简单)HTML进行基本的内联格式化 - 看一下github上的text / inline_format.rb示例。事实上,看看整个Prawn示例库,如果你还没有 - 这是我见过的最好的之一。
To get the HTML you need you can either type HTML straight into the textarea (a bit ugly - might not be a good idea if anyone besides you will be entering text) or use something like Markdown to interpret more user-friendly "style codes" like * does. I think BlueCloth is the best-known ruby implementation, but I've never used it myself.
要获得所需的HTML,您可以直接在textarea中输入HTML(有点难看 - 如果除了你之外的任何人都会输入文本可能不是一个好主意)或使用像Markdown这样的东西来解释更加用户友好的“样式代码”像*那样。我认为BlueCloth是最着名的ruby实现,但我自己从未使用它。
Bold and underline? No problem. Font size might be harder - I imagine it would be tricky to get BlueCloth to emit something like the (deprecated) < font > tag they use in the Prawn example...
大胆并强调?没问题。字体大小可能更难 - 我想让BlueCloth发出类似他们在Prawn示例中使用的(不赞成的)标签会很棘手......
Hope this helps - cheers!
希望这会有所帮助 - 干杯!
#2
1
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
end
respond_to do | format | format.pdf {render:layout => false} prawnto:filename => @current_project +“。pdf”,:prawn => {:font =>'Times-Roman'},:inline => false end
Then in pdf.prawn file you can use:
然后在pdf.prawn文件中你可以使用:
in a text box:
在文本框中:
pdf.text_box "Document Revisions", :size => 16, :style => :bold, :at => [0.mm,10.mm], :width => 100.mm, :height => 15.mm;
pdf.text_box“文档修订版”,: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;
pdf.text“文档内容”,:size => 16,:style =>:bold;
As I understand it - but not tried it - to underline you need to do:
据我了解 - 但没试过 - 强调你需要这样做:
:styles => [:bold, :underline];
:styles => [:bold,:underline];
反驳此链接以获取更多信息
This is not a feature of version 0.8.4 but version 0.10.2 - not sure how you would do underline in 0.8.4. I am not currently using 0.10.2 so can not confirm that this is works.
这不是0.8.4版本的功能,但是版本0.10.2 - 不确定如何在0.8.4中进行下划线。我目前没有使用0.10.2因此无法确认这是否有效。
Based on what you have said I think this is what you want to for bold:
根据你所说的,我认为这是你想要大胆的:
pdf.text_box "#{@yourtext.text}", :size => 16, :style => :bold, :at => [0.mm,10.mm], :width => 100.mm, :height => 15.mm;
pdf.text_box“#{@yourtext.text}”,:size => 16,:style =>:bold,:at => [0.mm,10.mm],:width => 100.mm,:height => 15.mm;