I am using Stimulsoft Java 2025.4.3, Java JDK 17, Spring Boot 3.2. Tomcat 10 server on Centos Linux with "Arial" fonts installed. I want to embed these fonts to the PDF exports so I have added arial fonts to the report as resources. The pdf exports are rendered correctly but I have problems with the viewer and designer. All the designer user interface and viewer fonts changed to Arial Bold Italic. I noticed it changes to the last added font. Below is the code I use to add fonts. Also attached the rendered images.
Code: Select all
private void loadFonts(StiReport report) {
// Font definitions with their names and file paths
LinkedHashMap<String, String> fontMappings = new LinkedHashMap<>();
fontMappings.put("Arial", "/META-INF/resources/fonts/arial/arial.ttf");
fontMappings.put("Arial Italic", "/META-INF/resources/fonts/arial/ariali.ttf");
fontMappings.put("Arial Bold Italic", "/META-INF/resources/fonts/arial/arialbi.ttf");
fontMappings.put("Arial Bold", "/META-INF/resources/fonts/arial/arialbd.ttf");
int loadedFonts = 0;
for (Map.Entry<String, String> fontEntry : fontMappings.entrySet()) {
String fontName = fontEntry.getKey();
String fontPath = fontEntry.getValue();
if (loadFont(report.getDictionary(), fontName, fontPath)) {
loadedFonts++;
}
}
if (loadedFonts > 0) {
logger.info("Successfully loaded {} Arial font(s)", loadedFonts);
} else {
logger.error("Failed to load any Arial fonts");
}
report.loadFonts();
}
private boolean loadFont(StiDictionary dictionary, String fontName, String fontPath) {
try (InputStream fontStream = getClass().getResourceAsStream(fontPath)) {
if (fontStream == null) {
logger.error("{} font file not found in classpath: {}", fontName, fontPath);
return false;
}
byte[] fontBytes = fontStream.readAllBytes();
StiResource stiResource = new StiResource();
stiResource.setType(StiResourceType.FontTtf);
stiResource.setInherited(true);
stiResource.setContent(fontBytes);
stiResource.setName(fontName);
stiResource.setAlias(fontName);
dictionary.getResources().add(stiResource);
logger.debug("Add font resource: {}", fontName);
return true;
} catch (Exception e) {
logger.error("Failed to load resource {} font from {}", fontName, fontPath, e);
return false;
}
}