---
name: styles-fonts
description: Package reusable JasperReports styles and fonts, including JRTX style templates, style inheritance, conditional styles, font extensions and PDF font embedding in headless servers. Use when text renders in the wrong font, glyphs are missing or replaced in PDF, a font is "not available to the JVM", styles must be shared between reports or style precedence is unclear; not for data, layout or calculation changes.
---
# Package styles and fonts
## Establish the rendering contract
Identify the exact engine/Java versions, the deployment (headless server, container, desktop), the export formats, every script and language the text must show, and which font families are licensed for embedding. Ask which fonts are approved and which characters must render instead of assuming that fonts installed on a developer machine exist on the server.
## Workflow
1. Name fonts only from a font extension. Set `fontName` to a family that a font extension registers, such as `DejaVu Sans` from `net.sf.jasperreports:jasperreports-fonts`, not to an operating-system font or a Java logical font. In the tested 7.1.1 runtime, the logical font `SansSerif` exports to PDF as non-embedded Helvetica and silently drops Greek, Cyrillic and Polish characters without any error.
2. Package custom fonts as an extension. Put the TTF files and a font families XML file on the classpath and register it in `jasperreports_extension.properties`:
```properties
net.sf.jasperreports.extension.registry.factory.simple.font.families=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
net.sf.jasperreports.extension.simple.font.families.myfonts=fonts/myfonts.xml
```
Each `<fontFamily name="...">` lists `normal`, `bold`, `italic` and `boldItalic` files and sets `<pdfEncoding>Identity-H</pdfEncoding>` and `<pdfEmbedded>true</pdfEmbedded>`. Provide every weight the report uses, and check the font license allows embedding.
3. Keep the missing-font failure. A report naming an unavailable font compiles but fails at fill with `JRFontNotFoundException: Font "..." is not available to the JVM`. Fix the extension or the font name. Do not set `net.sf.jasperreports.awt.ignore.missing.font=true` to make the error go away: it lets the report fill with a fallback font and hides wrong metrics or missing glyphs.
4. Share styles with JRTX templates. Put named styles in a `<jasperTemplate>` file, load it with `<template><![CDATA["styles/labels.jrtx"]]></template>` from a classpath-relative name and use `style="..."` on elements; a style can extend another with `style="Base"`. A missing template fails at fill with `Byte data not found at: ...`. A local style with the same name as a template style replaces it completely, without merging attributes, so give local variants new names.
5. Put conditional styles in the report. Declare `<conditionalStyle>` with a `<conditionExpression>` inside a report style. A conditional style in a JRTX template is interpreted at fill time and fails with anything but a simple parameter, field, variable or message reference, such as `$F{amount}.signum() < 0`; use a Boolean field or keep the condition in the JRXML.
6. Set the AWT headless mode (`-Djava.awt.headless=true`) on servers, and keep font metrics identical between design and runtime by using the same extension in both.
## Validate and deliver
Fill and export in headless mode with text in every required script. Extract the PDF text with an independent library such as PDFBox and compare it with the input, and check that each PDF font is embedded and is the expected family. Assert the applied style properties on printed elements, the colors from conditional styles and the explicit failures for a missing font and a missing template. State commands and results, and label any export format, operating system or font you could not test as unverified.
## Sources
- [Sample reference](https://jasperreports.sourceforge.net/sample.reference/README.html)
- [Schema reference](https://jasperreports.sourceforge.net/schema.reference.html)
- [API](https://jasperreports.sourceforge.net/api/index.html)
— ‹guest · 2026-11-29› —
این نسخه با نشانهگذاری اختصاصی حساب شما نمایش داده میشود. برای نصب سریع، به تب نصب و راهاندازی بروید.