diff --git a/product/ERP5/Document/TextDocument.py b/product/ERP5/Document/TextDocument.py
index 77e19475a34deb1bb96699c113d93fe8420fccd6..c4ef64caab268d643659b9b04f3953d003cad45a 100644
--- a/product/ERP5/Document/TextDocument.py
+++ b/product/ERP5/Document/TextDocument.py
@@ -28,6 +28,7 @@
 
 from AccessControl import ClassSecurityInfo
 
+from Products.CMFCore.utils import getToolByName
 from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
 from Products.ERP5.Document.Document import Document
 from Products.ERP5Type.WebDAVSupport import TextContent
@@ -99,11 +100,12 @@ class TextDocument(Document, TextContent):
       if format is None:
         # The default is to use ERP5 Forms to render the page
         return self.view()
-      # For now we just return the raw content
-      return self.getTextContent()
-      # XXX - In the future, we will use portal transforms
-      # to render the content in any format
-      return self.portal_transforms.convertTo('text/text', self.getTextContent())
+      # Return the raw content
+      if format == 'raw':
+        return self.getTextContent()
+      mime_type = getToolByName(self, 'mimetypes_registry').lookupExtension('name.%s' % format)
+      return getToolByName(self, 'portal_transforms').convertTo(mime_type,
+                           self.getTextContent(), object=self, mimetype=self.getTextFormat())
 
     ### Content indexing methods
     security.declareProtected(Permissions.View, 'getSearchableText')