Aspose Diagrams Fonts not loaded correcly sometimes

I am using aspose diagrams on Java (running on unix) to convert a visio to a PDF. We are loading some custom fonts, however we noticed that for the same visio (and same application version) it works fine sometimes, but sometimes the fonts are not loaded correctly (the fonts are included in the JAR).

Java code:

InputStream visioStream = new ByteArrayInputStream(Base64.getDecoder().decode(file));
ByteArrayOutputStream image = new ByteArrayOutputStream();
// Call the diagram constructor to load diagrams from a VSD file
Diagram diagram = new Diagram(visioStream);
visioStream.close();
diagram.setFontDirs(fontDirs);
diagram.save(image, SaveFileFormat.PDF);
diagram.dispose();

@ln1

It seems you are experiencing intermittent issues with custom fonts not loading correctly when converting Visio files to PDF using Aspose.Diagram in Java. Here are some suggestions to help you troubleshoot and potentially resolve this issue:

  1. Font Directory Setup: Ensure that you are setting the font directories at the start of your application. This is crucial because if the font directories are set after the diagram is loaded, it may lead to poorly formatted results. You can specify multiple font directories using the setFontDirs method of the Diagram class.

  2. Font Availability: The Aspose.Diagram API searches for fonts in the default system font directory. If the required custom font is not found, the API will substitute it with a default or the closest available font. This can lead to inconsistencies in rendering. To avoid this, make sure that the custom fonts are indeed available in the specified directories.

  3. Notification of Missing Fonts: Implement an IWarningCallback to receive notifications about any font substitutions during the rendering process. This will help you identify when a font is missing and what it is being replaced with. Here’s a simple implementation example:

    class FontWarningCallback implements IWarningCallback {
        @Override
        public void warning(WarningInfo warningInfo) {
            if (warningInfo.getWarningType() == WarningType.FontSubstitution) {
                System.out.println("Font substitution warning: " + warningInfo.getDescription());
            }
        }
    }
    
    // Usage
    diagram.setWarningCallback(new FontWarningCallback());
    
  4. Testing Environment: Since you are running on a Unix system, ensure that the font files are accessible and have the correct permissions. Sometimes, file access issues can lead to fonts not being loaded properly.

By following these steps, you should be able to improve the consistency of font rendering in your PDF outputs. If the problem persists, consider checking the Aspose documentation for further details on font operations and troubleshooting.

Sources:
[1]: Aspose.Diagram Font Operations - Aspose Documentation

@ln1
Could you please share your sample vsd file and the fonts that you are using?
That should help us to check this issue on our end.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): DIAGRAMJAVA-51233

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

I added the viso and the font, the font used is Calibri.

So sometimes the document is generated correctly
image.png (87.4 KB)

But sometimes it looks like this:
image.jpg (92.2 KB)

visio.zip (5.8 MB)

@ln1
Thanks for the template file and screenshots.
We will evaluate your issue further.