ruby – 当使用repeat(:all)时,Prawn似乎没有推动布局
发布时间:2020-12-17 02:21:00 所属栏目:百科 来源:网络整理
导读:我正在生成一个文档,其中包含流入每个后续页面的数据,每个页面都有一个标准标题.但是,当我使用repeat(:all)将标题放在每个页面上时,我发现除了第一页之外的每个页面上,下一个内容都没有按照我放在页面上的标题横幅的大小向下移动. 我生成横幅的代码: class
我正在生成一个文档,其中包含流入每个后续页面的数据,每个页面都有一个标准标题.但是,当我使用repeat(:all)将标题放在每个页面上时,我发现除了第一页之外的每个页面上,下一个内容都没有按照我放在页面上的标题横幅的大小向下移动.
我生成横幅的代码: class SmartsoftPdf < Prawn::Document BOX_MARGIN = 30 RHYTHM = 10 INNER_MARGIN = 30 # Colors # BLACK = "000000" LIGHT_GRAY = "F2F2F2" GRAY = "DDDDDD" DARK_GRAY = "333333" BROWN = "A4441C" ORANGE = "F28157" LIGHT_GOLD = "FBFBBE" DARK_GOLD = "EBE389" BLUE = "08C" GREEN = "00ff00" RED = "ff0000" def show_header(text,date) header_box do image "#{Rails.root}/app/assets/images/smart_records_logo_h60.png",:height => 40 draw_text text,:at => [80,25],:size => 12,:style => :bold,:color => BLUE draw_text "Date: #{ausDate(date)}",:at => [bounds.right - 100,bounds.top - 15],:size => 10 if date end end def header_box(&block) bounding_box([-bounds.absolute_left,cursor + BOX_MARGIN + 8],:width => bounds.absolute_left + bounds.absolute_right,:height => BOX_MARGIN*2) do fill_color LIGHT_GRAY fill_rectangle([bounds.left,bounds.top],bounds.right,bounds.top - bounds.bottom) fill_color BLACK move_down(RHYTHM) indent(BOX_MARGIN,&block) end stroke_color GRAY stroke_horizontal_line(-BOX_MARGIN,bounds.width + BOX_MARGIN,:at => cursor) stroke_color BLACK move_down(RHYTHM*4) end end 然后在pdf生成本身内我做: repeat(:all) do show_header("Custom Report",DateTime.now()) end 但是,当我开始将内容放到页面上时,我预计当内容溢出到下一页时,内容将显示在标题之后.我发现标题重叠了内容. 这是一个说明问题的图像:http://i.imgur.com/mSy2but.png 我是否错误地构建了标题框?我是否需要做一些额外的事情来使其溢出到下一页的内容被推下适当的数量? 解决方法
好的.我自己解决了这个问题.最新版本的Prawn有更好的方法来处理这种情况.当您使用repeat(:all)时,在创建文档后重新打开页面,然后添加内容创建项.这不会推翻页面.将此标头添加到每个页面的正确方法是使用“canvas”方法,该方法允许您在页边距的范围之外操作.使用画布在页面顶部绘制一个框,并设置页面的top_margin以推送横幅下方的所有内容.
canvas do bounding_box([bounds.left,:height => BOX_MARGIN*2) do fill_color LIGHT_GRAY fill_rectangle([bounds.left,bounds.top - bounds.bottom) fill_color BLACK move_down(RHYTHM) indent(BOX_MARGIN,&block) end stroke_color GRAY stroke_horizontal_line(-BOX_MARGIN,:at => cursor) stroke_color BLACK end 在文档创建… def initialize(options = {}) super(:page_layout => :landscape,:top_margin => HEIGHT_OF_BANNER) end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |