0

我有一个通过 Prawn 生成的 PDF,其中包含 HTML 代码。对于每个<br>或一对<br>s,我想用 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"

任何帮助将不胜感激。有点卡在这里。

4

2 回答 2

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}
于 2013-09-16T05:26:07.720 回答
0

您也可以只添加:inline_format => true到 PDF 文档中的元素:

  text "#{@text_area}", {
    :inline_format => true
  }

这会自动允许<br>标签和其他 HTML 格式标签

于 2015-03-07T00:41:08.843 回答