If you need to format content not just for web pages, but for pages that will actually be printed out, keep reading. There is a technology called XSL Formatting Objects that can help you get the job done. In this article, we'll explain how to use it to format your content appropriately.
Using XSL Formatting Objects - Page masters (Page 4 of 4 )
Let's explore XSL-FO in more detail, starting with page masters. As mentioned earlier, page masters govern the geometry of pages. Pages created from content within a page-sequence element that references a given page master will use the page master's properties.
In the first example, the text "Hello, world." was crammed into the top left-hand corner of the document, flush with the edge of the page. This is very unappealing. In order to fix this, we need to add some margins to the page. Before we do that, though, it helps to determine the size of the page itself. This can be done by setting the page-height and page-width attributes of the simple-page-master element. Let's create a letter-sized page (8.5" x 11") by modifying the simple-page-master element within helloworld.fo:
With the page's dimensions defined, we can now set some margins. There are a few ways we can do this. The first is to define the margins uniformly, giving each side of the page the same margin. This can be done using the margin attribute. Let's make the page have a margin of one inch on all sides:
Another way way is to set the margins individually. Margins for each side can be set using the margin-top, margin-bottom, margin-left and margin-right attributes. Suppose we wanted to specify margins of one inch on the top and the bottom and margins of three-quarters of an inch on the left and right. We'd do it like this:
The above markup is a bit lengthy though. It's also possible to set the margins individually with the margin attribute. Margin sizes for each side can be passed in, separated by whitespace, just as they can with HTML. We can accomplish the same thing as above like this:
The first measurement passed in is the top margin. From there, it moves clockwise, so that the second measurement is the right margin, and so forth. We can simplify the above code even more, though. If we just pass in two measurements, then the first measurement will be used for the top and bottom margins, and the second measurement will be used for the left and right margins. The following markup would produce the same output:
Text isn't simply thrown onto the page in the same area, though. Later, we'll cover regions. Thanks for reading!
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.