[#11371] - DOCX: Possibility to include used fonts as embedded

Enhancement request
Project: Severity:
Component: Reproducibility:
Assigned to:


Licensing does not allow copying of Windows fonts to web servers or other commercial software. So only free fonts (like ‘DejaVu’, etc.) or other fonts (available for redistribution) can be used for reports generation, but they are usually not installed in Windows, especially when the software, using the report engine, is designed to support the unlimited end users.

The possibility to embed (include as embedded) used fonts into the generated DOCX report file solves the described problem without the need to install used fonts in end user computers.

The text below shows an example how we had successfully embedded the "DejaVu Sans" font (regular and bold) into DOCX file:

1) DOCX parts in ‘/word/fonts’ folder with the content of the fonts used in Jasper report (e.g. added files ‘DejaVuSans.ttf’ and ‘DejaVuSansBold.ttf’) were created.

2) DOCX part ‘/word/fontTable.xml’ with the description of used fonts and the flags for their embedding was created:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:fonts xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" mc:Ignorable="w14 w15 w16se">
<w:font w:name="DejaVu Sans">
<w:panose1 w:val="020B0603030804020204"/>
<w:charset w:val="BA"/>
<w:family w:val="swiss"/>
<w:pitch w:val="variable"/>
<w:sig w:usb0="E7002EFF" w:usb1="D200FDFF" w:usb2="0A246029" w:usb3="00000000" w:csb0="000001FF" w:csb1="00000000"/>
<w:embedRegular r:id="rId1"/>
<w:embedBold r:id="rId2"/>

3) DOCX part ‘/word/_rels/fontTable.xml.rels’ with the relationships between fonts table and font files was created:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/font" Target="fonts/DejaVuSans.ttf"/>
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/font" Target="fonts/DejaVuSansBold.ttf"/>

4) The DOCX relationship (in ‘/word/_rels/document.xml.rels’) between the ‘document.xml’ part and the ‘fontTable.xml’ part was added:

<Relationship Id="rftId0" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/font... Target="fontTable.xml"/>

5) Content types for .ttf files and ‘fontTable.xml’ part (two lines added in ‘/[Content_Types].xml’ file) were added:

<Default Extension="ttf" ContentType="application/x-font-ttf"/>
<Override PartName="/word/fontTable.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"/>

This “JRDocxExporter” class extension code was used to achieve what is decribed above (see attached picture with the structure of resource files; note, that ‘Content_Types.xml’ file overrides the existing one in jasperreports-6.4.3.jar):

docxZip.addEntry("word/fontTable.xml", "net/sf/jasperreports/engine/export/ooxml/docx/word/fontTable.xml");
docxZip.addEntry("word/_rels/fontTable.xml.rels", "net/sf/jasperreports/engine/export/ooxml/docx/word/_rels/fontTable.xml.rels");
docxZip.addEntry("word/fonts/DejaVuSans.ttf", "net/sf/jasperreports/engine/export/ooxml/docx/word/fonts/DejaVuSans.ttf");
docxZip.addEntry("word/fonts/DejaVuSansBold.ttf", "net/sf/jasperreports/engine/export/ooxml/docx/word/fonts/DejaVuSansBold.ttf");
relsHelper.write(" <Relationship Id=\"rftId0\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/font...\" Target=\"fontTable.xml\"/>\n");

Image icon docx_embedded_fonts_resources.png6.26 KB
laimutisign's picture
Joined: Nov 16 2018 - 3:47am
Last seen: 2 months 3 weeks ago


  • Status:New» Feedback Requested
  • Assigned:nobody» teodord


This is very helpful. But I was wondering how common is for people to embed fonts into DOCX documents. Especially since embedding the font files makes the documents much larger.




I was wondering if you could send one of the DOCX files you generated on your side, using the approached described above.
I am particularly interested to see if the font files need to be obfuscated or whether embedded fonts work on Office on Mac.

Thank you,

  • Status:Feedback Requested» New

Hi Teodor,

I attached one of the DOCX files, generated using the approach described above.

Usually we use PDF format for various reports, and we have no problems with fonts.
However, this time we got the requirement to have the same information in DOCX format, so that it could look like as in generated PDF file, but can be editable before printing official papers. Draft papers are negotiated in electronic form with the staff of other institutions, so we stuck with Windows fonts licensing issues (as our software works in Linux), and we had to embed font to DOCX file in order to solve this issue.
Fonts embedding in DOCX file for all generated reports also closed multiple complaints from other users of the application like the same information generated in PDF format file looks differently than in generated DOCX format file.

This is not the first project, where we had to embed fonts into DOC/DOCX file, so I think that the possibility to embed used fonts into the generated DOCX report will solve many issues.


File mtep_contract.docx628.06 KB