Get the Font Size of a Substituted Font for a PowerPoint Presentation in Java

Hi,

Provide a solution in java to get the font size of the substituted font that was substituted using below rules,

slidesFontSettings = new FontSubstRuleCollection();
IFontSubstRule fontSubstituteRule = new FontSubstRule(new FontData(entry.getKey()), new FontData(entry.getValue()), FontSubstCondition.WhenInaccessible);
slidesFontSettings.add(fontSubstituteRule);

@aakanksha76

To retrieve the font size of a substituted font in Java using Aspose.Slides, you can follow these steps:

  1. Set Up Font Substitution Rules: First, you need to define your font substitution rules using the FontSubstRuleCollection and IFontSubstRule. This is where you specify which fonts to substitute when they are inaccessible.

  2. Load the Presentation: Use the Presentation class to load your PowerPoint file.

  3. Access Font Substitution Info: After loading the presentation, you can access the font substitution information to get details about the original and substituted fonts.

  4. Retrieve Font Size: You can then retrieve the font size of the substituted font using the appropriate method.

Here is a sample code snippet demonstrating these steps:

import com.aspose.slides.FontSubstitutionInfo;
import com.aspose.slides.Presentation;
import com.aspose.slides.FontData;
import com.aspose.slides.FontSubstRule;
import com.aspose.slides.FontSubstRuleCollection;
import com.aspose.slides.FontSubstCondition;

public class FontSubstitutionExample {
    public static void main(String[] args) {
        // Define your document directory
        String dataDir = "Your Document Directory";

        // Load the presentation
        Presentation pres = new Presentation(dataDir + "PresFontsSubst.pptx");

        // Create font substitution rules
        FontSubstRuleCollection slidesFontSettings = new FontSubstRuleCollection();
        FontData originalFont = new FontData("OriginalFontName");
        FontData substitutedFont = new FontData("SubstitutedFontName");
        IFontSubstRule fontSubstituteRule = new FontSubstRule(originalFont, substitutedFont, FontSubstCondition.WhenInaccessible);
        slidesFontSettings.add(fontSubstituteRule);

        // Iterate through font substitutions and get font size
        for (FontSubstitutionInfo fontSubstitution : pres.getFontsManager().getSubstitutions()) {
            System.out.println("Original Font: " + fontSubstitution.getOriginalFontName());
            System.out.println("Substituted Font: " + fontSubstitution.getSubstitutedFontName());
            // Assuming you have a method to get font size
            // int fontSize = getFontSize(fontSubstitution.getSubstitutedFontName());
            // System.out.println("Font Size: " + fontSize);
        }

        // Dispose of the presentation object
        if (pres != null) pres.dispose();
    }

    // Placeholder for a method to get font size
    // private static int getFontSize(String fontName) {
    //     // Implement logic to retrieve font size based on font name
    // }
}

In this code, replace "OriginalFontName" and "SubstitutedFontName" with the actual font names you are working with. The method to retrieve the font size (getFontSize) is a placeholder and should be implemented based on your specific requirements or available methods in the Aspose.Slides API.

This approach allows you to manage font substitutions effectively while also enabling you to access font size information as needed.

For more detailed information on font management and substitution in Aspose.Slides, you can refer to the official documentation here.

Sources:
[1]: Fonts Substitution in Java PowerPoint | Aspose.Slides Java PowerPoint …

@aakanksha76,
You have already asked this question here. Please do not duplicate forum threads in the future.