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.
Unfortunately, activation email could not send to your email. Please try again.

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

Thread ID:

Created:

Updated:

Platform:

Replies:

124418 Jun 8,2016 09:42 AM Jun 10,2016 12:20 AM Windows Forms 3
loading
Tags: DocIO
MikeD
Asked On June 8, 2016 09:42 AM

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 01:11 AM

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 
//{={NUMPAGES}-1} 
//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; 
        break; 
    } 
} 
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 
footer.ChildEntities.Add(paragraph); 

Regards,
Suganya
 


MikeD
Replied On June 9, 2016 10:15 AM

Suganya,

   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 12:20 AM

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.

Regards,
Suganya


CONFIRMATION

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.

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.

;