Generating the Individual Panels

page 183 When we invoke the PDF-generating templates with the mode=generate-pdf attribute, we pass in the page-size parameter to set the dimensions of the printed page. We generate PDFs with both letter-sized and A4-sized pages to support our customers around the world. To create the PDF, we first create the output file of formatting objects, converting the various XML tags from our source document into the various formatting objects we need: fo:block font-size=16pt line-height=19pt font-weight=bold space-after.optimum=12pt Introduction to JavaServer Pages fo:block fo:block space-after.optimum=6pt In todays environment, most web sites want to display dynamic content based on the user and the session. Most content, such as images, text, and banner ads, is most easily built with HTML editors. So we need to mix the static content of HTML files with directives for accessing or generating dynamic content. fo:block fo:block space-after.optimum=6pt JavaServer Pages meet this need. They provide server-side scripting support for generating web pages with combined static and dynamic content. fo:block Currently, the XSL:FO specification is a candidate recommendation at the World Wide Web Consortium W3C. Because future changes are likely, we wont discuss the formatting objects themselves. It suffices to say that our stylesheet defines page layouts margins, running headers and footers, etc. and then creates a number of formatting objects inside those page layouts. The FOP tool handles the details of calculating line, page, and column breaks, page references, and hyperlinks. Once the file of formatting objects is created, we call an extension function to convert the formatting objects file into a PDF. Heres the exensions main code: public static void buildPDFFileString foFilename, String pdfFilename { try { XMLReader parser = XMLReader Class.forNameorg.apache.xerces.parsers.SAXParser .newInstance; Driver driver = new Driver; driver.setRendererorg.apache.fop.render.pdf.PDFRenderer, Version.getVersion; driver.addElementMappingorg.apache.fop.fo.StandardElementMapping; driver.addElementMappingorg.apache.fop.svg.SVGElementMapping; driver.addPropertyListorg.apache.fop.fo.StandardPropertyListMapping; driver.addPropertyListorg.apache.fop.svg.SVGPropertyListMapping; driver.setOutputStreamnew FileOutputStreampdfFilename; driver.buildFOTreeparser, new InputSourcefoFilename; driver.format; driver.render; } The code merely creates the FOP Driver object, sets its various properties, and then tells it to render the formatting objects in a PDF file. The main difficulty here is in determining how the various XML elements should be converted to formatting objects; once the conversion is done, we have a tool that generates high-quality printable output from our XML source files. Best of all, this code uses open source tools exclusively.