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

Free Support Forum - aspose.com

PDF Hanging Indent

We've recently adding hanging indent functionality to our Word documents for the TOC and section titles. We now also need to be able to create hanging indents for the TOC when creating a document via Aspose PDF.

The only examples that I can find about creating hanging indents on the forums are using the legacy Aspose.PDF.Generator class. How can I create hanging indents in a TOC using the new Apose.PDF classes?

Thanks,
David


Hi David,


Thanks for contacting support.

daveywc:
How can I create hanging indents in a TOC using the new Apose.PDF classes?

As per my understandings, you want to add indents from different level of headings in TOC. You can add different margins for each level of TOC heading to achieve that. Please check following code snippet and attached output (generated by below code) for your reference.

Document doc = new Document();<o:p></o:p>

Page _tocPage = doc.Pages.Add();

TocInfo tocInfo = new TocInfo { FormatArrayLength = 3 };

_tocPage.TocInfo = tocInfo;

for (int i = 0; i < _tocPage.TocInfo.FormatArray.Length; i++)

{

LevelFormat lf = _tocPage.TocInfo.FormatArray[i];

lf.TextState.FontSize = 10;

lf.Margin.Top = 5;

lf.Margin.Left = (i + 1) * 10;

// set indent for every level (+ 10 for every level)

lf.TextState.ForegroundColor = Color.Blue;

if (i == 0)

{

lf.LineDash = TabLeaderType.None;

lf.TextState.FontStyle = FontStyles.Bold;

lf.Margin.Top = 10;

}

if (i == 2)

{

lf.Margin.Left += 10;

}

}

doc.Pages.Add();

for (int i = 0; i < 33; i++)

{

Heading heading = new Heading(1)

{

Text = "Hello" + i

};

doc.Pages[2].Paragraphs.Add(heading);

}

doc.ProcessParagraphs();

for (int i = 0; i < 33; 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;

_tocPage.Paragraphs.Add(heading2);

}

}

doc.Save(dataDir + @"TOC_With_Indent.pdf");


In case of any further assistance, please feel free to contact us.


Best Regards,

Hi Asad,


Thanks for your reply. We understand how to do indents. What we need to add are hanging indents, so that text that wraps onto the next line can line up with the title on the previous line, rather than the left margin e.g. if we have an entry in the TOC like “3.5.16 My very, very long title that will surely wrap around to the next line because it is very, very long” then we want the text that wraps around to line up under “My very…” not with the left margin. We have achieved this in Aspose Words after a lot of trial and error. We now need to replicate the same thing in Aspose.Pdf.

Regards,

David

Hi David,


Thanks for adding more details to the scenario.

We have logged an investigation ticket as PDFNET-42800 in our issue tracking system in which we have shared your requirements and our suggested solution, so that development team can look into the details of the scenario and share their feedback accordingly. As soon as we have some results in this regard, we will let you know. Please be patient and spare us little time.


Best Regards,

Hi Asad,


Have you had any feedback from the development team?

Kind regards,

David

Hi David,


Thanks for your inquiry.

As we have recently notified the development team about the investigation, so I am afraid that they have not shared any feedback yet. Although we have recorded your concerns and intimated the relevant team about them. As soon as we have some feedback in this regard, we will let you know. Please be patient and spare us little time.

We are sorry for this inconvenience.


Best Regards,