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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to do this: {={numpages}-1}, in DOCIO Footer?

Thread ID:





124418 Jun 8,2016 01:42 PM UTC Jun 10,2016 04:20 AM UTC WinForms 3
Tags: DocIO
Asked On June 8, 2016 01:42 PM UTC

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!

Suganya Rathinam [Syncfusion]
Replied On 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 


Replied On June 9, 2016 02:15 PM UTC


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

Suganya Rathinam [Syncfusion]
Replied On 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.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon