Problem with page number if TOC is bigger then one page

Hi, If I try to create PDF with TOC bigger than one page the numbers are incorrect. I used this code

using System;
using System.Linq;
using Aspose.Pdf;
using Aspose.Pdf.Text;

namespace asposeTest
{
internal class Program
{
public static void Main(string[] args)
{

        string[] titles = new string[26];
        titles[0] =
            "some very loooong name 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111aaa";
        titles[1] =
            "some very loooong name 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111bbb";
        titles[2] =
            "some very loooong name 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111cc";
        titles[3] =
            "some very loooong name 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111ddd";
        titles[4] =
            "some very loooong name 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111eee";
        titles[5] =
            "some very loooong name 222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 fff";
        titles[6] =
            "some very loooong name 222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 ggg";
        titles[7] =
            "some very loooong name 222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 hhh";
        titles[8] =
            "some very loooong name 222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 iii";
        titles[9] =
            "some very loooong name 222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 jjj";
        titles[10] =
            "some very loooong name 222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 kkk";
        titles[11] =
            "some very loooong name 222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 lll";
        titles[12] =
            "some very loooong name 222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 mmm";
        titles[13] =
            "some very loooong name 222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 nnn";
        titles[14] =
            "some very loooong name 222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 ooo";
        titles[15] =
            "some very loooong name 222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 ppp";
        titles[16] =
            "some very loooong name 222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 qqq";
        titles[17] =
            "some very loooong name 333333333333333222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 rrr";
        titles[18] =
            "some very loooong name 333333333333333333333333332222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 sss";
        titles[19] =
            "some very loooong name 333333333333333333333333333333333322222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 ttt";
        titles[20] =
            "some very loooong name 333333333333333333333333332222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 uuu";
        titles[21] =
            "some very loooong name 333333333333333333333333333222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 vvv";
        titles[22] =
            "some very loooong name 333333333333333333333333333322222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 www";
        titles[23] =
            "some very loooong name 333333333333333333333333333333332222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 xxx";
        titles[24] =
            "some very loooong name 333333333333333333333222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 yyy";
        titles[25] =
            "some very loooong name 333333333333333333333333333333333222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 zzz";

        var licLocation = "C:\\Temp\\Aspose.Total.NET.lic";
        var pdfLicense = new Aspose.Pdf.License();
        pdfLicense.SetLicense(licLocation);
        string dataDir = "C:\\Temp\\";



        Document document = new Document();
        //var tocPage = document.Pages.Add();
        var tocPage = document.Pages.Insert(1);
        TocInfo tocInfo = new TocInfo();
        TextFragment title = new TextFragment("Some text for title");
        title.Margin = new MarginInfo(0, 20, 0, 20);
        title.HorizontalAlignment = HorizontalAlignment.Center;
        title.TextState.FontSize = 22;

        // Set the title for TOC
        tocPage.TocInfo = tocInfo;
        tocInfo.IsCountTocPages = true;


        for (var i = 0; i <= titles.Length - 1; i++)
        {
            var page = document.Pages.Add();

            var table = new Table()
            {
                ColumnWidths = "400"
            };

            var tocHeading = new Heading(1);
            tocHeading.Text =
                $"{titles[i]} ({DateTime.Now.ToString("d")} - {DateTime.Now.AddHours(4).ToString("d")})";
            tocHeading.IsInNewPage = true;
            tocHeading.TocPage = document.Pages.First();

            TextSegment segment2 = new TextSegment();

            tocHeading.TocPage = tocPage;
            tocHeading.Segments.Add(segment2);

            //segment2.Text = titles[i];
            //segment2.Text = $"indeks --> {i} -- {titles[i]}";

            var heading = new Heading(1);
            heading.Text = titles[i];
            heading.IsInNewPage = false;
            heading.TextState.FontSize = 16;

            page.Paragraphs.Add(tocHeading);
            page.Paragraphs.Add(heading);

            // document.ProcessParagraphs();

        }
        PageNumberStamp pageNumberStamp = CreatePageNumberStamp(25, HorizontalAlignment.Right);
        foreach (var page in document.Pages)
        {
            pageNumberStamp.setStampId(3);
            page.AddStamp(pageNumberStamp);
        }
        document.Save("C:\\Temp\\output.pdf");

    }
    

    private static PageNumberStamp CreatePageNumberStamp(double bottomMargin, HorizontalAlignment alignment, double leftMargin = 0)
    {
        var pageNumberStamp = new PageNumberStamp
        {
            Background = false,
            BottomMargin = bottomMargin,
            LeftMargin = leftMargin,
            RightMargin = 30,
            HorizontalAlignment = alignment,
            StartingNumber = 1
        };

        //set text properties
        pageNumberStamp.TextState.Font = FontRepository.FindFont("Arial");
        pageNumberStamp.TextState.FontSize = 10.0F;
        pageNumberStamp.TextState.FontStyle = FontStyles.Bold;
        pageNumberStamp.TextState.FontStyle = FontStyles.Italic;
        pageNumberStamp.TextState.ForegroundColor = Aspose.Pdf.Color.Black;

        return pageNumberStamp;
    }
}

}

The first row jumps to 3rd page, but on this page is number 2. How to make it consitance?

@Arek_Slowik

While testing the scenario using the shared code and Aspose.PDF for .NET 21.5, we were able to notice that PageNumberStamp was added incorrectly i.e. on Page 3, it was 2. Therefore, we have logged an issue as PDFNET-50053 in our issue tracking system to further investigate this case. We will look into its details and keep you posted on the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

Hi, any update when it will be fixed?

@Arek_Slowik

We are afraid that earlier logged ticket has not been reviewed yet. As per free support model policies, it will be investigated and resolved on first come first serve basis. We will surely inform you as soon as we have some definite updates regarding its resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.

Hi, I have a license for Aspose. Can it speed up the process?

@Arek_Slowik

In order to escalate the ticket to high priority, you need to have subscription of paid support. In case you have one already, you can create a ticket in helpdesk with the reference to issue ID shared here and your issue will be raised to priority accordingly.