Aspose.Pdf

Change Text Format for all Segments

We have studied in previous topics that Aspose.Pdf supports developers to save their time by adding Text paragraphs or Segments who can inherit text format settings from their parent nodes. It is also possible to override the text format settings of parent nodes in child nodes if developers need to customize any particular Text paragraph or Segment .

 

In this topic, we are going to discuss a better technique to modify the text format settings of all Segments after they are added to a Text paragraph.

 

It's a common practice to use Text.TextInfo property to modify text format settings of any Section , Text paragraph or Segment . But when all segments are added to a Text paragraph then you should not change the Text.TextInfo property directly. Instead, you should clone a new TextInfo object, change the settings of new cloned instance of TextInfo and set the Text.TextInfo to the new cloned object. This way, all Segments in the Text paragraph will adapt the text format settings.

 

Example:

 

[C#]

 

//Instantiate Text object by calling one of its overloaded constructors

//that takes an instance of section as parameter

Text t3 = new Aspose.Pdf.Text(sec1);

...

 

//Please don't use the following line, it will not affect segments in the text

//t3.TextInfo.FontSize = 16;

 

//Make a cloned object of TextInfo by calling its Clone method

TextInfo info1 = t3.TextInfo.Clone() as TextInfo;

 

//Modify the font side to 16 pt

info1.FontSize = 16;

 

//Set TextInfo property of the text paragraph to newly cloned instance "info1"

t3.TextInfo = info1;

 

[VB.NET]

 

'Instantiate Text object by calling one of its overloaded constructors

'that takes an instance of section as parameter

Dim t3 As Aspose.Pdf.Text = New Aspose.Pdf.Text(sec1)

...

 

'Please don't use the following line, it will not affect segments in the text

't3.TextInfo.FontSize = 16

 

'Make a cloned object of TextInfo by calling its Clone method

Dim info1 as TextInfo = t3.TextInfo.Clone()

 

'Modify the font side to 16 pt

info1.FontSize = 16

 

'Set TextInfo property of the text paragraph to newly cloned instance "info1"

t3.TextInfo = info1