Updated pdf creation function