Remove trailing whitespace
Break apart pdf rendering logic