ruby-on-rails - 文本流到下一页与 Prawn 的标题重叠

标签 ruby-on-rails pdf prawn

我正在使用 Prawn.rb 生成 pdf 并遇到一个问题:

我在每个页面上都有一个标题,当我使用 span 时,span 中的文本将会流动到下一页并与页眉重叠,但如果我使用 bounding_box,其中的文本将从 bounding_box 从文本流到下一页的时间开始。

这是我的标题:

repeat(:all) do
      transparent(0.5) do
        bounding_box [bounds.left, bounds.top], :width  => 
        bounds.width do
             image "#{Rails.root}/app/assets/images/logo-of-
             nextcode.png", height: 20
             move_down 2
             stroke_horizontal_rule
        end
        bounding_box [bounds.left, bounds.bottom + 50], :width  => bounds.width do
          text_box 'PRIVATE & CONFIDENTIAL', align: :center, valign: :bottom, size: 10
        end
      end

这是长文本:

span(bounds.width) do
      object.actions.each_with_index do |a, i|
      text "#{i + 1}. Description: #{a.message}"
      text_box "Expected Completion Date: #{a.expected_completion_time&.strftime('%F')}", at: [0, cursor]
      move_down 15
      text_box "Actual Completion Date: #{a.actual_completion_time&.strftime('%F')}", at: [0, cursor]
      move_down 20
      end
end

我的问题是:如果使用 span 如何避免与标题重叠以及如果使用 如何避免标题和文本之间的大空白行>边界框 ?

最佳答案

尝试将您的 header 放入canvas

    repeat(:all) do
       canvas do 
         transparent(0.5) do
         bounding_box [bounds.left, bounds.top], :width  => 
         bounds.width do
            image "#{Rails.root}/app/assets/images/logo-of-
            nextcode.png", height: 20
           move_down 2
           stroke_horizontal_rule
         end
         bounding_box [bounds.left, bounds.bottom + 50], :width  => bounds.width do
         text_box 'PRIVATE & CONFIDENTIAL', align: :center, valign: :bottom, size: 10
    end
  end
end

关于ruby-on-rails - 文本流到下一页与 Prawn 的标题重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46971220/

相关文章:

ruby-on-rails - 在 Rails 中呈现不同的格式/布局如何影响 SEO?

java - 仅针对 PDF 打印中的首页设置方向 - java

ruby - 准备用作 Prawn 模板的 PDF

pdf - FEFF0009 的/ActualText 在 PDF 中是什么意思?

ruby-on-rails - Prawn :PDF生成带进度条或spinner

ruby-on-rails - 使用 prawn 时显示未初始化的常量 Prawn::FLOAT_PRECISION 错误

javascript - Heroku 的配置操作电缆 - 错误 localhost :3000/cable

ruby-on-rails - 如何修复 Ruby 2.0.0p645 的段错误

javascript - Rails 应用程序中最简单的可见计时器

java - 更改 Flying Saucer 标题