refactor more of pdf writing to the module