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();
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:
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.
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.
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());
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.
@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.