I am trying to convert HTML to Docx but some how <div> with Times New Roman font set in CSS does not applied when converted to Docx, div with Segoe UI is ok though. (My Microsoft Word do have option to change text font to Times New Roman and I can convert html <p> tag to Times, just can’t do the same with <div>)
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.times {
font-family: 'Times New Roman', Times, serif;
font-size: 12px;
}
.segoe {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: 12px;
}
</style>
</head>
<body>
<div class="times">HELLO in Times New Roman</div>
<div class="segoe">HELLO in Segoe UI</div>
</body>
This is my code to convert HTML to Docx file.
htmlContent = htmlContent.replace("<br>", "");
WordprocessingMLPackage wordPackage = WordprocessingMLPackage.createPackage();
wordPackage.getMainDocumentPart().addAltChunk(AltChunkType.Xhtml, htmlContent.getBytes());
File exportFile = new File(EXPORT_DOCX_FILE_PATH);
wordPackage.save(exportFile);