Table of Content with Headings and subheading from page

Hi, i am using aspose pdf to create an table of content for the provided pdf file.
For this i need to read headings or sub headings from each page. I have tried various methods including TextFragmentAbsorber as well but unable to get required results.

following is the code /w TextFragmentAbsorber

Document doc = new Document(sInputFilePath);
foreach (Page page in doc.Pages)
{
TextFragmentAbsorber absorber = new TextFragmentAbsorber();
page.Accept(absorber);
var _title = $“{absorber.TextFragments[2].Text} {absorber.TextFragments[3].Text}”;
tocTitles.Add(_title);
page.Dispose();
}

Here i am not able to identify whether fragment text is heading or subheading.

Shall anyone please let me know how can i extract/ read headings or subheadings from each pdf page?

@rohitCanarys

There is no particular definition of heading or subheading inside PDF document just like the header/footer. They are defined at the time of PDF generation. Once PDF is generated, they become part of the rest of the content on the page. You need to have some identifier for such content which you want to retrieve from an existing PDF document. Some bookmark like {heading1}, {subheading2}, etc. This way you would be able to extract the exact text to use it for further processing.