How can I add a font to the presentation that is not already present in the presentation’s font collection?
You can clone any existing font and change everything.
As example TextDemo has function GetFontId.
It looks for font by his name and add new one if can’t find it.
static int GetFontId(Presentation ppt, string fontName)
// Find font by name. It doesn’t check anything except font name
for (int i = 0; i < ppt.Fonts.Count; i++)
if (fontName.CompareTo(ppt.Fonts[ i ].FontName) == 0)
// Add new font by cloning first font of the presentation,
// change necessary values and return new Id
FontEntity newFont = new FontEntity(ppt, ppt.Fonts);
newFont.FontName = fontName;
I tied that with negative results. The GetFontId method does create a new FontEntity and sets it's name equal to whatever I pass in as fontName and it returns the newly created font index; however when viewed in the presentation the font appears to be Arial. Yet when the text in PowerPoint is highlighted the font name on the toolbar is blank.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
// My Sample Code:
Slide slide1 = GetSlideByPosition(pres, 1);
Shape shape = slide1.Shapes;
Paragraph para = shape.TextFrame.Paragraphs;
Portion port = para.Portions;
port.FontItalic = true;
port.FontShadow = true;
port.FontColor = Color.Green;
port.FontHeight = 55;
port.FontIndex = (short)GetFontId(pres, "Wing Dings");
Did you try “Wingdings” font name instead of “Wing Dings”?
If font not found then MS PowerPoint uses standard font substitution.
By the way, if you really need to add Wingdings font you should define
also correct values for Font.Charset and Font.Family.
int fontId = GetFontId(pres, “Wingdings”);
FontEntity font = pres.Fonts[fontId];
font.CharSet = FontCharSet.SYMBOL_CHARSET;
font.Family = FontFamily.DONTCARE;
sh.TextFrame.Paragraphs.Portions.FontIndex = (short)fontId;
I can still not get this to work. Are there any plans to possibly make this into an enum type instead of an index?
For example: sh.TextFrame.Paragraphs.Portions.FontType = FontType.WingDings;<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
By the way I have also found what maybe a bug. In past releases of Aspose.PowerPoint I could use
pres.Masters.Background.FillFormat.BackColor = Color.Plum;
to set the background color of the slide master. Now this no longer works. However I can use
pres.Masters.Background.FillFormat.ForeColor = Color.Plum;
to achieve the intended results.
Thousands of fonts exist in the world and anybody can create new fonts with any name.
How you think we can do enums for that?
I’d suggest to read msdn (or some other examples and documents on Internet) for better understanding how to work with fonts in Windows.
We had a bug with FillFormat in old versions. BackColor and ForeColor changed the same value in presentation. Now it works correctly.