bounding box - overflow to next page issue

851 views
Skip to first unread message

Chris M

unread,
Sep 9, 2009, 9:46:05 AM9/9/09
to Prawn
Hello,

I appreciate all that is being done with Prawn, definitely the best
tool for manipulating PDFs in Ruby by far. Unfortunately, I have run
into a problem with a bounding_box overflowing to the next page.

You can find a simplified example at (inlined at the bottom of this
message also): http://pastie.org/610979

If you run the example, after the first page, all successive pages
just have a line or two, and those lines are aligned towards the
bottom of the page. Are there any best practices on what I am doing
wrong, or does this look like a bug (I've looked through all the doc's
and postings I can find)?

Environment: Vista, ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-
mswin32], prawn 0.5.0.1

Appreciate any and all help,
Thanks,
-Chris

Inlined Code Sample
-------------------------------------------------
# encoding: utf-8
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..',
'lib'))
require 'prawn/core'
Prawn::Document.generate("problem.pdf") do
font 'Helvetica'
text 'Basic Time Card version # 1'
text 'Submitted by Chris (Test) at 09/08/2009 21:47 UTC'
stroke{line([0,cursor], [540,cursor])}
move_down 6
move_down 3
text 'HEADING'
stroke{line([0,cursor], [540-(1-1*15)+(1*-16),cursor])}
move_down 6
bounding_box [(1*15),cursor], :width => (540-(1*15)) do
text 'Chris'
text '23432'
text '09/08/09'
end
stroke{line([0,cursor], [540-(1-1*15)+(1*-16),cursor])}
move_down 3
move_down 3
text 'DATE LIST'
stroke{line([0,cursor], [540-(1-1*15)+(1*-16),cursor])}
move_down 6
bounding_box [(1*15),cursor], :width => (540-(1*15)) do
text '09/08/09'
move_down 3
text 'TIME LIST'
stroke{line([0,cursor], [540-(2-1*15)+(2*-16),cursor])}
move_down 6
bounding_box [(2*15),cursor], :width => (540-(2*15)) do
text '17:46'
move_down 3
text 'TIME LIST DETAIL'
stroke{line([0,cursor], [540-(3-1*15)+(3*-16),cursor])}
move_down 6
bounding_box [(3*15),cursor], :width => (540-(3*15)) do
text 'fda'
text 'fdsafda'
text '0.00'
text '0.00'
text '6.55'
end
stroke{line([0,cursor], [540-(3-1*15)+(3*-16),cursor])}
move_down 3
move_down 5
text '18:46'
move_down 3
text 'TIME LIST DETAIL'
stroke{line([0,cursor], [540-(3-1*15)+(3*-16),cursor])}
move_down 6
bounding_box [(3*15),cursor], :width => (540-(3*15)) do
text 'fdafdfda'
text 'afdasfdas'
text '0.00'
text '0.00'
text '6.55'
end
stroke{line([0,cursor], [540-(3-1*15)+(3*-16),cursor])}
move_down 3
move_down 5
text '20:46'
move_down 3
text 'TIME LIST DETAIL'
stroke{line([0,cursor], [540-(3-1*15)+(3*-16),cursor])}
move_down 6
bounding_box [(3*15),cursor], :width => (540-(3*15)) do
text 'adfas'
text 'fdasfdas'
text '0.00'
text '0.00'
text '6.55'
end
stroke{line([0,cursor], [540-(3-1*15)+(3*-16),cursor])}
move_down 3
move_down 5
text '23:46'
move_down 3
text 'TIME LIST DETAIL'
stroke{line([0,cursor], [540-(3-1*15)+(3*-16),cursor])}
move_down 6
bounding_box [(3*15),cursor], :width => (540-(3*15)) do
text 'fdafdas'
text 'fdasfdas'
text '0.00'
text '0.00'
text '6.55'
end
stroke{line([0,cursor], [540-(3-1*15)+(3*-16),cursor])}
move_down 3
move_down 5
end
stroke{line([0,cursor], [540-(2-1*15)+(2*-16),cursor])}
move_down 3
move_down 5
text '09/09/09'
move_down 3
text 'TIME LIST'
stroke{line([0,cursor], [540-(2-1*15)+(2*-16),cursor])}
move_down 6
bounding_box [(2*15),cursor], :width => (540-(2*15)) do
text '17:46'
move_down 3
text 'TIME LIST DETAIL'
stroke{line([0,cursor], [540-(3-1*15)+(3*-16),cursor])}
move_down 6
bounding_box [(3*15),cursor], :width => (540-(3*15)) do
text 'fdafda'
text 'dafdas'
text '0.00'
text '0.00'
text '6.55'
end
stroke{line([0,cursor], [540-(3-1*15)+(3*-16),cursor])}
move_down 3
move_down 5
text '19:46'
move_down 3
text 'TIME LIST DETAIL'
stroke{line([0,cursor], [540-(3-1*15)+(3*-16),cursor])}
move_down 6
bounding_box [(3*15),cursor], :width => (540-(3*15)) do
text 'fdafd'
text 'dafdas'
text '0.00'
text '0.00'
text '6.55'
end
stroke{line([0,cursor], [540-(3-1*15)+(3*-16),cursor])}
move_down 3
move_down 5
end
stroke{line([0,cursor], [540-(2-1*15)+(2*-16),cursor])}
move_down 3
move_down 5
end
stroke{line([0,cursor], [540-(1-1*15)+(1*-16),cursor])}
move_down 3
move_down 3
text 'SUMMARY'
stroke{line([0,cursor], [540-(1-1*15)+(1*-16),cursor])}
move_down 6
bounding_box [(1*15),cursor], :width => (540-(1*15)) do
text '5'
text '6'
text '7'
text ''
end
stroke{line([0,cursor], [540-(1-1*15)+(1*-16),cursor])}
move_down 3
move_down 3
text 'SIGNATURE'
stroke{line([0,cursor], [540-(1-1*15)+(1*-16),cursor])}
move_down 6
bounding_box [(1*15),cursor], :width => (540-(1*15)) do
text ''
end
stroke{line([0,cursor], [540-(1-1*15)+(1*-16),cursor])}
move_down 3
text ' '
end
------------------------------

Gregory Brown

unread,
Sep 9, 2009, 9:51:44 AM9/9/09
to prawn...@googlegroups.com
On Wed, Sep 9, 2009 at 9:46 AM, Chris M <cmorr...@gmail.com> wrote:
>
> Hello,
>
>  I appreciate all that is being done with Prawn, definitely the best
> tool for manipulating PDFs in Ruby by far.  Unfortunately, I have run
> into a problem with a bounding_box overflowing to the next page.
>
> You can find a simplified example at (inlined at the bottom of this
> message also): http://pastie.org/610979

This is not a simplified example. Reproduce the issue using only the
lines of code necessary to do so.

-greg

Chris Morrisette

unread,
Sep 9, 2009, 10:04:09 AM9/9/09
to prawn...@googlegroups.com
Apologize, here is a more simplified example.

http://pastie.org/611003

Thanks again for your time,

-------------

# encoding: utf-8
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
require 'prawn/core'
Prawn::Document.generate("problem.pdf") do
  20.times {text '1'}

  bounding_box [(1*15),cursor], :width => (540-(1*15)) do
    20.times {text '2'}
  end

  bounding_box [(1*15),cursor], :width => (540-(1*15)) do
    20.times {text '3'}

    bounding_box [(2*15),cursor], :width => (540-(2*15)) do
      20.times {text '4'}
    end
  end
end                
------------

Gregory Brown

unread,
Sep 9, 2009, 10:14:54 AM9/9/09
to prawn...@googlegroups.com
On Wed, Sep 9, 2009 at 10:04 AM, Chris Morrisette <cmorr...@gmail.com> wrote:
> Apologize, here is a more simplified example.
>
> http://pastie.org/611003

This is the documented behavior.

From Document#bounding_box at:
http://prawn.majesticseacreature.com/docs/prawn-core/

"When flowing text, the usage of a bounding box is simple. Text will
begin at the point specified, flowing the width of the bounding box.
After the block exits, the cursor position will be moved to the bottom
of the bounding box (y - height). If flowing text exceeds the height
of the bounding box, the text will be continued on the next page,
starting again at the top-left corner of the bounding box. "

Perhaps you want span() instead?

Chris Morrisette

unread,
Sep 9, 2009, 10:30:50 AM9/9/09
to prawn...@googlegroups.com
Ahh. I took, the documentation to mean
"...the text will be continued on the next page,starting again at the top-left corner of the bounding box (which if its a new page will be the top of the page - since the bounding box flowed to the new page, its coordinates were reset to the top)."

Regardless, makes sense now, and in the sample I gave was able to replace with a span and have everything work as expected.  Attached the updated code snippet.

Thanks again for the quick help,
-Chris

Updated code showing expected results
-----------------------------------------------------------------------

# encoding: utf-8
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
require 'prawn/core'
Prawn::Document.generate("problem.pdf") do
  20.times {text '1'}
  span (540-(1*15)), :position =>(1*15) do
    20.times {text '2'}
  end
  span (540-(1*15)), :position =>(1*15) do
    20.times {text '3'}
    span (540-(2*15)), :position =>(2*15) do

      20.times {text '4'}
    end
  end
end           
------------------------------------------------------------
Reply all
Reply to author
Forward
0 new messages