Move PDF generation to a plugin. Fixes #1009