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

Free Support Forum - aspose.com

Multi-page TOC in PDF is only counted as 1 page

When adding a TOC page to my PDF document, I realised that if the TOC is longer than 1 page, all TOC pages are still counted as 1.

This can be easily reproduced by the following code:

var document = new Document();
var tocPage = document.Pages.Add;
tocPage.TocInfo = new TocInfo();
for (var i = 0; i < 50; i++)
{
    var page = document.Pages.Add();
    page.AddStamp(new PageNumberStamp());
    tocPage.Paragraphs.Add(new Heading(1)
    {
        TocPage = tocPage,
        DestinationPage = page,
        Text = "page",
        Margin = new MarginInfo(0, 20, 0, 20)
    });
}

The generated PDF should have a TOC of 3 pages, however the page number on the page after TOC still says “2”.

I’d like to know if there’s a way to correctly count multi page TOC.

@leon.zhou

This is default behavior of TOC pages. If you can create different file with Adobe Acrobat then share the file here as your desired output for our investigations.

@mudassir.fayyaz

What I really want to achieve was to have proper page number at the bottom of each page, including the TOC pages.

This doesn’t seem to be possible, example code below:

var document = new Document();
var tocPage = document.Pages.Add();
tocPage.TocInfo = new TocInfo();
for (var i = 0; i < 50; i++)
{
    var page = document.Pages.Add();
    tocPage.Paragraphs.Add(new Heading(1)
    {
        TocPage = tocPage,
        DestinationPage = page,
        Text = "page",
        Margin = new MarginInfo(0, 20, 0, 20)
    });
}

// Add page number stamp to every page in the document.
foreach (var page in document.Pages)
{
    page.AddStamp(new PageNumberStamp());
}

Is page numbering not supported for TOC pages at all?

You mentioned that counting all TOC pages as 1 single page is the default behaviour, and requested creating a different file with Adobe Acrobat with the desired result I wanted. However, not even Adobe Acrobat Pro DC has the feature of creating TOC, as discussed in this Adobe community thread: https://community.adobe.com/t5/acrobat-sdk-discussions/toc-in-adobe-acrobat-pro-dc/m-p/8386354.

Just quoting what the Adobe Community Professional said as why Acrobat doesn’t have the TOC feature built-in:

TOC is very basic task that any reasonably good content creator should be able to do. But Acrobat is a content distribution application so that after you have your content created you can distribute it safely into many many hands as a PDF.

Nonetheless, I have attached a PDF with TOC and proper page number at the bottom of each page as an example. This PDF was created in Microsoft Word: Contents.pdf (82.7 KB)

@leon.zhou

We are afraid this can not be created using Aspose.PDF API. A ticket with ID PDFNET-50699 has been created in our issue tracking system to further investigate the issue on our end. This thread has been linked with the issue so that you may be notified once the feature will be supported.