Email print preview using Document templates > la: Error processing custom XSL content

Hi, Our application is used for email processing and the users requested an email print preview functionality that can be used to properly print an email. We use a Document Template (HTML) to generate a preview of the email and which is opened in a separate tab in the browser of the user. We used this method in order to facilitate the user to print the email without any application borders/scrollbars etc... It is working fine for emails containing text only. However, the email body text can be HTML based and as such the users expect that the print preview will show the HTML layout as well (e.g. bold, colors and images and tables etc...). However, when we set the dynamic label in the document template to Render HTML we get the error mentioned at the bottom of this post. Since these are incoming emails we cannot control the incoming HTML code. What can we do to prevent this error and/or what could be a workable alternative solution that will allow us to display html. Kind regards, Brian la: Error processing custom XSL content at ExchangeClientAddition.EmailPrintPreview ( : 'Generate HTML (.html) document using template 'DTEmail_PrintPreview'') Advanced stacktrace: at mg.a(SourceFile:188) Caused by: com.mendix.systemwideinterfaces.MendixRuntimeException: Error processing custom XSL content at ky.a(SourceFile:143) Caused by: org.xml.sax.SAXParseException: Premature end of file. at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source) at javax.xml.parsers.DocumentBuilder.parse( at ky.a(SourceFile:131) at ky.a(SourceFile:79) at kw.a(SourceFile:321) at kF.a(SourceFile:70) at kw.a(SourceFile:321) at kv.a(SourceFile:33) at kw.a(SourceFile:321) at kw.a(SourceFile:129) at kq.a(SourceFile:81) at ko.a(SourceFile:89) at ko.a(SourceFile:56) at lg.a(SourceFile:109) at mg.a(SourceFile:73) at mf.executeAction(SourceFile:101) at com.mendix.systemwideinterfaces.core.UserAction.execute(SourceFile:57) at at hC.b(SourceFile:183) at com.mendix.core.Core.execute(SourceFile:219) at gm.execute(SourceFile:186) at iW.a(SourceFile:304) at com.mendix.externalinterface.connector.RequestDispatching$Worker.a(SourceFile:148) at com.mendix.externalinterface.connector.RequestDispatching$Worker$a.a(SourceFile:140) at com.mendix.externalinterface.connector.RequestDispatching$Worker$a.apply(SourceFile:138) at$class.apply(Actor.scala:545) at com.mendix.externalinterface.connector.RequestDispatching$Worker.apply(SourceFile:134) at at akka.dispatch.MessageInvocation.invoke(MessageHandling.scala:25) at akka.dispatch.ExecutableMailbox$class.processMailbox(ExecutorBasedEventDrivenDispatcher.scala:223) at akka.dispatch.ExecutorBasedEventDrivenDispatcher$$anon$4.processMailbox(ExecutorBasedEventDrivenDispatcher.scala:123) at akka.dispatch.ExecutableMailbox$ at akka.dispatch.ExecutorBasedEventDrivenDispatcher$$anon$ at java.util.concurrent.ThreadPoolExecutor$Worker.runTask( at java.util.concurrent.ThreadPoolExecutor$ at at
1 answers

The dynamic label can generate things like bold text, colors, tables and even remote images. What it can't do is parse invalid XHTML. If you use user input to generate a document, you will first need to validate the XHTML that goes in there. Note that not all HTML is valid XHTML, for example you will need to close img tags. Additionally, many browsers are quite lax when it comes to HTML checking and will attempt to show something even if it isn't valid, but when generating a document out of it this is not possible.

This is also mentioned at

Edit: Since you only need the exact HTML to be in a HTML file, you could simply use this code to put the HTML content in a filedocument and then offer it as a download.

    if (content != null)
        Core.storeFileDocumentContent(getContext(), fileDoc.getMendixObject(), new ByteArrayInputStream(content.getBytes("UTF-8")));
    return true;

This action would take a content parameter which is the HTML string, and a fileDoc parameter which is an entity based on System.FileDocument. Don't forget to import and com.mendix.core.Core