Calculated Page Number in Page Header

Hello,
We are evaluating the aspose words.net product, we are facing a scenario we cannot resolve, it’s the last thing we should test before purchasing the packing, but we can’t make it done correctly.

We would like to create a document consists of N pages, and the PageNo we would like to put on every page is calculated using a formula related to our business, for example the first page in the document may have the number 100 and the next page have the number 1, our question is how to accomplish this scenario?

Also we have another value we would like to put it in the header, it’s a value changing according to how many pages in the document, so if we have a document consisting of 8 pages, the value for the first 3 pages maybe xx and for the last 5 pages maybe yy, this is based on some conditions.

What we are looking for is something that’s firing on the evaluation of each header in every page, we will evaluate our conditions and put the correct value for the page.

Attached is a sample document we are using in the demo the SessionText field is replaced in the runtime with alot of text which make the document have N Pages. We would like to call a C# function/method on every page to determine the correct value for both “BookNo” and “PageNo”

Regards,
Ahmed

Hi Ahmed,

Thanks for your inquiry. The contents of header and footer display on all pages of document’s section. You can use combination of IF, PAGE, and DOCVARIABLE fields to achieve your requirements. We have modified the demo.docx and attached it with this post. Please check the fields in the header of document. Hope this helps you.

var doc = new Document(MyDir + "Demo.docx");
doc.Variables.Add("CurrentBookNo", "1");
doc.UpdateFields();
doc.Save(MyDir + "output.docx");

Hello,
Am trying to put an “Evaluated Expression” in the else of the if condition but I can’t do it, in order to accomplish my scenario I would like the else of the if condition to be an evaluated expression,
am trying to write a formula looks like the following:
{ IF 1 > 100 "1" "(PAGE + DOCVARIABLE CurrentPageNo) " }

I would like the bold part to be an expression like above. That’s the way to get dynamic result of the IF condition, otherwise it won’t work, if you have another point of view, please let me know.

Hi Ahmed,

Thanks for your inquiry. Please use the attached modified document to get the desired output. Hope this helps you.

var doc = new Document(MyDir + "Demo (1).docx");
doc.Variables.Add("CurrentBookNo", "100");
doc.UpdateFields();
doc.Save(MyDir + "output.docx");

Hello,
thanks for the help it works fine now, do you have a manual/reference for writing formula expression ?

Regards,
Ahmed

Hi Ahmed,

Thanks for your inquiry. The FieldFormula class implements the = (formula) field. Please refer to the following article. Hope this helps you.

Working with Fields