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

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

我正在使用 Prawn Gem 生成 PDF,但我无法找到在 text_box 从溢出文本展开后向下移动 cursor 的方法,类似于常规文本调用的方式。

文本框示例

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 payablepadmove_down 才能正确设置下一组 text_box 的格式,而无需重叠。如果我对 payable 字符串使用直接 text 调用,则在所有文本呈现后,光标将按预期向下移动。

我使用 text_box 而不是常规 text 的原因是这样我可以将文本并排放置在同一行上。虽然这对于所有适合单行的字符串非常有效,但如果其中一个区域向下扩展 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

关于ruby-on-rails - Prawn - 在text_box展开后向下移动光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46555227/

相关文章:

ruby-on-rails - Rails Presenter block 方法

ruby-on-rails - 人类可读的 URL 会导致 Ruby on Rails 出现问题

ruby-on-rails - Rails ActionMailer 不会从控制台发送

ruby-on-rails - jQuery 发布到 Rails

ruby-on-rails - Rails - 在 Devise 中禁用 "already_authenticated"重定向

iphone - CGPDFDictionary引用一些有用的东西

php - DOMPDF 无法呈现字体,而是显示圆圈

mysql - 预加载带条件的嵌套资源

ruby-on-rails - 如何让我的数据库查询更有效率?

javascript - 从页面上的链接获取ID