We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to change the font size/ font name of the above result ?

       IWParagraph header = section.HeadersFooters.Header.AddParagraph();
                            header.AppendText("Site: ");
                            header.AppendField("CurrentPageNumber", FieldType.FieldPage);
                            header.AppendField("TotalNumberOfPages", FieldType.FieldNumPages);

How to change the font size/ font name of the above result, the result text is "Site 1/12"

7 Replies

VR Vijay Ramachandran Syncfusion Team October 13, 2016 07:05 AM UTC

Hi Customer,

Thank you for using Syncfusion products.

You can set font name and font size for the text using the text range character format property. Kindly use the following code snippets instead of the given code snippet to set font name and font size. In this code snippet the highlighted code set the font name and size for the text.
      IWParagraph header = section.HeadersFooters.Header.AddParagraph(); 
      IWTextRange textRange = header.AppendText("Site: "); 
      //Set font name and font size for the text ranage 
      textRange.CharacterFormat.FontName = "Calibri"; 
      textRange.CharacterFormat.FontSize = 12; 
      IWField field = header.AppendField("CurrentPageNumber", FieldType.FieldPage); 
      field.CharacterFormat.FontName = "Calibri"; 
      field.CharacterFormat.FontSize = 12; 
      textRange = header.AppendText("/"); 
      textRange.CharacterFormat.FontName = "Calibri"; 
      textRange.CharacterFormat.FontSize = 12; 
      field = header.AppendField("TotalNumberOfPages", FieldType.FieldNumPages); 
      field.CharacterFormat.FontName = "Calibri"; 
      field.CharacterFormat.FontSize = 12; 

Please refer the following UG documentation link for more details:

Let us know if you have any concern.

Vijay R

NT New Tester October 13, 2016 07:44 AM UTC

I still have the same font and font size

NT New Tester October 13, 2016 07:52 AM UTC

Sorry, you are right.

PG Pon Geetha A J Syncfusion Team October 13, 2016 09:02 AM UTC

Hi Customer, 
We are glad that our solution worked. 

JA Jochen Albrecht April 19, 2018 02:52 PM UTC

With version

IWField field = paragraph2.AppendField("Page", FieldType.FieldPage);
field.CharacterFormat.FontSize = 6;

the fontsize within IWField will not change...

With IWTextRange it is ok.

IWTextRange textrange = paragraph0.AppendText("TEST");
textrange.CharacterFormat.FontSize = 6;

MJ Mohanaselvam Jothi Syncfusion Team April 20, 2018 12:04 PM UTC

Hi Jochen,

Thank you for your update.

From v16.1.0.24, the entire field code is included in Document Object Model (DOM). Hence the adding a field will automatically include below elements in DOM,

   1. WField -- represents the starting of Field.
   2. ParagraphItem – represents the Field code.
   3. WFieldMark –represents the Field separator.
   4. ParagraphItem – represents the Field result.
   5. WFieldMark – represents the end of Field

Please refer the below UG documentation link to know about migration changes in DocIO:

To achieve your requirement, we suggest you to set font size for Field and its paragraph items.
Please refer the below code snippets to achieve your requirement using DocIO:
IWField field = paragraph2.AppendField("Page", FieldType.FieldPage); 
IEntity entity = field; 
//Iterates to sibling items until Field End 
while (entity.NextSibling != null) 
    if (entity is WTextRange) 
        //Sets character format for text ranges. 
        (entity as WTextRange).CharacterFormat.FontSize = 6;     
    else if ((entity is WFieldMark) && (entity as WFieldMark).Type == FieldMarkType.FieldEnd) 
    entity = entity.NextSibling; 

Please let me know if you have any other questions.

Mohanaselvam J

JA Jochen Albrecht April 23, 2018 07:48 AM UTC


thanks. That´s the way...


Live Chat Icon For mobile
Up arrow icon