我有一个通过Prawn生成的PDF,其中包含HTML代码。对于每个<br>
或<br>
对,我想用Prawn的text
方法插入一个新段落。鉴于此字符串:
sharemarket is a minnow by world standards, at just 2.5 per cent of the global sharemarket value. <br><br>One approach for local investors might be via an international share fund, with the fund manager
我想在<br><br>
结束当前这样的段落:
pdf.text "sharemarket is a minnow by world standards, at just 2.5 per cent of the global sharemarket value."
然后从这一点开始新的text
:
pdf.text "One approach for local investors might be via an international share fund, with the fund manager"
非常感谢任何帮助。有点困在这里。
答案 0 :(得分:1)
您可以将文本拆分为数组:
> str = 'sharemarket is a minnow by world standards, at just 2.5 per cent of the global sharemarket value. <br><br>One approach for local investors might be via an international share fund, with the fund manager'
=> "sharemarket is a minnow by world standards, at just 2.5 per cent of the global sharemarket value. <br><br>One approach for local investors might be via an international share fund, with the fund manager"
> rows = str.split('<br><br>')
=> ["sharemarket is a minnow by world standards, at just 2.5 per cent of the global sharemarket value. ", "One approach for local investors might be via an international share fund, with the fund manager"]
然后,将其写入pdf:
rows.each {|row| pdf.text row}
答案 1 :(得分:0)
您也可以将:inline_format => true
添加到PDF文档中的元素:
text "#{@text_area}", {
:inline_format => true
}
这会自动允许<br>
标记和其他HTML格式标记