For quite some time I have searched for an elegant free way of generating PDF files
in .Net. My unfortunate work colleagues used to get spammed with emails about
this library or a different approach, but at last I think my searching may be at an
end. I had come across the iTextSharp (http://itextsharp.sourceforge.net/)
library before but I didn't realise that one could generate a PDF
file from XML. Previously it looked like one had to code declarations to add
paragraphs, titles, etc. to the document. As it turns out (or maybe it has simply
advanced since my first encounter with the library) it can also generate HTML and
RTF (using an extension package).
Looking at the example of pdf
generated from an XML file, this could be very useful in my current project where
we need to generate a pdf file from a potentially modifiable template document.
I'm thinking that the document template could be stored as XML and when we generate
the pdf file we do the following:
-
Replace placeholders for information such as name and add in any extra clauses
etc.
-
We could apply an XSLT transform to convert the resultant XML document into the
format expected by iTextSharp
-
And feed the result through iTextSharp and stream the output back to the
web client.
As an aside, he following site seems to be quite a useful XSLT resource: http://www.informatik.hu-berlin.de/~obecker/XSLT/