开发者

Rails PDF Prawn Data Generation from controller

开发者 https://www.devze.com 2023-01-11 15:39 出处:网络
I have a file named report.pdf.prawn, which is the view part of my PDF file where we can edit the contents of the PDF file like >>>

I have a file named report.pdf.prawn,

which is the view part of my PDF file where we can edit the contents of the PDF file like >>>

*pdf=Prawn::Document.new(:page_layout =>:landscape,:page_size => 'A4')
pdf.text"Hello"
head=@headers
headers=[""],[""]
pdf.table headers,
:width => 768,
:size => 11,
:border_style => :underline_header,
:headers => [head.titleize],
:header_color => 'b7e3fe',
:padding=>5*

<<< etc ect...

The above just prints like

Hello
Header1header2header3

I have two values from my controller >>> def report <<< as

@header and @data

  • @header gives values like Header1Header2Header3
  • @data gives values like data11data12data13data21data22data23

How do i print the values like the format given below on all PDF pages being generated?

Header1     Header2    Header3

data11  开发者_JAVA百科    data12     data13

data21      data22     data23

data31      data32     data33

data41      data42     data33


cs = [ ]
    @sql_query.each do |column|
         data=[]


         if @headers.include?('data1x')
         column.number
         data << column.number
         end

             if @headers.include?('data2x')
         column.number
         data << column.number
         end

cs << data

end

pdf.table cs,

:width => 768,

:size => 11,

:border_style => :underline_header,

:headers => @header,

:header_color => 'b7e3fe',

:column_widths=>{0=>55,1=>100,2=>70,3=>77,4=>88,5=>90,6=>75,7=>75,8=>75,9=>65,10=>55,11=>55},
:padding=>5
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号