Not really answering your question but you could consider generating postscript output and then using ghostscript to convert it to pdf. That would let you create and write arbitrary stuff. I think pandoc uses pdflatex to generate a pdf via latex from the internal pandoc representation.
Imagemagick also writes to pdf I believe, but it may only convert raster images. With postscript you can generate a vector pdf