Initial work on PDF generation, rules refactor.