Problem with TOC in PDF

Hi, I tried to create TOC bigger than one page. The problem is it done, but TOC appears in reverse order. I mean the last page is first, the first is last. I created the code for reproducing it.

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.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();
             
         }

         document.Save("C:\\Temp\\output.pdf");
    
    }
}

}

@Arek_Slowik

Please check the attached output PDF that has been generated at our end using your code snippet with Aspose.PDF for .NET 21.5. We were unable to get the reverse order of pages inside it. Could you please share an annotated screenshot to elaborate on the issue that you are facing actually so that we can further proceed to assist you.

simpletoc.pdf (29.7 KB)

Hi thanks for your response. That is how looks my pdf generated with my codeoutput.pdf (29.6 KB)
I have Aspose.PDF, Version=19.1.0.0,

@Arek_Slowik

Would you please try to test the scenario using the latest version of the API as we tested using it and did not notice any issue in the output PDF. Please note that it is always recommended to use the latest version as it contains more fixes and improvements. Furthermore, the support is also provided on the basis of the latest version usage. In case you notice any issue with the latest version of the API, please feel free to let us know.

Hi, I used the latest version and problem solved, thanks a lot

1 Like