Hi Sunder,
The widget is generating an html string and the document needs an xhtml string. I've built something similar and had to create a java action that converts the html string to xhtml for the document template.
Here is the code for the java action. It takes in a string parameter and returns the xhtml string.
// This file was generated by Mendix Modeler.
//
// WARNING: Only the following code will be retained when actions are regenerated:
// - the import list
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
// Special characters, e.g., é, ö, à, etc. are supported in comments.
package docugen.actions;
import javax.swing.text.Document;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.webui.CustomJavaAction;
import org.jsoup.*;
import org.jsoup.select.Elements;
import org.jsoup.parser.Parser;
import org.jsoup.nodes.*;
public class ConvertToXHTML extends CustomJavaAction<java.lang.String>
{
	private java.lang.String HTML;
	public ConvertToXHTML(IContext context, java.lang.String HTML)
	{
		super(context);
		this.HTML = HTML;
	}
	@Override
	public java.lang.String executeAction() throws Exception
	{
		// BEGIN USER CODE
		org.jsoup.nodes.Document document = Jsoup.parse(HTML);
		document.outputSettings().syntax(org.jsoup.nodes.Document.OutputSettings.Syntax.xml); 
	    return document.toString();
		// END USER CODE
	}
	/**
	 * Returns a string representation of this action
	 */
	@Override
	public java.lang.String toString()
	{
		return "ConvertToXHTML";
	}
	// BEGIN EXTRA CODE
	// END EXTRA CODE
}
You would need to download and add the jsoup jar file to the userlib folder in your project.
You can find that here
And here is some documentation on creating a java action.
https://docs.mendix.com/howto/logic-business-rules/extending-your-application-with-custom-java
Hope this helps!