Method for converting document to string