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?"
I'm not actually familiar with the details of postcript at all, but it certainly seems a logical format to consider if printing things is your concern.
A Minesweeper clone that doesn't suck
Apache FOP Homepage
Very powerful if you ask me. I used it on a project back in 2000-2001 and was pleased with how it turned out at the time. I'm sure the current product is much, much, better than it was back then.
I have a similiar problem I solve through the use of XSLT and XSL-FO. Use XSLT to transform the XML into XSL-FO. Then, use Apache FOP to render the XSL-FO into PDF.
Another variation is to transform your XML into an HTML subset, then use a standard XSLT to transform the HTML into XSL-FO. A similiar technique is used by Aurigadoc to create all sorts of output formats using an XML source.
http://xml.apache.org/fop/r ights.com/training/ has a book about how do this that was created using XSLT-FO
http://www.cranesoftw
There are also paywhere implimentations XSLT-FO this. Basicaly it is the extension to XSLT for print.
Oh really?
Prince is a batch formatter for converting XML into PDF and PostScript by applying Cascading Style Sheets (CSS). Unlike other formatters, Prince prints any XML vocabulary without relying on proprietary markup
500GB of disk, 5TB of transfer, $5.95/mo
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.
The company I work for dynamically fills out complicated forms and fills in their data. We use PDF, sure, but if you've got any complicated stuff where you need things to be very exact, or need to support things like mixed pages sizes, etc. You want to look into Printer Control Language, originally created by HP and supported on most printers.
RandomAndInteresting.comdefending the world from stupidity since 1979
Docbook is an XML based document format, with support to output to many different formats, including HTML and LaTeX, as I recall.
I'm not sure how the docbook LaTeX filters work, but you may want to avoid LaTeX, for several reasons: special characters. LaTeX doesn't do Unicode, you'll have to translate those characters. That's not a huge problem, merely an annoyance.
But quotes can be annoying. Latex wants directional quotes. This is fine only if you have full control of your source and are willing to deal with it.
I tried to go direct to latex on one of my projects, it's not straightforward. Unless I'm missing something obvious; if someone does know a solution, please inform me 8-}
Another XML-based format is DocBook, which originally was SGML based but now has a XML DTD too. From this format you can output to ps, pdf, rtf and plenty of other formats.
You could also hack one of the docbook XSL stylesheets (using XSLT? would be pretty!) to make it parse your own format.
Feel ready to own one or many Tux Stickers?
While its support might not be complete (http://xml.apache.org/fop/output.html#ps) Apache FOP can also render into postscript. The advantage of XML-FO, while it hasn't been very well received, is it tries to be sufficiently expressive to support any number of output types from print (PDF, PS, RDF, etc) to graphics (SVG).
If I understand what you're asking, SVG would be a good choice. Bullet sharp text that prints excellently. It can be automatically generated and is based off of xml so it shouldn't be too hard to intergrate.
Never quite sure what the hell it does myself, but a few people here swear by it:
http://www.xmlpdf.com/
Cheers,
Dave
I write a blog now, you should be afraid.
send it to a MySQL database, then Use PHP to creat a PDF, and print it from PDF... although I can't contest for the quality of printing from PDF. Just my 2cents.
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.
I'm not sure why HTML isnt sufficient for you. We build an app that had to print boxlabels, HTML fit the bill nicely. Its designed for visual presentation of data, placing of text and graphics, and thats whats happening during printing or viewing for proofing. Ours is a bad example because we didnt have XML-source data but I know HTML would work fine.
"Give orange me give eat orange me eat orange give me eat orange give me you." -Nim Chimpsky
I've had do to just this, actually... here's the setup. Don't ask me why certain things were the way they were, certainly you can improve. I inherited some of this. But it worked...
First, we had a bunch of product data in a MS SQL server db. We had a Java (I think) task that nightly dumped XML file (one per product) based on the DB.
Then, we applied an XSLT transformation to each XML to produce the static HTML page for that day (static both to reduce server load and optimize google's searching of it, since Google didn't/doesn't like dynamic content)
Then we wanted to produce a printer catalogue, so rather than printing pages, I made an XSLT that transformed the XML not into HTML but into FOP. FOP is some Java shit from Apache that takes FOP files and spits out a PDF.
Obviously I don't remember details, but it worked.
I had the idea to generate the PDFs not just for the printed catalogues but also as "printable version" for each HTML page. So both PDFs and HTMLs were generated nightly. Yeah it took a while but it was cool.
It also served to improve our pagerank because (1) the PDFs made it look like we've got twice as much content and because (2) google gave higher weightings to PDFs (at the time, anyway)
And, it was easy.
Ecce Europa - Web Design for Business
You'd be surprised what a little coloring and some ASCII artwork can do.
I just happened to be updating my resume again, decided to make it XML based and found the xml resume library on sourceforge (xmlresume.sourceforge.net)
One of their XSLT transforms the XML to a PDF file, maybe that would be a good place to look. I only found this today, and since I'm only just learning XML, I don't know how well this applies... Enjoy!
On Arrakis: early worm gets the bird. Magister mundi sum!
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.
Parent is spot on!
Everyone seems to know XSLT, but not it's sister XSLFO spec. XSL-FO is designed for exactly this!
All my users use Word as a helper application, which they think is great, but it makes me cringe to think of more invocations of an MS product.
I would loved to try producing the PDF, XSL/FO and Postscript outputs via XSL transformations, just haven't had the time to try it yet. I'm sure they would yield better results, so go for it!
There are also paywhere implimentations
"payware".
Is /. now the offical R&D contractor for every shitty, piss-ant "company" with a "product" out there?
Seriously, buddy. It's not hard. XML -> Perl/Php/Python/Whatever P you chose -> PostScript -> pretty printing
Google is your friend.
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.
lpr file.xml
Comment removed based on user account deletion
That's XSL-FO (eXtensible Style Language - Formatting Objects) - there's no such thing as XSLT-FO.
In this world nothing is certain but death, taxes and flawed car analogies.
I'm amazed that no one has suggested good old troff! :-}
I ran across this a little while ago.... DeliveryWare
It will handle XML documents and convert to various formats and can fax, e-mail, print or do whatever with the file.
ÕÕ
gvim will do it - and command-line. Just run it with a couple of initial commands (use -c to specify comands). ":syntax on" to turn syntax highlighting on and ":hardcopy" to print.
Haven't tried it, but should be a breeze. And a portable solution too.
Some parts of the slashcode are pretty easy to understand. For example, I patched it so that Underrated and Overrated would get caught in moderation. (But that's a feature that they want to keep. Despite new users filing it as a bug every three months.)
Irene KHAAAAAAN!