allow function override in toDocument()