Refactored pdf writer