Refactor PDF generator