Page Numbering

Jun 12, 2015 at 6:06 PM
Can anyone help me insert page numbering in a footer, in the format of 'Page x of y' ?

How do I change the DocX code to enable this feature?
Jun 15, 2015 at 3:43 PM
Edited Jun 15, 2015 at 10:35 PM
It's already there...

create the doc...
(you may have to do this for doc.Footers.odd and doc.Footers.even depending on how you have the footer flags set)

doc.AddFooters();

doc.DifferentFirstPage = false;
doc.DifferentOddAndEvenPages = false;

var footPara=doc.Footers.odd.Paragraphs.First();
footPara.Alignment = Alignment.right;
footPara.AppendPageNumber(PageNumberFormat.normal);
footPara.Append(" of ");
footPara.AppendPageCount(PageNumberFormat.normal);
Jun 16, 2015 at 5:58 PM
Thank you ... that works for inserting the 'Page Number' and 'Page Count' fields. Sometimes I miss the obvious.

However, for the life of me, I can't seem to be able to change the font nor size for the 'Page Number' or 'Page Count' fields. It is whatever the Microsoft Word default is [in my case, Calibri (Body)]. When I apply the font to the paragraph, it does not change anything.
// Insert a Paragraph into the Footer.
Novacode.Paragraph p1 = document.Footers.odd.Paragraphs.First().Font(new FontFamily("Arial Narrow")).FontSize(8);
p1.Alignment = Alignment.left;
p1.Append("Company Name\t");
p1.AppendPageNumber(PageNumberFormat.normal);
p1.Append(" of ");
p1.AppendPageCount(PageNumberFormat.normal);
p1.Append("\t16 June 2015);
If I add the font afterwards, only the date gets the new font.
// Insert a Paragraph into the Footer.
Novacode.Paragraph p1 = document.Footers.odd.Paragraphs.First();
p1.Alignment = Alignment.left;
p1.Append("Company Name\t");
p1.AppendPageNumber(PageNumberFormat.normal);
p1.Append(" of ");
p1.AppendPageCount(PageNumberFormat.normal);
p1.Append("\t16 June 2015);
p1.Font(new FontFamily("Arial Narrow")).FontSize(8);
I can add the font to the individual 'Append' methods:
// Insert a Paragraph into the Footer.
Novacode.Paragraph p1 = document.Footers.odd.Paragraphs.First();
p1.Alignment = Alignment.left;
p1.Append("Company Name\t").Font(new FontFamily("Arial Narrow")).FontSize(8);
p1.AppendPageNumber(PageNumberFormat.normal);
p1.Append(" of ").Font(new FontFamily("Arial Narrow")).FontSize(8);
p1.AppendPageCount(PageNumberFormat.normal);
p1.Append("\t16 June 2015).Font(new FontFamily("Arial Narrow")).FontSize(8);
But the 'Page Number' and 'Page Count' do not change.

How do I apply font formatting to the 'Page Number' and 'Page Count' ?