Repeat thead and tfoot of tables when printing pages.

This feature was previously added in e.g. commit
5605fed8171cab26b7693b6b759b7b484474b781 but lost in the porting
process apparently.

This patch here brings the feature back and additionally fixes the
bug where the borders of table headers or footers where not properly
printed on the repeated elements.