Web Viewer font problem

Stimulsoft Reports.JAVA discussion
Post Reply
borax1974
Posts: 13
Joined: Mon Dec 08, 2025 3:26 pm

Web Viewer font problem

Post by borax1974 »

Hi,

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;
        }
    }
Attachments
StimulsoftViewerBoldProblem.png
StimulsoftViewerBoldProblem.png (160.01 KiB) Viewed 405 times
Vadim
Posts: 436
Joined: Tue Apr 23, 2013 11:23 am

Re: Web Viewer font problem

Post by Vadim »

Hello

Can you send us this font files: arial.ttf, ariali.ttf, arialbi.ttf, arialbd.ttf ?
borax1974
Posts: 13
Joined: Mon Dec 08, 2025 3:26 pm

Re: Web Viewer font problem

Post by borax1974 »

I attached them as a rar file.
Attachments
arial.rar
(1.73 MiB) Downloaded 42 times
Lech Kulikowski
Posts: 7587
Joined: Tue Mar 20, 2018 5:34 am

Re: Web Viewer font problem

Post by Lech Kulikowski »

Hello,

We need some additional time to investigate the issue, we will let you know about the result as soon as possible.

Thank you.
Post Reply