Forum Bugs

Div boundaries are not correctly calculated when page size is defined in mm/cm

genn843
Hello,
I am using Prince to generate PDF from HTML with a 10-column css grid system with floated divs.
I noticed that changing to some page sizes breaks the grid system.
I was able to narrow down the problem to the units used when defining the page size.

E.g.
With this the grid system renders fine:
@page {
            size: 8.27in 11.69in;
            margin: 10pt
        }


But with this definition the boundaries are not calculated correctly and the grid is broken:
@page {
            size: 210mm 297mm;
            margin: 10pt
        }


Note that these are the dimensions of the A4 paper size only in different units.

I have attached a test HTML file, which can be used to reproduce the problem + the outputs using the mentioned definitions.

Anyway thanks for the great product - I am still evaluating the free version, but will definitely buy a license.
:)
  1. TEMP.html3.3 kB
  2. o_inch.pdf2.0 kB
  3. o_mm.pdf2.0 kB
mikeday
Right, it looks like an issue with floating point round-off. Internally Prince will convert all units to points, but since floating point arithmetic is not exact, it is possible for 30%+30%+30%+10% to sum to slightly less or slightly more than the original 100% width. In this case it sums to slightly more, just a tiny bit. Changing 10% to 9.99% and 40% to 39.99% is enough to fix the issue.

Perhaps in the future we could clamp widths to the nearest point, or half a point, and round down, which would reduce the chance of this slight overflow, at the cost of introducing small gaps in some circumstances. It's a tricky issue to solve in every case.