perfect printtopage function