【问题标题】:text flows to next page overlap with header in prawn文本流到下一页与虾中的标题重叠
【发布时间】:2017-10-27 08:59:24
【问题描述】:

我正在使用 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 如何避免与标题重叠,如果使用 bounding_box ?

【问题讨论】:

    标签: ruby-on-rails pdf prawn


    【解决方案1】:

    尝试将您的标头放入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
    

    【讨论】:

      【解决方案2】:

      我遇到了和你一样的问题,我想出了一个很好的解决方法,你可以在第一次实例化 Prawn 时更改页面上边距,并将 at: 选项添加到你的 image 上,这样它就可以位于pdf页面的顶部。

      即如果当前页边距为 [35,35,35,35] 并且您的图像高度为 20,那么您可以将顶部页边距设置为 55。如果当前页面高度为 722,则将 at: 选项设置为:

      def instantiate
        super(margin: [55, 35, 35, 35])
        repeat(:all) do
          image "#{Rails.root}/app/assets/images/logo-of-
          nextcode.png", height: 20, at: [0, 722]
        end
      end
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-11-05
        • 2011-10-08
        • 2017-03-01
        • 2015-10-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多