大虾-在text_box展开后将光标向下移动 [英] Prawn - Move cursor down after text_box expand
问题描述
我正在使用Prawn Gem生成PDF,并且在text_box
从溢出文本扩展后无法找到将cursor
向下移动的方法,这与常规text
调用的方式类似. /p>
文本框示例
pad(5) {
text_box payable, :at => [bounds.left, cursor], :width => 540, :height => 15, :overflow => :expand, inline_format: true
}
move_down(15)
pad(5) {
text_box address, :at => [bounds.left, cursor], :width => 250, :height => 15, :overflow => :expand, inline_format: true
text_box city, :at => [250, cursor], :width => 100, :height => 15, :overflow => :expand, inline_format: true
text_box state, :at => [350, cursor], :width => 75, :height => 15, :overflow => :expand, inline_format: true
text_box zip, :at => [425, cursor], :width => 110, :height => 15, :overflow => :expand, inline_format: true
}
因此,在上面,我必须从text_box payable
开始pad
和move_down
,以便正确设置下一组text_box的格式而不会重叠.如果我在payable
字符串上直接使用text
调用,则在所有文本呈现之后,光标将按预期方式向下移动.
我在常规text
上使用text_box
的原因是,我可以在同一行上并排放置文本.虽然这对于所有都适合一行的字符串非常有用,但是如果其中一个区域向下扩展text_box
,则似乎不能很好地发挥作用,因为光标只是从下一个文本行开始,而不是在扩展的text_box下方
任何见解或建议将不胜感激,谢谢!
到目前为止,您可能已经发现了一些问题,但是我对Prawn还是陌生的,并且有相同的问题,希望对其他人有所帮助.本示例同时显示了一个文本框和一个格式化的文本框.也许有某种更好的方法,但这对我有用.
txt1 = "u" * 250
txt2 = "v" * 600
txt3 = "w" * 100
txt4 = "x" * 500
txt5 = "y" * 200
txt6 = "z" * 400
stroke_horizontal_rule
options = {:document=>@pdf, :at=>[0,cursor]}
text_box(txt1, options)
measure = Prawn::Text::Box.new(txt1, options)
measure.render(:dry_run => true)
move_down(measure.height)
options = {:document=>@pdf, :at=>[0,cursor]}
text_box(txt2, options)
measure = Prawn::Text::Box.new(txt2, options)
measure.render(:dry_run => true)
move_down(measure.height)
options = {:document=>@pdf, :at=>[0,cursor]}
text_box(txt3, options)
measure = Prawn::Text::Box.new(txt3, options)
measure.render(:dry_run => true)
move_down(measure.height)
array = [{:text=>txt4, :size=>12}]
options = {:document=>@pdf, :at=>[0,cursor]}
formatted_text_box(array, options)
measure = Prawn::Text::Formatted::Box.new(array, options)
measure.render(:dry_run => true)
move_down(measure.height)
array = [{:text=>txt5, :size=>16}]
options = {:document=>@pdf, :at=>[0,cursor]}
formatted_text_box(array, options)
measure = Prawn::Text::Formatted::Box.new(array, options)
measure.render(:dry_run => true)
move_down(measure.height)
array = [{:text=>txt6, :size=>12}]
options = {:document=>@pdf, :at=>[0,cursor]}
formatted_text_box(array, options)
measure = Prawn::Text::Formatted::Box.new(array, options)
measure.render(:dry_run => true)
move_down(measure.height)
stroke_horizontal_rule
I'm generating PDF's using the Prawn Gem and I'm unable to find a way to move the cursor
down after text_box
expands from overflow text, similar to the way a regular text
call would.
Text_box example
pad(5) {
text_box payable, :at => [bounds.left, cursor], :width => 540, :height => 15, :overflow => :expand, inline_format: true
}
move_down(15)
pad(5) {
text_box address, :at => [bounds.left, cursor], :width => 250, :height => 15, :overflow => :expand, inline_format: true
text_box city, :at => [250, cursor], :width => 100, :height => 15, :overflow => :expand, inline_format: true
text_box state, :at => [350, cursor], :width => 75, :height => 15, :overflow => :expand, inline_format: true
text_box zip, :at => [425, cursor], :width => 110, :height => 15, :overflow => :expand, inline_format: true
}
So above, I have to pad
and move_down
from the text_box payable
in order for the next set of text_boxes to be formatted correctly without overlapping. If I use a straight text
call on the payable
string then the cursor moves down after all of the text is rendered, as expected.
The reason I'm using text_box
over regular text
is so that I can position text side by side on the same line. While this works great for strings thats all fit on a single line, it doesn't seem to play out well if one of those areas expands the text_box
downwards because the cursor just starts at the next text line instead of below the expanded text_box.
Any insight or suggestions would be appreciated, thanks!
You've probably figured out something by now but I'm also new to Prawn and had the same question so hopefully this will help someone else. This example shows both a text box and a formatted text box. There is probably somehow a better way but this is working for me.
txt1 = "u" * 250
txt2 = "v" * 600
txt3 = "w" * 100
txt4 = "x" * 500
txt5 = "y" * 200
txt6 = "z" * 400
stroke_horizontal_rule
options = {:document=>@pdf, :at=>[0,cursor]}
text_box(txt1, options)
measure = Prawn::Text::Box.new(txt1, options)
measure.render(:dry_run => true)
move_down(measure.height)
options = {:document=>@pdf, :at=>[0,cursor]}
text_box(txt2, options)
measure = Prawn::Text::Box.new(txt2, options)
measure.render(:dry_run => true)
move_down(measure.height)
options = {:document=>@pdf, :at=>[0,cursor]}
text_box(txt3, options)
measure = Prawn::Text::Box.new(txt3, options)
measure.render(:dry_run => true)
move_down(measure.height)
array = [{:text=>txt4, :size=>12}]
options = {:document=>@pdf, :at=>[0,cursor]}
formatted_text_box(array, options)
measure = Prawn::Text::Formatted::Box.new(array, options)
measure.render(:dry_run => true)
move_down(measure.height)
array = [{:text=>txt5, :size=>16}]
options = {:document=>@pdf, :at=>[0,cursor]}
formatted_text_box(array, options)
measure = Prawn::Text::Formatted::Box.new(array, options)
measure.render(:dry_run => true)
move_down(measure.height)
array = [{:text=>txt6, :size=>12}]
options = {:document=>@pdf, :at=>[0,cursor]}
formatted_text_box(array, options)
measure = Prawn::Text::Formatted::Box.new(array, options)
measure.render(:dry_run => true)
move_down(measure.height)
stroke_horizontal_rule
这篇关于大虾-在text_box展开后将光标向下移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!