Error in displaying total Page number using $p of $P

I encountered this problem of trying to put in page number to the footer.

In my subroutine, I called SetupFooter to setup for Footer with Content as “Page $p of $P”. I’ve set IsSymbolReplaceable to true. (See the Subrountine below)

But strange thing is the $p is replaced correctly by the page number and the total Page $P is not displayed correctly. Instead $P is not replaced by total page at all.

Is this a problem here ?

- - - - - - - - - - - - -


Private Sub SetupFooter(ByRef section As Section, _
ByVal fontName As String, ByVal fontSize As String, ByVal fontColor As System.Drawing.Color)
Dim footer As New HeaderFooter(section)
Dim footerTxt As Text = New Text(footer)
footer.Paragraphs.Add(footerTxt)
Dim footerSeg As Segment = New Segment(footerTxt)
footerTxt.Segments.Add(footerSeg)
footerSeg.IsSymbolReplaceable = True
footerSeg.Content = “Page $p of $P”
footerSeg.TextInfo.FontName = fontName
footerSeg.TextInfo.FontSize = fontSize
footerSeg.TextInfo.Color.ColorSpaceType = ColorSpaceType.Rgb
footerSeg.TextInfo.Color.RgbColorSpace = fontColor
footerSeg.TextInfo.Alignment = AlignmentType.Center
section.OddFooter = footer
section.EvenFooter = footer
End Sub

Dear tanlhwa,

Thanks for your consideration.

Please download hot fix in thread New Release 1.5 and Its Hot Fixes.

Hi ,
For me $P is not geting replaced by the total number of pages but $p works fine.It used to work fine in stream mode,but when i changed to write direct to file mode…I am facing this issue.Please advice

Hello Varsha,

When using $P in Direct to File mode, the symbol is not replaced at runtime and it's a known issue. I am afraid we might not be able to fix this problem due to design constraints as $P represents the total number of pages in a document and until or unless the document is saved, we cannot be certain about the number of pages that will be included in PDF document. We apologize for your inconvenience.

In case you are using the new Merged API of Aspose.Pdf for .NET v.6.0.0, you may try using Aspose.Pdf.Facades namespace. Please visit the following link for more information on Add Page Number in a PDF File (Facades). Please notice that you can only use this approach once the PDF file is already generated.

FYI, Aspose.Pdf.Generator namespace contains the classes that can be used to generate PDF document from scratch. Whereas Aspose.Pdf.Facades namespace contains the classes that can be used to manipulate/edit pre-existing PDF documents. In the event of any further query, please feel to contact.