Free Support Forum - aspose.com

Issue with TOC Indent Issue

Hi,

I have seen when a TOC Name is bigger the toc page number gets cut at the end, is there a way to rap it to the next line and properly alligned.

Regards,

@nihhhs

Thanks for contacting support.

I have tested the scenario by following code snippet while using Aspose.Pdf for .NET 17.7 and I was unable to notice the issue that you have mentioned. For your reference, I have attached an output file as well, which was generated by below code snippet.

Document doc = new Document();
Page _tocPage = doc.Pages.Add();
TocInfo tocInfo = new TocInfo { FormatArrayLength = 3 };
_tocPage.TocInfo = tocInfo;
doc.Pages.Add();
for (int i = 0; i < 10; i++)
{
 Heading heading = new Heading(1)
 {
  Text = "Hello" + i
 };
 doc.Pages[2].Paragraphs.Add(heading);
}
doc.ProcessParagraphs();
for (int i = 0; i < 10; i++)
{
 TextFragmentAbsorber absorber = new TextFragmentAbsorber("Hello" + i);
 doc.Pages.Accept(absorber);
 if (absorber.TextFragments.Count > 0)
 {
  Aspose.Pdf.Heading heading2 = new Aspose.Pdf.Heading(i == 0 ? 1 : i == 1 ? 2 : 3);
  TextSegment segment2 = new TextSegment();
  heading2.TocPage = _tocPage;
  heading2.Segments.Add(segment2);
  heading2.DestinationPage = absorber.TextFragments[1].Page;
  heading2.Top = absorber.TextFragments[1].Page.Rect.Height;
  segment2.Text = absorber.TextFragments[1].Text + "123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 ";
  _tocPage.Paragraphs.Add(heading2);
 }
}
doc.Save(dataDir + @"TOC_LargeText.pdf"); 

TOC_LargeText.pdf (4.2 KB)

Would you please share the sample document along with working code snippet that you are using to generate the PDF, so that we can test the scenario again in our environment and address it accordingly.