prawn-table question.

243 views
Skip to first unread message

Hiroyuki Sato

unread,
Jul 9, 2015, 9:49:06 AM7/9/15
to prawn...@googlegroups.com
Hello

I have a question about prawn-table (0.2.1)

* Is it possible to create new page automatically if content(one-table) does not fit single page?
* How do I know table height like dry_run in TextBox?

Please see detail.


Thank you for your advice.

--
Hiroyuki Sato.


rogerdpack

unread,
Jul 18, 2015, 2:33:30 PM7/18/15
to prawn...@googlegroups.com

Hiroyuki Sato

unread,
Jul 19, 2015, 3:54:53 AM7/19/15
to prawn...@googlegroups.com
Hello rogerdpack.

I can calculate like this 

table.row_heights.inject(0){ |sum,h| sum += h }

Thanks.


2015年7月19日日曜日 3時33分30秒 UTC+9 rogerdpack:

Aditya Gupta

unread,
Dec 2, 2015, 9:33:51 AM12/2/15
to Prawn
Hi Sato,

I have the same requirement and want to continue data of same row in next page it exceeded .
 how to put.

Please give example if possible.

Thanks,
Aditya 

Hiroyuki Sato

unread,
Dec 2, 2015, 11:18:12 PM12/2/15
to Prawn
Hello Aditya

This is example code. 

Please check this URL.

Please let me know if you need more detail.

table = Prawn::Table.new(data,@pdf,table_opts) do
...
end

if( fits_on_current_page?(table) == false )
  @pdf.start_new_page
end


UNDER_MARGIN = 5.mm + 10.mm
def fits_on_current_page?(table)
  h = table_height(table)
  #@pdf.y is current height position.
  @pdf.y - UNDER_MARGIN > h
end

# calculate table height.
def table_height(table)
  table.row_heights.inject(0){ |sum,h| sum += h }
end

Thanks
Hiroyuki Sato.



2015年12月2日水曜日 23時33分51秒 UTC+9 Aditya Gupta:

Aditya Gupta

unread,
Dec 3, 2015, 8:23:30 AM12/3/15
to Prawn
HI Hiroyuki,

Thanks to answer.

But i am quite new for rails programming.

I am using prawn-table gem to create table

file_location = file_path + "/" + file_name + ".pdf"

    pdf = Prawn::Document.new(:template => file_location, :skip_page_creation => true) do

    start_new_page(:template => file_path)

    end

#data is 2D array

    pdf.indent(10) do

      pdf.table(data, :header => true ) do

        rows(0..data.length).style(:border_width => 1, :align => :center).size=12
        row(0).style(:background_color => '01d4ab', :border_width => 1,:align => :center, :font_style => :bold, :text_color =>'000000')

        if change_config != nil

          change_config.each do |c|

            row(c).style(:background_color => 'FFFF00', :border_width => 1,:align => :center, :font_style => :bold)

          end

        end

      end

      pdf.number_pages "Page <page> of <total>", :at => [432, -4], :width => 100,  :text_color =>'00ff00'
      pdf.render_file  file_location

    end


I want to fit that code .please suggest.

Thanks,
Aditya 

Hiroyuki Sato

unread,
Dec 3, 2015, 9:33:39 PM12/3/15
to Prawn
Hello Aditya.

Could you tell me more detail what is the problem?

I modified your code. It seems work well.
https://gist.github.com/hiroyuki-sato/0618a351be44137b7f45

2015年12月3日木曜日 22時23分30秒 UTC+9 Aditya Gupta:

Aditya Gupta

unread,
Dec 4, 2015, 1:42:39 PM12/4/15
to Prawn
Very nice to modified the code as working. :)

I just gave you piece of code from my program.

Okay. well now what is my problem:

actually that data 2D array contains n number of row like and one of the row contains microsoft security patch id's (KB's).

Some time we have more than 500 kb ids in that one row . so, in my code when size exceed from A4 paper size it will skip rest data what not fit in one page.

I want to achieve like what left in a row should print in next page.

Hope now you can understand my problem.

Hiroyuki Sato

unread,
Dec 7, 2015, 6:17:57 AM12/7/15
to Prawn
Hello Aditya

I've never tried that data.

Have you ever tried table/basic_block.rb?


2015年12月5日土曜日 3時42分39秒 UTC+9 Aditya Gupta:
Reply all
Reply to author
Forward
0 new messages