Attempting to set font and size of "numbering" elements

I am trying to set the font and size of the page numbering of a generated word document.

I am unable to set the font and size of the text for the "numbering" elements.


(Example of how I want it to look)


Company Name



Unauthorized use or reproduction is prohibited

Page 1 of 1


I tried the "numbering" as IWTextRange so I could set the font and size (like I did with the contents of cell 2), but they come out on different lines (example below) and would not align right. I had to add the "numbering" elements as an IWParagraph to keep them all on one line. 


So at this point its choice between font and size or alignment and wrapping.


(Example of what it looks like when "numbering" elements are an IWTextRange)


Company Name



Unauthorized use or reproduction is prohibited

Page

1

of

1


(Example of what it looks like when "numbering" elements are an IWParagraph)


Company Name



Unauthorized use or reproduction is prohibited

Page 1 of 1


Below is my code.


private void AddFooter(IWSection section)
{
// Add a new table to the header
IWTable table = section.HeadersFooters.Footer.AddTable();
// Set no border
table.TableFormat.Borders.BorderType = BorderStyle.None;
// Set border line for top
table.TableFormat.Borders.Top.BorderType = BorderStyle.Single;

// Inserting table with 2 rows and 3 columns
table.ResetCells(2, 3);

#region Owner and Usage
// Add text to row 1, cell 2
IWTextRange textRange = table[0, 1].AddParagraph().AppendText($"Property of {Application.AppSettings("CompanyName")}");
AlignTableCell(table[0, 1], HorizontalAlignment.Center);
SetHeaderFooterFont(textRange);

// Add text to row 2, cell 2
textRange = table[1, 1].AddParagraph().AppendText("Unauthorized use or reproduction is prohibited");
AlignTableCell(table[1, 1], HorizontalAlignment.Center);
SetHeaderFooterFont(textRange);
#endregion

#region Page Numbering
// Add text to row 2, cell 3
IWParagraph paragraph = table[1, 2].AddParagraph();
paragraph.AppendText("Page ");
AlignTableCell(table[1, 2], HorizontalAlignment.Right, VerticalAlignment.Bottom);

WField field = (WField)paragraph.AppendField("Page", FieldType.FieldPage);
AlignTableCell(table[1, 2], HorizontalAlignment.Right, VerticalAlignment.Bottom);

paragraph.AppendText(" of ");
AlignTableCell(table[1, 2], HorizontalAlignment.Right, VerticalAlignment.Bottom);

field = (WField)paragraph.AppendField("NumPages", FieldType.FieldNumPages);
AlignTableCell(table[1, 2], HorizontalAlignment.Right, VerticalAlignment.Bottom);
#region Page Number Settings
section.PageSetup.RestartPageNumbering = true;
section.PageSetup.PageStartingNumber = 1;
section.PageSetup.PageNumberStyle = PageNumberStyle.Arabic;
#endregion Page Number Settings
#endregion
}


private void AlignTableCell(WTableCell cell, HorizontalAlignment hAlign, VerticalAlignment vAlign = VerticalAlignment.Top)
{
cell.CellFormat.VerticalAlignment = vAlign;
cell.Paragraphs[0].ParagraphFormat.HorizontalAlignment = hAlign;
}
private void SetHeaderFooterFont(IWTextRange textRange)
{
textRange.CharacterFormat.FontName = "Open Sans";
textRange.CharacterFormat.FontSize = 8;
textRange.CharacterFormat.CharacterSpacing = .5f;
}

Thanks for any assistance you can offer,

Matt





3 Replies

MR Manikandan Ravichandran Syncfusion Team October 13, 2021 09:24 AM UTC

Hi Matthew,

Thank you for contacting Syncfusion support.

From the given details, we have found that your requirement is to set font name and font size to the page number paragraph. We have created a sample with your code snippet and modified your code to achieve your requirement.

The sample can be download from the below link.
https://www.syncfusion.com/downloads/support/forum/169604/ze/ConsoleAppBase_F169604-1005191190

In this sample, we have iterated the page number paragraph and get text ranges and apply font size and font name.

Please let us know if you have any other queries.

Regards,
Manikandan Ravichandran
 



MG Matthew Gulick October 15, 2021 02:55 PM UTC

Thanks,

That did the trick.



AA Anitha Azhagesan Syncfusion Team October 18, 2021 07:29 AM UTC

Hi Matthew, 
  
Thanks for the update. We are glad to know that your reported issue has been resolved at your end. Please let us know if you require any other assistance. 
  
Regards, 
Anitha 


Loader.
Up arrow icon