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

Free Support Forum - aspose.com

Change font in a textframe

Hi,

I need to switch between different fonts in a single textframe. I like to write a headline in bold and a description without bold. I tried the following:

// This shape is a text placeholder i selected
IAutoShape iAutoShape = (IAutoShape)shape;
// start with no bold
iAutoShape.TextFrame.Text += “TESTNoBold”;

//use the textframe to get font information
ITextFrame tf1 = iAutoShape.TextFrame;

// Accessing the first Paragraph
IParagraph para1 = tf1.Paragraphs[0];

// Accessing the first portion
IPortion port1 = para1.Portions[0];

// Set font to Bold
port1.PortionFormat.FontBold = NullableBool.True;

iAutoShape.TextFrame.Text += “TESTBold”;

// Set font to back to no bold
port1.PortionFormat.FontBold = NullableBool.False;
iAutoShape.TextFrame.Text += “TESTNoBold”;

Could you point me in the right direction? Do i need more paragraphs?
Thanks

Fixed it by myself, sorry
here is a sample:

IAutoShape iAutoShape = (IAutoShape)shape;
Paragraph temp = new Paragraph();
Portion noBold = new Portion();
noBold.PortionFormat.FontBold = NullableBool.False;

Portion bold = new Portion();
bold.PortionFormat.FontBold = NullableBool.True;

temp.Portions.Add(noBold);
temp.Text = “No Bold Text”;

Paragraph temp2 = new Paragraph();
temp2.Portions.Add(bold);
temp2.Text = “Bold Text”;

iAutoShape.TextFrame.Paragraphs.Add(temp);
iAutoShape.TextFrame.Paragraphs.Add(temp2);

@mapro2,

It’s good to know you have figured out the issue. I suggest you to please visit this documentation link for your convenience just in case if you require it.