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

Free Support Forum - aspose.com

How to retrieve headings from Word document


I have a Word document with some headings, which I want to export. I’ve tried the following without luck:


I need the name of the headline, which page it is on and where it is placed in the tree. So for my attached test document I need something like this:

1 Heading one
1.1 Heading sub one
1.2 Another heading sub one
2 Heading Two
2.1 Heading sub two
2.1.1 Heading sub tow child

My overall goal and needs is to convert the word document to a PDF and add the headlines as bookmarks.

Test doc for Aspose.zip (12.0 KB)


Thanks for your inquiry. In your case, we suggest you please iterate over the paragraphs of document and get paragraph’s style using Paragraph.ParagraphFormat.StyleName property. The headings in your document have styles “Heading 1”, “Heading 2” and “Heading 3”.

If you want to get the page number of Paragraph node, you can use Paragraph.ParagraphFormat.StyleName method. This method returns the page number of node.

In this case, you can use OutlineOptions.HeadingsOutlineLevels property as shown below to get the desired output.

Document doc = new Document(MyDir + "Test doc for Aspose.docx");
PdfSaveOptions options = new PdfSaveOptions();
options.OutlineOptions.HeadingsOutlineLevels = 9;
doc.Save(MyDir + "18.5.pdf", options);

If you still face problem, please share some more detail about your query along with expected output PDF. We will then provide you more information on it.