[XML-SIG] xml to pdf... a newbie question...

mgushee@havenrock.com mgushee@havenrock.com
Tue, 04 Mar 2003 04:01:57 -0700

On 4 Mar 2003 at 10:43, Gisbert Amm wrote:

> > thanks... i'm currently downloading it now...
> > 
> > how about if i choose to present the reports in postscript???
> > 
> > is there a python application that can change xml/xsl to postscript???
> >
> I'm afraid there isn't a out-of-the-box solution. But I don't know exactly.
> The only way to create Postscript I know is from DocBook XML via Latex to
> Postscript, but that's a thorny path and seems somewhat oversized just for
> some reports ...

Another similar, more flexible option is to use ConTeXt. It's another 

TeX macro system, and it has semi-built-in support for processing XML 

directly. By 'semi-built-in', I mean that you will likely have to 
write a sort of mapping file to tell ConTeXt how to handle your 
particular XML dialect. Not too hard if you're well-versed in TeX, 
but otherwise it might be rough.

Actually, you could render the XML (using your Python code) to a 
Tkinter Canvas, and then use the Canvas.postscript() method to output 

PS. If you don't need a GUI, I believe you can do this without ever 
displaying the Tk window. It's kind of an odd approach, but certainly 

feasible (and probably no harder than any of the other options that 
have been mentioned).

> On the other hand: If you want to be flexible with future output formats,
> write out your data from Python to XML (stream or file) and then transform
> it with XSLT to the format you want.
> There are several XSLT engines in general and for python, most popular
> perhaps Saxon (Java) and 4xslt (Python) and Xalan (C++, Java) for which
> exists a Python interface called Pyana which I use currently. And FOP, as
> you certainly know, can generate PDF from XML directly (using the
> appropriate XSLT).

I wouldn't call that 'direct', since you need to use full XSL rather 
than just XSLT.

> Be aware of the work to do with XSLT (and to learn it, if you're not already
> typing it fluently).
> If PDF is the only format you need, ReportLab is a good choice.

I second that recommendation. I would just add that once you've got 
ReportLab it may not be at all clear how to proceed, but I would 
suggest writing a SAX Handler that uses ReportLab's PLATYPUS 
interface to generate PDF.

One problem you may run into is that ReportLab has built-in so-called 

"XML support"--meaning that it automatically interprets certain tags 
within paragraphs as formatting instructions (<b>, <i>, and the 
like). But it doesn't handle arbitrary elements or full XML 
documents. I wish they hadn't added that "feature"--it's a 
significant flaw in an otherwise excellent product. But, as I recall, 

it's not terribly hard to work around that as long as you're aware of 

the issue. It's been a while since I've done anything with ReportLab, 

but I may be able to help a bit if you run into trouble.

Matt Gushee
Englewood, CO USA