Tuesday, August 16, 2005

NFJS 2.3 - Killer Graphics & Professional PDFs with XML

Ben Galbraith is the author of several Java/XML books and is a well know name in User Interface development. This talk by him, was one of the introductory ones to the capabilities of XSL-FO and SVG for creating PDF's and Images (as the name suggests). The first question is why would one use XML for these and why not a commercial package? First of all it is FREE! and it is open format so one can do anything they want. It is really easy to take source data and convert into other formats that no vendor controls.

XSLT lets you take the data into XML using XSL-FO. XSL-FO is an XML grammer for representing a document and a program is needed to generate the pdfs, postsrcripts, word docs or even any other format. XSLT and XSL-FO are tightly related. The primary intention of XSL to transform unformated XML into XSL-FO that can further be converted to HTML. This idea came from SGML (Standard Generation Markup Language), that the browser would request XML from the server and then use XSL-FO to format and print.

XSL-FO is still the best / powerful grammer for representing the formatted documents. Current version of XSL-FO is 1.0 and the new implementations aim to provide all the capabilities of LATEX. I wish I knew about it when I was in school... :) Editing my thesis would have been much easier.

There are a variety of tools available to convert XSL-FO to PDF or other formats. The mostly used Open source one is the Apache's FOP and is probably the best tool out there. It was started by a number of talented people who later left and now the attitude is to pretty much start from the scratch for new functionalities etc. It is used to create high quality medical text books (or atleast thats what Ben uses it for). Some known commercial tools available are Render X and Antena House.

Some clarifications about XSL-FO: that it is probably not suitable for generating tabular reports and any open source / commercial reporting tool (e.g., iText) can rather be used. XSL-Fo does not prvide the capability to add bookmarks/layers to the documents. It is pretty trivial to transform XSL-FO to HTML and there are style sheets out there that do that, so it can render docs for the web.

There are various other tools out there as well that convert other formats to XSL-FO. Some examples: CSSToXSLFO- converts XML/CSS2 into XSL-FO, RTF2FO- for rich text conversion into FO and others like Antenna House, Scriptura and XSL-FAST.

XSL-FO does have some limitations and they can be pretty serious. Although there are some workarounds that can be used. XSL-FO does not provide the capability for the magazine type layout, there is no spot-color support, very weak float support and not access to PDF specific features. The workarounds include using iText to create composite PDF's. Multivalent (available at sourceforge) is an open source tool that decodes the PDFs and make it readable and it can be used to modify PDFs directly.

The second part of the talk was about SVG (Scalar Vector Graphics) which is a language for describing two-dimensional graphics and graphical applications in XML. SVG supports animation, interactivity and other cool effects and the file size is much smaller compared to the jpeg, png etc and other image formats. Simillar to XSL-FO, SVG files are rendered by an SVG viewer. The available out there are Adobe's IE SVG viewer plugin and Apache Batik which is a popular Java-Based SVG viewer toolkit. Mozilla is actively developing SVG support however, microsoft's support is unclear in this regard.

SVG provides a lot of effects like clipping, masking, coompositing, lighting, filters and gradients etc. and it is pretty easy to create animations. Some tools available for generating SVG docs: Open Source Inkscape - written in C++ and has a CLI, Other commercial solutions available are Adobe Illustrator, Sketsa based on Batik and EvolGrafiX XStudio.

The talk did provide a dive into the working and creating of XSL-FO and SVG documents but I think it will be better to look at the code directly from the slides or the symposium CD. (Let me know if interested)