First of all, post the HTML you generate. Not the thing which is generating it. And second, get rid of the 90% of that code which doesn't have anything to do with your question. A reasonable example would be no more than 10 lines of code.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Does Onload supported in Mozilla Firefox 3.6