Similar functionality is packaged in wkhtmltopdf, which essentially runs Webkit headless to print to PDF.
The wkhtmltopdf utility has been around awhile and works great when you get it working correctly on your platform. However, the newest version as of this writing 0.12.5 has a bug prevening TOC generation on some platforms. Some Linux platforms require the installation of Microsoft font packs, and compiling from source leads you down a rabbit hole of dependency hell.
Did you manage to find a workaround for https://github.com/wkhtmltopdf/packaging/issues/2? If so, would appreciate a PR :-)