Skip to content

Instantly share code, notes, and snippets.

@TylerRick
Created May 12, 2014 20:00
Show Gist options
  • Select an option

  • Save TylerRick/9819204441df2c8703b5 to your computer and use it in GitHub Desktop.

Select an option

Save TylerRick/9819204441df2c8703b5 to your computer and use it in GitHub Desktop.

Revisions

  1. TylerRick created this gist May 12, 2014.
    21 changes: 21 additions & 0 deletions table_bounds_width_bug.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    require "prawn"

    Prawn::Document.generate("#{__FILE__}.pdf") do |pdf|
    pdf.start_new_page margin: [100, 100, 100, 100]
    pdf.stroke_axis
    orig_bounds_width = pdf.bounds.width
    pdf.formatted_text_box [ { :text => "width: #{pdf.bounds.width}" } ], :at => [0, 20]

    pdf.indent(100) do
    pdf.stroke_axis
    pdf.formatted_text_box [ { :text => "width: #{pdf.bounds.width}" } ], :at => [0, 20]

    # Problem only occurs when table too big to fit on one page, and position: :center is used
    pdf.table([ ['Test'] ]*30, {position: :center})
    end

    pdf.start_new_page margin: [100, 100, 100, 100]
    pdf.stroke_axis
    # Observe: Width is 312.0, but should have been reset to 412.0
    pdf.formatted_text_box [ { :text => "width: #{pdf.bounds.width} (should still be #{orig_bounds_width})" } ], :at => [0, 20]
    end