Make sure that document conversions produce a UTF-8 string.

Closes #1393.

<!---
@huboard:{"order":12.647705078125}
-->