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 do this: {={numpages}-1}, in DOCIO Footer?

Hello All!  I am trying to modify the page count in my document to be one less than the actual page count because I do not want to count my cover page in the total count.  In Word 2010 all I have to do is modify the footer to be {={numpages}-1}, but for all of my efforts I cannot seem to figure out how to do this in Syncfusion DOCIO.  I have the page count in my DOCIO footer, just not the page count - 1.  Any advice would be appreciated.  Thanks!

3 Replies

SR Suganya Rathinam Syncfusion Team June 9, 2016 05:11 AM UTC

Hi Michael,

Thank you for contacting Syncfusion support.

On further analyzing, your requirement to get the pages count excluding the first page in the document can be achieved by combining the Formula field and NUMPAGES field using DocIO. Please find the following code snippets for your reference and let us know if it helps.

//Create new paragraph 
WParagraph paragraph = new WParagraph(footer.Document); 
//To get the total number of pages excluding first page, the field should be in below syntax 
//Insert the formula field to the paragraph 
WField formulafield = paragraph.AppendField("Formula", FieldType.FieldExpression) as WField; 
formulafield.FieldCode = "="; 
//Get the index of the formula field in the paragraph items. 
int fieldindex = paragraph.ChildEntities.IndexOf(formulafield) + 1; 
//Create a temporary paragraph 
WParagraph tempParagraph = new WParagraph(footer.Document); 
//Append NUMPAGES field 
tempParagraph.AppendField("", FieldType.FieldNumPages); 
for (int i = 0; i < tempParagraph.ChildEntities.Count; i++) 
    //Get the NUMPAGES field from the temporary paragraph and insert it as first operand in the formula field paragraph. 
    if (tempParagraph.ChildEntities[i] is WField && 
        (tempParagraph.ChildEntities[i] as WField).FieldType == FieldType.FieldNumPages) 
        //The NUMPAGES field is inserted at the index next to Formula field in the paragraph 
        int itemsCount = paragraph.ChildEntities.Count; 
        paragraph.ChildEntities.Insert(fieldindex, tempParagraph.ChildEntities[i]); 
        fieldindex += paragraph.ChildEntities.Count - itemsCount; 
IWTextRange text = new WTextRange(footer.Document); 
//Insert the operater and second operand to the formula field 
text.Text = " - " + 1; 
paragraph.ChildEntities.Insert(fieldindex, text); 
//Add the page number paragraph to the required footer in the document 


MI MikeD June 9, 2016 02:15 PM UTC


   I was able to get your solution to work perfectly. Thank you so much for your help!

SR Suganya Rathinam Syncfusion Team June 10, 2016 04:20 AM UTC

Hi Michael,

We are happy to hear that the provided solution resolved your problem. Please let us know if you need any further assistance. We will be happy to assist you as always.


Live Chat Icon For mobile
Up arrow icon