Hi jonito, welcome to the forums!
It should just be a case of querying the DB and putting the PDF contents into a variable, then you can use the file_put_contents function to write it to a file:
If you want the user to be able to download the PDF, then probably what you want to do is something like this:
which will set the correct headers and output the file to the browser. If the user has a PDF reader plugin, they'll be able to view it in their browser, otherwise they'll be prompted to download it.