We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Section Page numbering and section.PageCount

Im building a long PDF out of multiple documents. Each document is created as its own Section, then added to a Pdf.

Each section/document in the PDF needs to have its own page numbers ie, “page X of Y” where Y is the number of pages in the section/document, NOT the whole PDF. ($P will just insert the number of pages for the whole long pdf)

The X is properly inserted after finding the section.IsPageNumberRestarted option, and I THOUGHT section.PageCount would have taken care of the Y number, but it always returns 0.
Is that a bug? And if not, am I using it improperly? If it is a bug, is there a workaround?

what is the best way to get the number of pages in a section and insert that into the section footer?

thanks in advance


Thanks for contacting support.

The Section.PageCount property can display/return correct value when using called after Pdf.Save(…) method i.e. We can be certain about the number of pages once the pages are actually placed inside the PDF file and file is saved. However if you need to get the values before saving the document, then please try using following replaceable symbols.

  • $Sp Displays page number in the current section.
  • $SP Displays page count of the current section.
  • $SN Displays section index of the section in the document.

In case you still face any issue, please share the code snippet so that we can test the scenario at our end. We are sorry for this inconvenience.

thanks, $SP worked perfectly and now I see that in the docs. Not sure how I missed that option in the docs the first time!

Hi there,

Thanks for your feedback. It is good to know that you have managed to get your desired results.

Please keep using our APIs and feel free to ask any question or concern. We will be more than happy to extend our support.

Best Regards,