CSS paged media
In paged media the content of the document is split into one or more discrete pages. Paged media includes paper, transparencies, pages, Microsoft Word documents, Adobe PDF (portable document format) files among others > **This needs to be tested with modern browsers. As far as I know this is only supported on Chrome and, maybe, Firefox** > > **I am currently working on a sample page and associated stylesheet to test the concept and see how well it works. See the bottom of this post for more information** We no longer need to convert our documents into PDF or Word in order to print them. Using paged media and good layout and typography there is no reason not to expect high quality print results from our web content. This is not a widely supported technology in browsers but it's getting there and, when it does, it'll make `HTML` an even better format to publish content. There are formatters; programs that will take an HTML file and the style sheet and output a file suitable for printing. Some of the formatters include: - [Antenna House](http://www.antennahouse.com/) - [WKHTMLtoPDF](https://code.google.com/p/wkhtmltopdf/) - [xhtml2pdf](http://www.xhtml2pdf.com/) - [PhantomJS](http://phantomjs.org)? If we can capture the page then we might be able to use PhantomJS to print the page instead. This is not quite the ideal I had in mind when I first started looking at Paged Media but until browser support gets better than it may just have to do. Before we jump in to the code, there's one great article from A List Apart that covers book making with CSS: [Building books with CSS](http://alistapart.com/article/building-books-with-css3) ## Defining Pages: the @page rule CSS defines a "page box", a box of finite dimensions where content is rendered. It is formed by two areas: - **The page area**: The page area includes the boxes laid out on that page. The edges of the page area act as the initial containing block for layout that occurs between page breaks. - **The margin area**: which surrounds the page area. You can specify the dimensions, orientation, margins, etc. of a page box within an @page rule. The dimensions of the page box are set with the 'size' property. The dimensions of the page area are the dimensions of the page box minus the margin area. For example, the following @page rule sets the page box size to 8.5 x 11 inches and creates '1in' margin on all sides between the page box edge and the page area: ``` ``` You can use the `margin, margin-top, margin-bottom, margin-left, and margin-right` properties within the @page rule to set margins for your page same as you would for your regular CSS rules. ## Setting Page Size: The `size` property specifies the size and orientation of a page box. There are four values which can be used for page size: - **auto:** Same as the target paper size. - **landscape:** Vertical layout, larger side of the page are left and right - **portrait:** Horizontal layout, larger sides of the pare are top and bottom - **length:** Length values for the 'size' property create an absolute page box. Values are entered manually. We'll concentrate in `length` for this document. Once we've done some testing we will go back to how the `auto, portrait and landscape` value interact with the other parameters set up on the stylesheet The example belows explicitly says the dimensions of the page to 8.5in by 11in. The pages created from the example requires paper that is 8.5"x11" or larger. ``` ``` Once you create a named page layout, you can use it in your document by adding the page property to a style that is later applied to an element in your document. For example, this style renders all the tables in your document on landscape pages: ``` ``` If the browser encounters a `