Pretty Printing From An XML File?
Omega1045 writes "Where I work we are developing a new product that receives an XML document (on a W2k workstation), and we need to format and print said document. We are currently using XSLT + CSS to build a cool little HTML page out the the XML, then use a browser to print out the HTML. However, while HTML is a nice format for display, it is not a nice format for printing. We have messed around with the idea of spitting out Rich Text with XSLT. However, Rich Text is confusing and quite frankly sucks. We are looking for a (free if possible) format that we can translate our XML document into via XSLT, and print. The best idea we have at this point is to translate into a Word or OpenOffice XML schema document, and use one of those applications to print. Other ideas?"
Generate a LaTeX document file, compile it using PDFLatex and print. Or, use normal LaTeX and print directly from it, depending if .dvi files offend you.
Having been in the same situation before, this is what I suggest...
/*Styles for browser and printer*/ /*Styles for browser only*/ /*Styles for printer only*/
Take the XML and the XSL and transform it into 100% valid XHTML. HTML 4 is deprecated, the standard will not be updated. XHTML 1.0 is 5 years old already - start to use it.
Use CSS - pay attention to
@media screen,print
{
}
@media screen
{
}
@media print
{
}
If it doesn't print well, you probably need to refresh your CSS here: http://www.w3.org/style
Goodluck.
You'd be surprised what a little coloring and some ASCII artwork can do.
We had this problem once, but worse.
When I started with my current employer, we had a very complicated PDFing process. Every night a transfer workstation would copy datafiles localy from a backup of the production server. A pervasive driver was loaded to read the dat files. Access would import the data from pervasive and run a report that was saved as a RTF file. It was then opened in Word where a macro would then PDF the document and close. The PDF was then copied to the webserver for the users to download.
What a mess and a nightmare to debug. It would work for a few months and then at seamingly random times, it would crash horibly for several days in a row.
When it did break, i felt like I wasted a lot of time tracking down ghost problems. In my slow days I rewrote it.
It now pulls read only data from the production server with that pervasive driver into a xml file. Then apply a xsl transform and pass the result to the FOP processor and place the result directly on the webserver.
A process that took an hour to run now finishes in 2 minutes. It is quick enough, we run it every 20 min. FOP was quick to setup and the examples are like a blue print and easy to figure out.
I have never had a problem with the new implementation and the end user had no impact and was unaware of the change.
I would recomend using a FOP processor to my friends.
Im a gamer, not a grammer major. This post is full of spelling and grammer mistakes.
Use XSLT to transform your XML to DocBook, then use DocBook XSL to convert to XSL-FO, then Apache FOP to generate a PDF.
Alternatively, skip the DocBook step and transform straight to XSL-FO.
In this world nothing is certain but death, taxes and flawed car analogies.