Solve undefined variables from best post and testing print to pdf function