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

Free Support Forum - aspose.com

Table of Contents

Hi,

while I’m trying to create a table of contents (toc) page I get a strange behaviour with the numbering.
The headings numbering is reverse. First page gets number from last page and so on and therefore the toc list is created from end to the beginning.
Am I doing something wrong with the toc creation?
Attached some screenshots and Code.

Thank you


public static void ToC_Create ( )
{
Document doc = new Document( );
Page toc = doc.Pages.Add( );
toc.PageInfo = new PageInfo
{
Width = PageSize.A4.Width,
Height = PageSize.A4.Height,
IsLandscape = false,
Margin = new MarginInfo( 64, 28, 42, 85 )

TocInfo tocInfo = new TocInfo( );
TextFragment title = new TextFragment( “Table of Contents” );
title.TextState.FontSize = 20;
title.TextState.FontStyle = FontStyles.Bold;
title.TextState.HorizontalAlignment = HorizontalAlignment.Left;

tocInfo.Title = title;
toc.TocInfo = tocInfo;

Page page1 = doc.Pages.Add( );
toc.PageInfo = new PageInfo
{
Width = PageSize.A4.Width,
Height = PageSize.A4.Height,
IsLandscape = false,
Margin = new MarginInfo( 64, 28, 42, 85 )
};

Page page2 = doc.Pages.Add( );
toc.PageInfo = new PageInfo
{
Width = PageSize.A4.Width,
Height = PageSize.A4.Height,
IsLandscape = false,
Margin = new MarginInfo( 64, 28, 42, 85 )
};

var heading1 = new Heading( 1 );
heading1.Text = “Heading 1”;
heading1.IsAutoSequence = true;
heading1.IsInList = true;
heading1.Level = 1;
heading1.TocPage = toc;
page1.Paragraphs.Add( heading1 );
string text1 = “Text1 Text1 Text1 …”;
page1.Paragraphs.Add( Tools.AddTextBlock( text1, Tools.DefaultFontSize, HorizontalAlignment.Left, Tools.TextBlockMargin ) );

var heading2 = new Heading( 2 );
heading2.Text = “Heading 1.1”;
heading2.IsAutoSequence = true;
heading2.IsInList = true;
heading2.Level = 2;
heading2.TocPage = toc;
page1.Paragraphs.Add( heading2 );
string text2 = “Text11 Text11 Text11 …”;
page1.Paragraphs.Add( Tools.AddTextBlock( text2, Tools.DefaultFontSize, HorizontalAlignment.Left, Tools.TextBlockMargin ) );

var heading3 = new Heading( 1 );
heading3.Text = “Heading 2”;
heading3.IsAutoSequence = true;
heading3.IsInList = true;
heading3.Level = 1;
heading3.TocPage = toc;
page2.Paragraphs.Add( heading3 );
string text3 = “Text2 Text2 Text2 …”;
page2.Paragraphs.Add( Tools.AddTextBlock( text3, Tools.DefaultFontSize, HorizontalAlignment.Left, Tools.TextBlockMargin ) );

using ( var fileStream = new FileStream( ResultFile, FileMode.Create ) )
{
doc.Save( fileStream );
}
}

Hi Ariel,

Thanks for using our API's.

I have tested the scenario and have managed to reproduce same problem. For the sake of correction, I have logged it as PDFNEWNET-40714 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

Hi,

Has this issue been resolved ?

I can still see this behaviour in Aspose.Pdf 17.11.0

@support-1

Thank you for getting back to us. I am afraid this issue has not been resolved yet because of some other higher priority and critical issues. I have intimated the concerned team to schedule an investigation for this issue and we will let you know once some significant progress is made. We really appreciate your patience in this regard.

Is there any kind of work around for this issue ?

I’m a little surprised this is still an issue, it seems like a fairly major bug to me… the table of contents in pdf’s being broken.

@support-1

Thanks for writing back.

I am afraid that we are not in a position to share any workaround for now. However we have recorded you concerns and shared them with the respective team to escalate the issue to next level. As soon as we receive significant feedback from their side, we will let you know. Your patience and comprehension is highly appreciated in this regard. Please spare us little time.

We are sorry for the inconvenience.