In one of the documents I'm working with, there's a long stretch of pages containing nothing but tables. The tables are of variable length, and I'm using the box-tracking API to determine how much vertical whitespace is left after each set of tables, and evenly distribute it between them (i.e., so that the final table on each page is always flush with the bottom margin).
The code I'm using is as follows. This code assumes that jQuery is available, that there will always be exactly four tables per page, and that the total number of tables is known ahead of time (all of which happen to be true in this case, but adapting the code to cases where one or more of those things isn't true should be trivial):
This works well enough, but there's a hard-coded constant in there: the 56.13 representing the page's bottom margin. Ideally I'd like to be able to avoid that constant and use the box tracking API to fetch the bottom margin of whatever page each group of tables happens to be on, but I'm a bit stumped on how to reliably do that.
The code I'm using is as follows. This code assumes that jQuery is available, that there will always be exactly four tables per page, and that the total number of tables is known ahead of time (all of which happen to be true in this case, but adapting the code to cases where one or more of those things isn't true should be trivial):
Prince.trackBoxes = true;
Prince.registerPostLayoutFunc(function() {
for (var i = 4; i <= 36; i = i + 4) {
var boxes = document.querySelector('table.touchstones:nth-of-type(' + i + ')').getPrinceBoxes();
var space = parseFloat(boxes[0].y) - parseFloat(boxes[0].h) - 56.13;
if (space > 0) {
var baseMargin = parseFloat(boxes[0].marginBottom);
var equalSpacing = (space / 3) + baseMargin;
$('table.touchstones:nth-of-type(' + (i - 3) + ')').css('margin-bottom', equalSpacing + 'pt');
$('table.touchstones:nth-of-type(' + (i - 2) + ')').css('margin-bottom', equalSpacing + 'pt');
$('table.touchstones:nth-of-type(' + (i - 1) + ')').css('margin-bottom', equalSpacing + 'pt');
}
}
});
This works well enough, but there's a hard-coded constant in there: the 56.13 representing the page's bottom margin. Ideally I'd like to be able to avoid that constant and use the box tracking API to fetch the bottom margin of whatever page each group of tables happens to be on, but I'm a bit stumped on how to reliably do that.
Edited by David J Prokopetz