Create toc insert page

Hello
We are creating TOC and LOT using this code below. We don’t have issue if they are in single page. However when TOC is exceeding one page, page number of TOC items is not showing correct number. However corresponding link is going to correct destination. Please find attached input and output files. In generated file, you can see that Link of “Page 2” is linked to page 5 correctly. However its page number is shown as 4
Downloads.zip (733.5 KB)

    public static void CreateTOCFromBookmarksFixRaj(String sourcePath, String OutputPath)
    {
        Document myDocument = new Document(sourcePath);
        TocInfo tocInfo = new TocInfo();
        Aspose.Pdf.Page tocPage = myDocument.Pages.Insert(1);
        tocPage.TocInfo = tocInfo;

        TextFragment titleFrag = new TextFragment();
        titleFrag.Text = "TABLE OF CONTENTS";
        tocInfo.Title = titleFrag;
        for (int i = 1; i <= 30; i++)
        {
            Aspose.Pdf.Heading heading2 = new Heading(1);
            TextSegment segment2 = new TextSegment();
            heading2.TocPage = tocPage;
            heading2.TextState.LineSpacing = 30;
            segment2.Text = "Page  " + i ;
            heading2.DestinationPage = myDocument.Pages[i];
            heading2.Top = myDocument.Pages[i].Rect.Height;
            heading2.Segments.Add(segment2);
            tocPage.Paragraphs.Add(heading2);
        }


        tocInfo = new TocInfo();
        tocPage = myDocument.Pages.Insert(2);
        tocPage.TocInfo = tocInfo;

        titleFrag = new TextFragment();
        titleFrag.Text = "LIST OF TABLES";
        tocInfo.Title = titleFrag;
        for (int i = 1; i <= 30; i++)
        {
            Aspose.Pdf.Heading heading2 = new Heading(1);
            TextSegment segment2 = new TextSegment();
            heading2.TocPage = tocPage;
            heading2.TextState.LineSpacing = 30;
            segment2.Text = "Table  " + i;
            heading2.DestinationPage = myDocument.Pages[i];
            heading2.Top = myDocument.Pages[i].Rect.Height;                    
            heading2.Segments.Add(segment2);
            tocPage.Paragraphs.Add(heading2);
        }
        myDocument.Save(OutputPath);

    }

@crshekharam

We were able to notice the issue in our environment while testing the scenario with Aspose.PDF for .NET 20.12. It seems like the problem is due to auto generation of next page when TOC is exceeding the page length. For further investigation, we have logged a ticket as PDFNET-49211 in our issue tracking system. We will look into its details and keep you posted with the status of its rectification. Please be patient and spare us some time.

We are sorry for the inconvenience.