3
votes

I'm trying to generate a pdf using Prawn 0.12.0.

The content I am rendering is very dynamic and often spans over multiple pages.

The problem I'm having is that when it starts a new page automatically the current bounding box "breaks". The text that renders on the new page does not have the correct bounding box. If I use stroke_bounds I can see the bottom stroke at the very bottom of the page. I've read about this problem on various forums but can't seem to figure out what is actually happening.

Here is the specific code that loops out the content:

items.each do |item|
  group do
    title_text = [{ text: item.title, styles: [@heading_style], size: 11}]
    formatted_text title_text
    text(item.description, size: 9)
    stroke { line(bounds.bottom_left, bounds.bottom_right); }
  end
end

As you can se I want to draw a line just below every item and that is why I need the current bounding box to be correct.

1
Experiencing the same problem. Could you find something? - pdu
To anyone who finds this and notices the group method in your code: NotImplementedError: Document#group has been disabled because its implementation lead to corrupted documents whenever a page boundary was crossed. We will try to work on reimplementing it in a future release - iconoclast

1 Answers

2
votes

Per the prawn documentation at: http://prawnpdf.org/manual.pdf

A bounding box is bound to the page margins:

A bounding box is a structure which provides boundaries for inserting content. A bounding box
also has the property of relocating the origin to its relative bottom-left corner. However, be aware
that the location specified when creating a bounding box is its top-left corner, not bottom-left
(hence the [100, 300] coordinates below).

A span is a better choice for the type of boundary that will flow gracefully across pages:

Span is a different kind of bounding box as it lets the text flow
gracefully onto the next page. It doesn't matter if the text started
on the middle of the previous page, when it flows to the next page
it will start at the beginning. 

A span should be able to incorporate the desired line strokes. Hope this helps.