Skip to content Skip to sidebar Skip to footer

Docx To HTML: Headings' Font Style Is Not Correct Using DOCX4J

I have a docx file with Heading1 style with Calibri Light (every other texts use Calibri Light too). After converting to html, Every texts are Calibri Light (correctly), but the te

Solution 1:

Font-family is handled using directly applied CSS.

For example:

  <li class="Heading1 Normal DocDefaults " style="display: list-item;"><span class="DefaultParagraphFont " style="font-family: 'Calibri Light';">Chapter 2</span></li></ol>
  
  <p class="Normal DocDefaults "><span class="" style="font-family: 'Calibri Light';">This is an example part, chapter 2</span></p></div>

For font-family to be applied, the font must either be physically present on your machine, or mapped to a font which is physically present (see docx4j's ConvertOutHtml sample for an example).

If this is not the case, no font-family property will be emitted.

For greater insight, you can turn debug level logging on for org.docx4j.fonts.RunFontSelector. Example logging:

08:54:21.295 [main] DEBUG org.docx4j.fonts.RunFontSelector 1136 - looking for: Calibri Light
08:54:21.295 [main] DEBUG org.docx4j.fonts.RunFontSelector 1144 - Font 'Calibri Light' maps to Calibri Light

Post a Comment for "Docx To HTML: Headings' Font Style Is Not Correct Using DOCX4J"