There are several options to choose from : PDF library MFC at DuckDuckGo
I take a side-step approach to this. I set up code for printing and then "encourage" the user to select the "Write to PDF File" driver and that results in a PDF file being writing. XPS files can also be written this way. I suspect that one could automate this process a bit by selecting the driver and output file in but I have never tried.