10 Dec
2004

PDF in XSLT

Within the last 24 hours, I have downloaded, installed, and actually
gotten use from the Tall
Components’ TallPDF.Net
package.

My needs are to generate highly formatted PDF documents from XML documents. 
This package suits that need perfectly.  I need only run my XML through an XSLT
file of my own design that translates the XML into another XML document that I then
feed to TallPDF’s Document object.  Like this:

1public void WritePdfFile( string pathToSourceXml, string pathToXsl, string fileNameToWrite
)

2{
3 XPathDocument
hwXml = new XPathDocument( pathToSourceXml );
4

5 XslTransform
tranny = new XslTransform();
6 tranny.Load(
pathToXsl );
7

8 XmlReader
xmlReader = tranny.Transform( hwXml, null, new XmlUrlResolver()
);
9

10 FileStream
fs = null;
11 try {
12 fs
= new FileStream( fileNameToWrite, FileMode.Create
);
13

14 Document
d = new Document(); // <–
This is the magic Tall Object


15 d.Read(
xmlReader );
16 d.Write(
fs );
17 }
18 finally {
19 if(
fs != null ) {
20 fs.Close();
21           
}
22 }
23}

After creating a simple app to use this function, all the rest of my
work is in XSLT.  Now, the complexity of the XML that I must generate is severe,
but the power of changing the PDF layout without re-compiling is great.

The reason I am so impressed with this system is because I remember trying
to do this with SGML instead of XML back in the mid-90s and the complexity and expense
of the rendering engine was amazing.  Basically, you had to invest $50K just
to even think about doing this.  TallPDF.Net sells for as little as $499. 
XML really has changed things.