Combine these programs, first cpri (for access through your code to a printer device)
It's in C language
http://sourceforge.net/projects/cpri/
then you can use
http://sourceforge.net/projects/pdfcreator
to get a virtual printer to generate the pdf, xps format output