title: How to write HTML text to Microsoft word document using POI or docx4j?
body: <p>I am using docx4j to create Microsoft word documents. I also need to write html text to doc. Below is the code I am using, bu when the doc file is generated, its all empty. </p>
  
  <pre><code>import org.docx4j.dml.ObjectFactory;
  import org.docx4j.jaxb.Context;
  import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
  import org.docx4j.openpackaging.parts.WordprocessingML.AltChunkType;
  
  public class AltChunkAddOfTypeHtml {
  
      static String DEST = "/home/Downloads/Sample.docx";
  
      private static org.docx4j.wml.ObjectFactory factory;
  
      public static void main(String[] args) throws Exception {
  
          WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
                  .createPackage();
  
          String html =  "&lt;html&gt;पासवर्ड&lt;/html&gt;";
  
          wordMLPackage.getMainDocumentPart().addAltChunk(AltChunkType.Html,
                  html.getBytes());
  
          wordMLPackage.save(new java.io.File(DEST));
      }
  
  }
  </code></pre>
  
  <p><strong>EDIT 1:</strong></p>
  
  <p>Below is the code which works properly. Only issue now is setting the font properly. When i set the font in the HTML as below</p>
  
  <pre><code>&lt;table border="1px" width="70%" style="font-size: 9px;"&gt;
  </code></pre>
  
  <p>Given font size is applied to English text only. It is not applied to the Marathi text. </p>
  
  <pre><code>import java.io.File;
  import org.apache.commons.io.FileUtils;
  import org.docx4j.XmlUtils;
  import org.docx4j.convert.in.xhtml.XHTMLImporterImpl;
  import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
  
  public class ConvertInXHTMLFragment {
  
      static String SRC = "/home/Downloads/Input.html";
      static String DEST = "/home/Downloads/Sample.docx";
  
      public static void main(String[] args) throws Exception {
  
          String stringFromFile =  "&lt;html&gt;पासवर्ड&lt;/html&gt;";
          WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
  
          XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(wordMLPackage);
  
          wordMLPackage.getMainDocumentPart().getContent().addAll(XHTMLImporter.convert(stringFromFile, null));
  
          System.out.println(XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true));
  
          wordMLPackage.save(new java.io.File(DEST));
      }
  
  }
  </code></pre>