Creating a .pdf from database content

Many websites will create a .pdf on the fly for all kinds of reasons, especially for providing a printable receipt for a customer. Can someone point me in the right direction on how to do this? Do I need to own a copy of Adobe’s expensive software?

Thank you!

Google html 2 pdf library there are a few of them.

I like dom PDF.