HeaderFooter - Auto Page Numbering

I am creating a PDF file. How do I add auto page numbering to the Header / Footer? I'm using the following code snippet for the footer:

Aspose.Pdf.HeaderFooter hf1 = new Aspose.Pdf.HeaderFooter(section);
hf1.DistanceFromEdge = 20;
section.OddFooter = hf1;
section.EvenFooter = hf1;
Text text = new Text(hf1, "Page 1"); // PAGE NUMBER IS STATIC
text.TextInfo.Alignment = Aspose.Pdf.AlignmentType.Center;
hf1.Paragraphs.Add(text);

Hello Edmond,

Thanks for considering Aspose.

Please visit the following link for required information. Image & Page Number in Header/Footer section

In case it does not satisfy your requirements or you've any further query, please feel free to contact.

Thank you I added the page symbols:

Text text = new Text(hf1, "Page $p of $P");

The result:

Page 1 of $P

The $P does not get updated at run time. Any ideas?

I'm using Aspose.PDF 2009.03.25

Hello Edmond,

Please try using the latest release version of Aspose.Pdf for .NET 4.1.2 which can be accessed over this link. During my testing, I'm unable to notice the problem.

Can you please try using this version and in case you still face any problem or you've any further query, please feel free to contact.

I just realized that the $P symbol will not work for direct-to-file operations. I changed it to other file save method and it worked.

Thank you.

Hello Edmond,

I'm afraid $P is not supported in Direct-to-File mode and the information is specified over the following link Writing PDF directly. For the sake of implementation, I have logged it in our issue tracking system as PDFNET-14911. We will investigate this issue in details and will keep you updated on the status of a correction.

We apologize for your inconvenience.

Hello Edmond,

I am afraid the issue reported earlier cannot be resolved as in direct-to-file mode, $P returns the same value as $p. Because, the total number of pages is not known until all the pages are written. We would recommend you to avoid using direct-to-file mode in case you are using $P.

In case I can be of any further assistance, please feel free to contact. We apologize for your inconvenience.