We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Font substitution callback not being called

Hello.
We have font issues on one of customer's servers.
I'm trying to implement font substitution warning, but the callback does not get executed.
Finally I ran a simple test and it also does not produce any output.
Here is the code:

@Test
public void saveAsImage() throws Exception {
FontSettings.setFontsFolder("", false);
FontSettings.setDefaultFontName("Arial");

Document doc = new Document(getMyDir() + "BUG_49599_chinese chars.docx");

ImageSaveOptions imageOptions = new ImageSaveOptions(SaveFormat.JPEG);
imageOptions.setWarningCallback(new Examples.HandleDocumentWarnings());

imageOptions.setJpegQuality(80);
doc.save(getMyDir() + "Rendering.JpegCustomOptions Out.jpg", imageOptions);
}



public class HandleDocumentWarnings implements IWarningCallback
{
public void warning(WarningInfo info)
{
// We are only interested in fonts being substituted.
if (info.getWarningType() == WarningType.FONT_SUBSTITUTION) {
System.out.println("Font substitution: " + info.getDescription());
}
}
}

As you can see, it's very simple and callback hast to be called, but it's not.
Is it a bug or am I missing something?

Version used:
Specification-Title: Aspose.Words for Java
Specification-Version: 13.6.0.0
Release-Date: 2013.06.30

Hi Josh,

Thanks for your inquiry. You are using the correct code to get the notifications of any font substitution during document save. I have tested the scenario using latest version of Aspose.Words for Java 14.10 and have not found the shared issue. Please use Aspose.Words for Java 14.10.

If
you still face problem, please share following detail for
testing. I will investigate the issue and provide you more information
about your query.

What environment are you running on?

  • Please share your input document
  • OS (Windows Version or Linux Version)
  • Architecture (32 / 64 bit)
  • Java version


Hi Tahir.

Thank you, it works with this version of the library. One more question: is it possible to list loaded fonts and font folders in linux system?
FontSettings.getFontsSources() gives my only one element - SystemFontSource
and it does not have any methods that can give me any information.
My goal is to compare and find difference between two linux systems. The same document renders fine in one system and shows squares for all characters in another system.

Hi Josh,

Thanks for your inquiry. The FontSettings.getFontsSources method returns correct value. In your case, I suggest you please implement IWarningCallback interface to be notified of any font substitution during document save.

The FontSettings.getFontsSources method gets a copy of the array that contains the list of sources where Aspose.Words looks for TrueType fonts. You can also set Aspose.Words to look for TrueType fonts in system folders as well as a custom defined folder when scanning for fonts.