added toDocument() method