public class FontsManager extends java.lang.Object implements IFontsManager
Manages fonts across the presentation.
The following example shows how to add embedded fonts to PowerPoint Presentation.// Load presentation Presentation pres = new Presentation("Fonts.pptx"); try { // Load source font to be replaced IFontData sourceFont = new FontData("Arial"); IFontData[] allFonts = pres.getFontsManager().getFonts(); for (IFontData font : allFonts) { boolean fontAlreadyEmbedded = false; IFontData[] embeddedFonts = pres.getFontsManager().getEmbeddedFonts(); for (int i = 0; i < embeddedFonts.length; i++) { if (embeddedFonts[i].equals(font)) { fontAlreadyEmbedded = true; break; } } if (!fontAlreadyEmbedded) { pres.getFontsManager().addEmbeddedFont(font, EmbedFontCharacters.All); } } // Save the presentation pres.save("AddEmbeddedFont_out.pptx", SaveFormat.Pptx); } finally { if (pres != null) pres.dispose(); }
| Modifier and Type | Method and Description |
|---|---|
void |
addEmbeddedFont(byte[] fontData,
int embedFontRule)
Adds the embedded font
|
void |
addEmbeddedFont(IFontData fontData,
int embedFontRule)
Adds the embedded font
|
IFontData[] |
getEmbeddedFonts()
Returns the fonts embedded in the presentation
|
byte[] |
getFontBytes(IFontData fontData,
int fontStyle)
Retrieves the byte array representing the font data for a specified font style and font data.
|
int |
getFontEmbeddingLevel(byte[] fontBytes,
java.lang.String fontName)
Determines the embedding level of a font from the given byte array and font name.
|
IFontFallBackRulesCollection |
getFontFallBackRulesCollection()
Represents a user's collection of FontFallBack rules for managing of collections of fonts for proper substitutions by fallback functionality
Read/write
IFontFallBackRulesCollection. |
IFontData[] |
getFonts()
Returns the fonts used in the presentation
|
IFontSubstRuleCollection |
getFontSubstRuleList()
Font substitutions to use when rendering.
|
com.aspose.ms.System.Collections.Generic.IGenericEnumerable<FontSubstitutionInfo> |
getSubstitutions()
Gets the information about fonts that will be replaced on the presentation's rendering.
|
void |
removeEmbeddedFont(IFontData fontData)
Removes the embedded font
|
void |
replaceFont(IFontData sourceFont,
IFontData destFont)
Replace font in presentation
|
void |
replaceFont(IFontSubstRule substRule)
Replace font in presentation using information provided in
FontSubstRule |
void |
replaceFont(IFontSubstRuleCollection substRules)
Replace font in presentation using information provided in collection of
FontSubstRule |
void |
setFontFallBackRulesCollection(IFontFallBackRulesCollection value)
Represents a user's collection of FontFallBack rules for managing of collections of fonts for proper substitutions by fallback functionality
Read/write
IFontFallBackRulesCollection. |
void |
setFontSubstRuleList(IFontSubstRuleCollection value)
Font substitutions to use when rendering.
|
public final IFontSubstRuleCollection getFontSubstRuleList()
Font substitutions to use when rendering.
Read/write IFontSubstRuleCollection.
getFontSubstRuleList in interface IFontsManagerpublic final void setFontSubstRuleList(IFontSubstRuleCollection value)
Font substitutions to use when rendering.
Read/write IFontSubstRuleCollection.
setFontSubstRuleList in interface IFontsManagerpublic final IFontFallBackRulesCollection getFontFallBackRulesCollection()
Represents a user's collection of FontFallBack rules for managing of collections of fonts for proper substitutions by fallback functionality
Read/write IFontFallBackRulesCollection.
Presentation pres = new Presentation(); try { // Getting of empty or preinitialized rules collection from FontsManager IFontFallBackRulesCollection rulesList = pres.getFontsManager().getFontFallBackRulesCollection(); // adding of rules to collection rulesList.add(new FontFallBackRule(0x400,0x4FF, "Times New Roman")); // or // initialization of new instance of rules collection IFontFallBackRulesCollection rulesList = new FontFallBackRulesCollection(); // adding of rules to collection rulesList.add(new FontFallBackRule(0x400,0x4FF, "Times New Roman")); // and replacing of existing collection by the new one in FontsManager pres.getFontsManager().setFontFallBackRulesCollection(rulesList); } finally { if (pres != null) pres.dispose(); }
getFontFallBackRulesCollection in interface IFontsManagerpublic final void setFontFallBackRulesCollection(IFontFallBackRulesCollection value)
Represents a user's collection of FontFallBack rules for managing of collections of fonts for proper substitutions by fallback functionality
Read/write IFontFallBackRulesCollection.
Presentation pres = new Presentation(); try { // Getting of empty or preinitialized rules collection from FontsManager IFontFallBackRulesCollection rulesList = pres.getFontsManager().getFontFallBackRulesCollection(); // adding of rules to collection rulesList.add(new FontFallBackRule(0x400,0x4FF, "Times New Roman")); // or // initialization of new instance of rules collection IFontFallBackRulesCollection rulesList = new FontFallBackRulesCollection(); // adding of rules to collection rulesList.add(new FontFallBackRule(0x400,0x4FF, "Times New Roman")); // and replacing of existing collection by the new one in FontsManager pres.getFontsManager().setFontFallBackRulesCollection(rulesList); } finally { if (pres != null) pres.dispose(); }
setFontFallBackRulesCollection in interface IFontsManagerpublic final IFontData[] getFonts()
Returns the fonts used in the presentation
getFonts in interface IFontsManagerpublic final com.aspose.ms.System.Collections.Generic.IGenericEnumerable<FontSubstitutionInfo> getSubstitutions()
Gets the information about fonts that will be replaced on the presentation's rendering.
Presentation pres = new Presentation("pres.pptx"); try { for (FontSubstitutionInfo fontSubstitution : pres.getFontsManager().getSubstitutions()) { System.out.println(fontSubstitution.getOriginalFontName() + " -> " + fontSubstitution.getSubstitutedFontName()); } } finally { if (pres != null) pres.dispose(); }
getSubstitutions in interface IFontsManagerFontSubstitutionInfo.public final IFontData[] getEmbeddedFonts()
Returns the fonts embedded in the presentation
getEmbeddedFonts in interface IFontsManagerIFontData[]public final void removeEmbeddedFont(IFontData fontData)
Removes the embedded font
removeEmbeddedFont in interface IFontsManagerfontData - Font data object IFontDatapublic final void addEmbeddedFont(IFontData fontData, int embedFontRule)
Adds the embedded font
addEmbeddedFont in interface IFontsManagerfontData - Font data object IFontDataembedFontRule - Embedded font rule EmbedFontCharacters
com.aspose.ms.System.ArgumentException - An ArgumentException can be thrown if font data is null or this font is already embedded
public final void addEmbeddedFont(byte[] fontData,
int embedFontRule)
Adds the embedded font
addEmbeddedFont in interface IFontsManagerfontData - Font data byte[]embedFontRule - Embedded font rule EmbedFontCharacters
com.aspose.ms.System.ArgumentException - An ArgumentException can be thrown if font data is null or this font is already embedded
public final void replaceFont(IFontData sourceFont, IFontData destFont)
Replace font in presentation
replaceFont in interface IFontsManagersourceFont - Source fontdestFont - Destination fontpublic final void replaceFont(IFontSubstRule substRule)
Replace font in presentation using information provided in FontSubstRule
replaceFont in interface IFontsManagersubstRule - Font substitution infopublic final void replaceFont(IFontSubstRuleCollection substRules)
Replace font in presentation using information provided in collection of FontSubstRule
replaceFont in interface IFontsManagersubstRules - Font substitution rules collectionpublic final byte[] getFontBytes(IFontData fontData, int fontStyle)
Retrieves the byte array representing the font data for a specified font style and font data.
Presentation pres = new Presentation ("Presentation.pptx"); try { // Retrieve all fonts used in the presentation IFontData[] fonts = pres.getFontsManager().getFonts(); // Get the byte array representing the regular style of the first font in the presentation byte[] fontBytes = pres.getFontsManager().getFontBytes(fonts[0], FontStyleType.Regular); } finally { if (pres != null) pres.dispose(); }
getFontBytes in interface IFontsManagerfontData - The font data object containing the information about the font FontData.fontStyle - The style of the font for which the data is to be retrieved FontStyleType.public final int getFontEmbeddingLevel(byte[] fontBytes,
java.lang.String fontName)
Determines the embedding level of a font from the given byte array and font name.
Presentation pres = new Presentation(pptxFileName); try { // Retrieve all fonts used in the presentation IFontData[] fontDatas = pres.getFontsManager().getFonts(); // Get the byte array representing the regular style of the first font in the presentation byte[] bytes = pres.getFontsManager().getFontBytes(fontDatas[0], FontStyle.Regular); // Determine the embedding level of the font int embeddingLevel = pres.getFontsManager().getFontEmbeddingLevel(bytes, fontDatas[0].getFontName()); } finally { if (pres != null) pres.dispose(); }
getFontEmbeddingLevel in interface IFontsManagerfontBytes - The byte array containing the font data.fontName - The name of the font.com.aspose.ms.System.ArgumentNullException - Thrown when fontBytes is null.Copyright © 2004-2025 Aspose Pty Ltd. All Rights Reserved.