views:

167

answers:

2

When writing a print stylesheet, is there a way to ensure that an image is always only on a single page, instead of spanning multiple pages. The images much smaller than the page, but based on the document flow, they end up at the bottom of the page and get split. An example of the behavior I'm seeing is below:

Page 1 |                    |
       |  (text text text)  |
       |  (text text text)  |
       |  ________________  |
       | | Top of image   | |
       |____________________|
       ------page break------
        ____________________
Page 2 | | Rest of image  | |
       | |________________| |
       |         …          |

What I'd like

Page 1 |                    |
       |  (text text text)  |
       |  (text text text)  |
       |                    |
       |                    |
       |____________________|
       ------page break------
        ____________________
Page 2 |  ________________  |
       | | Full image     | |
       | |                | |
       | |________________| |
       |         …          |

All those times I bitching about floats in LaTeX, and here I am asking for the same functionality... Can this be done? I'm not necessarily concerned about it working in all browsers, since this is often just a one-off document I'm writing to be turned into a PDF.

+2  A: 

The only means I can think of is to use one (or potentially more) of the following css rules:

img {
page-break-before: auto; /* 'always,' 'avoid,' 'left,' 'inherit,' or 'right' */
page-break-after: auto; /* 'always,' 'avoid,' 'left,' 'inherit,' or 'right' */
page-break-inside: avoid; /* or 'auto' */
}

I half-recall that these declarations only apply to block-level elements (so you'd also have to define display: block; on your image, or use some kind of wrapping container and apply the rules to that (whether it's in a paragraph, div, span, list, etc...).

W3Schools' reference pages for these properties:

Some useful discussion here: http://stackoverflow.com/questions/2226939/what-are-most-useful-mediaprint-specfic-cross-browser-compatible-css-properti

David Thomas
Yup, this works. (`page-break-inside:avoid`). Now I'm reminded of why LaTeX floats are a pain.
notJim
A: 

If you're generating a PDF you should probably just be using InDesign.

Azeem.Butt
InDesign would be *way* overkill for what I'm doing. I'm just writing instructions with screenshots for using an internal application. It's the sort of thing most people would use MS Word for, really.
notJim