How to set font in text frame


#1

hi

i have created a text frame ,how can i set the font to arial .


#2

Presentation.Fonts collection contains all fonts used in a presentation.
If collection doesn’t have Arial font then you should add new one by cloning any other font.

Check TextDemo demo. It contains many usefull examples. For example you can use this function:

static int GetFontId(Presentation ppt, string fontName)
{
for (int i = 0; i < ppt.Fonts.Count; i++)
if (fontName.CompareTo(ppt.Fonts[ i ].FontName) == 0)
return i;
// Add new font by cloning first font of the presentation,
// change necessary values and return new Id
FontEntity newFont = new FontEntity(ppt, ppt.Fonts[ 0 ]);
newFont.FontName = fontName;
return ppt.Fonts.Add(newFont);
}

Function returns ID of a font which can be used in Portion object.


#3

Hi,

Where can I get this TextDemo code from? I could not find it. Also using the latest jar file the code for this is somewhat different

s<br><br>tatic int GetFontId(Presentation ppt, String fontName) throws IOException
<br>{
    <br>    for (int i = 0; i < ppt.getFonts().size(); i++)<br>            if ( fontName.equals(ppt.getFonts().get(i).getFontName()) )<br>                return i;
    <br><br>FontEntity newFont = new FontEntity(ppt, ppt.getFonts().get(0));
    <br>newFont.setFontName(fontName);
    <br>int fontid = ppt.getFonts().add(newFont);
    <br>return fontid;
<br>}


Does this look correct?

Thanks.


#4

Yes, code looks correct.
The previous example is for .Net C#.