Closed reiz closed 3 months ago
@gettalong I just found a solution for this problem. It seems that height: 1
and border: {width: [1, 0, 0]}
do not work together. Or at least not with this values. If I remove border: {width: [1, 0, 0]}
from the styles then it works. I updated the style like this:
c.style(:top_line_line, margin: [2, 0, 10], background_color: "black" )
c.box(:base, height: 1, style: :top_line_line)
and now it works.
But the error message Box doesn't fit on empty page
is somehow misleading.
The height
attribute defines the height of the box and this includes the border and padding but not the margin. So when you say height: 1
and border: {width: [1, 0, 0]}
, there is no room for the content anymore because the content_height
of the box would be 0. Therefore this box never fits. First it doesn't fit after the formatted text. Then HexaPDF tries to fit that box on an empty page and that doesn't work either. Since it doesn't make sense to do another try at this point, the error is raised.
The error message is indeed somewhat misleading, maybe it would be better to use "Box didn't fit multiple times, even on an empty page".
Circling back to the original reason for the error: Since other boxes happily work with a content height of zero, I think the base box should also work this way. I will change that for the next release.
Thx for the explanation. Makes sense now.
I'm using this in my Gemfile:
With
ruby 3.1.6p260 (2024-05-29 revision a777087be6) [arm64-darwin22]
. My class looks like this:When I run the code, I'm getting this error:
Box doesn't fit on empty page (HexaPDF::Error)
. Any idea?