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

Free Support Forum - aspose.com

Table of Contents and Index was outside the bounds of the array

Im trying to add a TOC to a PDF document with 15 pages. When I add any heading to the TOC I get ‘Index was outside the bounds of the array.’ wqhen the pdf is created. If I just add text the TOC adds ok, but as it isnt a heading I dont get the page numbers etc.


What I mean is:

tocPage.Paragraphs.Add(new Heading(1) { Text = “foo” });

does not work, but

tocPage.Paragraphs.Add(new TextFragment(“foo”));

does work.

Any ideas?

Hi There,


Thanks for contacting support.

Please use following sample code snippet. Hopefully it will server your purpose. You need to add TextFragment in Heading Object.

C#

Aspose.Pdf.Heading heading = new Aspose.Pdf.Heading(1);
TextSegment segment = new TextSegment();
heading.TocPage = tocPage;
heading.Segments.Add(segment);
// Specify the destination page for heading object
heading.DestinationPage = doc.Pages[1];
// Destination page
heading.Top = doc.Pages[i + 1].Rect.Height;
// Destination coordinate
segment.Text = “FOO”;
// Add heading to page containing TOC
tocPage.Paragraphs.Add(heading);

If you still face any issue, please share your full sample code for further assistance.

We are sorry for the inconvenience.

Best Regards,