加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 在Rails中使用Prawn gem如何将表格宽度设置为1

发布时间:2020-12-16 23:26:04 所属栏目:百科 来源:网络整理
导读:我使用Prawn gem生成pdf表.我需要将表的宽度设置为100%.我怎样才能做到这一点? 这是我的slmun_pdf.rb class SlmunPdf Prawn::Document def initialize(slmunDbs,view,allcount) if slmunDbs.table_name == "schools" super(top_margin: 50) if slmunDbs.si
我使用Prawn gem生成pdf表.我需要将表的宽度设置为100%.我怎样才能做到这一点?

这是我的slmun_pdf.rb

class SlmunPdf < Prawn::Document
  def initialize(slmunDbs,view,allcount)

    if slmunDbs.table_name == "schools"
      super(top_margin: 50)
      if slmunDbs.size != allcount
        @warn = " (Not all Schools)"
      else
        @all = " All #{slmunDbs.size} Schools"
      end
      text "Showing#{@all}",size: 18,style: :bold,align: :center,color: "636363"
      text "#{@warn}",size: 11,color: "858585"
      @schools = slmunDbs
      @view = view
      school_list

    end


  end

  def school_list
    move_down 20
    table school_list_rows,:cell_style => { :font => "Helvetica",:size => 9,:border_width => 0.5,:borders => [:top,:bottom],:border_color => "B0B0B0",:text_color => "737373"} do
        self.row(0).align = :center
        row(0).background_color = 'A0B046'      
        row(0).text_color = "FFFFFF"
        self.row_colors = ["DDDDDD","FFFFFF"]
        self.header = true
    end
  end

  def school_list_rows
    [["Name","Contact","Country","Pre Registration","Full Registration","Assigned Countries","Total Delegates"  ]] +
    @schools.map do |school|
      countries = ""
      len = school.countries.count
      school.countries.each_with_index do |country,index|
        countries << "#{country.country }"
         if index+1 != len
          countries << ","
         end
      end 
      [school.name,school.contact,school.country,@view.yesno(school.prereg),@view.yesno(school.fullreg),countries,school.delegates.size ]
    end
  end

end

现有的文件没有帮助.我可能会使用不同的方法?我是从rails cast中学到的!

解决方法

您可以使用 Prawn::Document::BoundingBox类的 width方法:
require 'prawn'
require 'prawn/table'

Prawn::Document.generate("hello.pdf") do
  table_content = [["This table"],["covers the"],["whole page width"]]
  table table_content,width: bounds.width
end

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读