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

Free Support Forum - aspose.com

The font obtained from the slideshow seems to be wrong

When processing the slideshow, I found that the recognized font is different from the font of the text in the source file. For example, in the source file I uploaded, the font of the text is Song Ti + Times New Roman, but I get the font when I get the font through the program The fonts are all Microsoft Yahei. What method should I use to obtain the correct font? The following is the method and process I currently use:font.7z (320.9 KB)

        Presentation ppt = info.getPresentation();
        ISlideCollection iSlides = ppt.getSlides();
        for (int i = 0; i < iSlides.size(); i++) {
            ISlide slide = iSlides.get_Item(i);
            IShapeCollection shapes = slide.getShapes();
            for (int j = 0; j < shapes.size(); j++) {
                IShape shape = shapes.get_Item(j);
                if (shape instanceof AutoShape) {
                    AutoShape autoShape = (AutoShape) shape;
                    ITextFrame textFrame = autoShape.getTextFrame();
                    IParagraphCollection paragraphs = textFrame.getParagraphs();
                    for (IParagraph paragraph : paragraphs) {
                        IPortionCollection portions = paragraph.getPortions();
                        for (IPortion portion : portions) {
                            IPortionFormat portionFormat = portion.getPortionFormat();
                            String fontName = "";
                            IFontData fontData = portionFormat.getEastAsianFont();
                            if (fontData != null) {
                                fontName = fontData.getFontName();
                                if (StringUtils.isEmpty(fontName) || "Arial".equalsIgnoreCase(fontName)) {
                                    fontData = portionFormat.getLatinFont();
                                    if (fontData != null) {
                                        fontName = fontData.getFontName();
                            System.out.println("the font family of this portion is" + fontName);



Thank you for posting the query. I opened the presentation file you provided and found no text items in Song Ti font. I found SimSun and Times New Roman fonts applied. Could you please check it and confirm?

Also, please check the issue with the latest version of Aspose.Slides. If the problem persists, please share and specify the folowing:

  • your output text for this code example
  • JDK version you used
  • OS version on which the problem occurs

Yes, the source file only uses Song Ti (maybe because of the font difference you recognize as SimSun, but it is not important) and Times New Roman font, and I used the aspose-slide.21.5 version, which was recognized The font is only the Microsoft Yahei font, which caused my original file to use spaces to lose the corresponding effect of the content, because the font is inconsistent and the width of the space is too large. The picture below is a comparison between the source file and the result obtained using the method submitted on July 21. It can be clearly seen that the Song Ti of the source file is recognized as Microsoft Yahei or Times New Roman. The operating system I use Is winds10
fontQue.jpg (247.1 KB)

You should use the getEffective method to validate the final defined formats because format values may be unspecified and may be inherited from parent elements. For example, the text portion format can be inherited from the paragraph format that can be inherited from the text style, and so on. Please try to use the getEffective method like this:

// IPortionFormat portionFormat = portion.getPortionFormat();
IBasePortionFormatEffectiveData portionFormat = portion.getPortionFormat().getEffective();

My output: output.png (6.5 KB)

Documents: Shape Effective Properties
API Reference: PortionFormat class

I tried the method you provided, but the problem still exists. If the source file is SongTi, the recognition result is still Microsoft Yahei. When I change SongTi to Kaiti, the recognition result is correct. And I found a strange phenomenon. When I was reading the content with the font of SongTi, the language Id of this part was zh-CN. The result obtained by using the method of obtaining East Asian fonts was Microsoft Yahei, but the result obtained by using the method of obtaining Latin fonts It is SimSun, this phenomenon may be helpful to your solution.fontFamily.jpg (112.8 KB)
fontFamilyBug1.jpg (237.8 KB)

Could you share your SongTi font from the machine where this problem occurs to investigate this issue further, please?

Of course, the attachment is the font file I used in the source file
simsun.7z (6.4 MB)

Thank you for sharing the font. I will answer you as soon as possible.

I used the code example below for your presentation:

IBasePortionFormatEffectiveData portionFormat = portion.getPortionFormat().getEffective();
System.out.println("Text: " + portion.getText());
System.out.println("Language Id: " + portionFormat.getLanguageId());
System.out.println("East asian font: " + portionFormat.getEastAsianFont());
System.out.println("Latin font: " + portionFormat.getLatinFont());

and received the next output for Windows: output.png (26.4 KB)

Song Ti is the Chinese font and the zh-CN language tag corresponds to the “Mainland China” language. Could you please clarify what is wrong?

It looks like the font substitution occurs on your side. This can happen when the font is not available on your machine. Please check accessibility for this font (try to read the font file in your application, for example). Also, please set a warning callback for presentation loading as shown below and share your output warnings:

LoadOptions options = new LoadOptions();
Presentation presentation = new Presentation(dataPath + "font.pptx", options);

Documents: Getting Warning Callbacks for Fonts Substitution in Aspose.Slides
API Reference: IWarningCallback interface