fixed query bug and added new code for saving pdf document.