As Russell says wkhtmltopdf is probably the best bet. I've created a free online service to convert HTML to PDF files http://www.html2pdfrocket.com which uses wkhtmltopdf but makes the process easy and cross platform.
I've added examples on how to conversion HTML to PDF for PHP, C#, RUBY and HTML. You could trigger it in JavaScript if you wish.
It's being used by the heart foundation and others to create PDF files in real time, for example PDFs of recipes, invoices, receipts etc - although you can download and cache the PDF output if you wish.
Hope you find it helpful and please write to me there if you have feedback or if you need help getting kwhtmltopdf working in your own env.