Updated pdf generation code