Prawnto displays tables that don't break when a new page

I have a variable number of tables with a variable number of rows, and I want them to be displayed one after another, but if the table does not fit on the current page, put it on the next one, and then continue. I put the table in a transaction so that I can go back and then print it if the height matches the current page, but how do I get the height of the table?

I have this code at the moment

pdf.transaction do 

pdf.table @data,
    :font_size  => 12, 
    :border_style => :grid,
    :horizontal_padding => 10,
    :vertical_padding   => 3,
    :border_width       => 2,
    :position           => :left,
    :row_colors => ["FFFFFF","DDDDDD"]

pdf.move_down 20

#pdf.rollback 
end

Any help on this would be great. Or any other way to do this?

Regards Rick

+5
source share
4

@current_page = pdf.page_count

@roll = pdf.transaction do 
  pdf.move_down 20

  pdf.table @data,
    :font_size  => 12, 
    :border_style => :grid,
    :horizontal_padding => 10,
    :vertical_padding   => 3,
    :border_width       => 2,
    :position           => :left,
    :row_colors => ["FFFFFF","DDDDDD"]

  pdf.rollback if pdf.page_count > @current_page

end 

if @roll == false

  pdf.start_new_page

  pdf.table @data,
    :font_size  => 12, 
    :border_style => :grid,
    :horizontal_padding => 10,
    :vertical_padding   => 3,
    :border_width       => 2,
    :position           => :left,
    :row_colors => ["FFFFFF","DDDDDD"]
end

, , : -)

+5

4 ...:)

@m-x, , "", . , :

( )

pdf.table @data,
  header: true, # You can use 'header: 2' if your header take two rows
  font_size: 12, 
  border_style: :grid,
  horizontal_padding: 10,
  vertical_padding: 3,
  border_width: 2,
  position: :left,
  row_colors: ["FFFFFF","DDDDDD"]

  • ,

:

t = pdf.make_table @data,
  font_size: 12, 
  border_style: :grid,
  horizontal_padding: 10,
  vertical_padding: 3,
  border_width: 2,
  position: :left,
  row_colors: ["FFFFFF","DDDDDD"]

if cursor - t.height < 0
  start_new_page
end

t.draw

,

+4

, , .

, , @data, , Prawn::Document.cursor.

, , . , ( Prawn::Document.start_new_page).

.

0

, new_page. chek, var > var, . . .

pdf.start_new_page , pdf.rollback, . . .

- , !

Rick

@current_page = pdf.page_count

pdf.transaction do 
  pdf.move_down 20

  pdf.table @data,
    :font_size  => 12, 
    :border_style => :grid,
    :horizontal_padding => 10,
    :vertical_padding   => 3,
    :border_width       => 2,
    :position           => :left,
    :row_colors => ["FFFFFF","DDDDDD"]

  @the_next_page = pdf.page_count
  pdf.rollback

end 

if @the_next_page > @current_page

  pdf.start_new_page

  pdf.table @data,
    :font_size  => 12, 
    :border_style => :grid,
    :horizontal_padding => 10,
    :vertical_padding   => 3,
    :border_width       => 2,
    :position           => :left,
    :row_colors => ["FFFFFF","DDDDDD"]
end 

> You have a nil object when you didn't expect it!
The error occurred while evaluating nil.identifier

Extracted source (around line #158): 

155: end



RAILS_ROOT: C:/InstantRails/rails_apps/Macrotec-Application

Application Trace | Framework Trace | Full Trace 
c:/InstantRails/ruby/lib/ruby/gems/1.8/gems/prawn-core-0.7.1/lib/prawn/document.rb:302:in `go_to_page'
c:/InstantRails/ruby/lib/ruby/gems/1.8/gems/prawn-core-0.7.1/lib/prawn/document/internals.rb:128:in `finalize_all_page_contents'
c:/InstantRails/ruby/lib/ruby/gems/1.8/gems/prawn-core-0.7.1/lib/prawn/document/internals.rb:127:in `each'
c:/InstantRails/ruby/lib/ruby/gems/1.8/gems/prawn-core-0.7.1/lib/prawn/document/internals.rb:127:in `finalize_all_page_contents'
c:/InstantRails/ruby/lib/ruby/gems/1.8/gems/prawn-core-0.7.1/lib/prawn/document.rb:344:in `render'
C:/InstantRails/rails_apps/Macrotec-Application/app/views/quotations/show.pdf.prawn:158:in `_run_prawn_app47views47quotations47show46pdf46prawn'
0

All Articles