Prawn - 在text_box展开后向下移动光标

时间:2017-10-04 00:13:46

标签: ruby-on-rails ruby pdf ruby-on-rails-5 prawn

我正在使用Prawn Gem生成PDF,我无法找到一种方法在cursor从溢出文本扩展后移动text_box,类似于常规{{1调用会。

Text_box示例

text

因此,我必须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 } padmove_down,以便正确格式化下一组text_box而不重叠。如果我在text_box payable字符串上使用直接text调用,那么在按照预期呈现所有文本后,光标会向下移动。

我使用payable而不是常规text_box的原因是我可以将文字并排放在同一行上。虽然这适用于所有适合单行的字符串,但如果其中一个区域向下扩展text,它似乎不会很好,因为光标只是从下一个文本行而不是下面的文本行开始expand text_box。

任何见解或建议都将不胜感激,谢谢!

1 个答案:

答案 0 :(得分:3)

你现在可能已经找到了一些东西,但我也是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