I still believe per my comments above that your issues are related to "containers". I'm trying to set aside a bit of time to test some variations of what I'm going to share with you, but wanted to post it and some references in the mean time since I know you're also working on this.
Background: Essentially, you're "printing" a document to a PDF printer as pages. As such, containers are even more important to consider, both in terms of a page level and a box level. See W3 Org's Introduction to Paged Media for more on this model.
The W3 specs allow you to specify different CSS for the media type you're outputting to and also for Paged Media (usually print and projection) using @page
and for multiple output on different via different display methods using the @media
method in your CSS. Below is a simple example:
@media print {
body { font-size: 10pt }
}
@media screen {
body { font-size: 13px }
}
@media screen, print {
body { line-height: 1.2 }
}
Your specific issue though is related to orphans and widows that are being created within "boxes" when your overflow
isn't being hidden
as your CSS has called for which then causes pagination to occur.
In your case, these are being created when hidden text at one of the following below causes an allowed page break to occur:
- Between line boxes inside a block container box.
- Between the content edge of a block container box and the outer edges
of its child content (margin edges of block-level children or line
box edges for inline-level children) if there is a (non-zero) gap
between them
These are controlled by page-break-before
, page-break-after
and most importantly, page-break-inside
, all of which are set to auto
by default. I think you want to use page-break-inside:avoid
. These settings are also impacted to some extent by the orphans
and widows
setting (min no lines at start of a page and max no lines remaining at end of a page) for your smallest inner "container" or "block" that you're using.
You may also want to note the following per this reference: http://www.w3.org/TR/CSS21/visuren.html#fixed-positioning and see if it can be of any use to you.
For paged media, boxes with fixed positions are repeated on every
page. This is useful for placing, for instance, a signature at the
bottom of each page. Boxes with fixed position that are larger than
the page area are clipped. Parts of the fixed position box that are
not visible in the initial containing block will not print.
In summary, I think creating your page based on a page container block model may be the way to solve your issue. I've never been in the situation where I needed to hide overflow text like you're in, so have never encountered this issue. Instead, I've always had the opposite one to deal with; making certain it was all visible.
When I find time to test this further, I'll report back with my findings.