Refactored save as pdf method