Save pages into List instead of Queue
avoid infinite loop
handling exception for image file and document file