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

Category:
Enhancement request
Priority:
Normal
Status:
New
Project: Severity:
Minor
Resolution:
Open
Component: Reproducibility:
N/A
Assigned to:
0

Hello,

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"/>
</w:font>
</w:fonts>

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"/>
</Relationships>

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");

AttachmentSize
Image icon docx_embedded_fonts_resources.png6.26 KB
v6.4.3
laimutisign's picture
Joined: Nov 16 2018 - 3:47am
Last seen: 4 weeks 8 hours ago
Feedback