Rails & prawnpdf: замена строк новым абзацем
У меня есть PDF, созданный с помощью Prawn, с HTML-кодом. Для каждого <br>
или пара <br>
s Я хочу вставить новый абзац с креветками 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"
Любая помощь будет принята с благодарностью. Немного застрял здесь.
2 ответа
Решение
Вы можете разбить текст на массив:
> 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}
Вы также можете просто добавить :inline_format => true
к элементу в документе PDF:
text "#{@text_area}", {
:inline_format => true
}
Это автоматически позволяет <br>
теги и другие теги форматирования HTML