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

Free Support Forum - aspose.com

How to nest bookmarks without using Headings

Hi we have been trying to nest bookmarks in aspose.word using the methods you have shown in this page http://www.aspose.com/docs/display/wordsnet/Bookmarks+in+Aspose.Words

We can get this to work no problem using the startbookmark and endbookmark methods but can you please advise us how to achieve nested bookmarks using this method.

Putting bookmark start and ends inside each other does nothing other than achieving a flat bookmark structure.

We are creating the word document first and then converting to pdf and can only achieve a flat bookmark layout.

The only way we have been able to achieve nesting is if we insert H1 tags and nest these and then set the HeadingsOutlineLevels. Using heading will not work for us as we merge in word documents inline in our document and do not wish any H1s that are currently in the merged word documents to be shown as levels of bookmarks.

Any advice will be greatly appreciated.

Hi Graeme,

Thanks for your inquiry. Please use the following code snippet to create nested bookmark. Hope this helps you.

Document doc = new Document(MyDir + “in.docx”);

DocumentBuilder builder = new DocumentBuilder(doc);


builder.Writeln("Text inside a bookmark.");


builder.Writeln("Text inside a NestedBookmark.");


builder.Writeln("Text after Nested Bookmark.");


doc.Save(MyDir + "Out.docx");

PdfSaveOptions options = new PdfSaveOptions();

options.OutlineOptions.BookmarksOutlineLevels.Add("MyBookmark", 1);

options.OutlineOptions.BookmarksOutlineLevels.Add("NestedBookmark", 2);

options.OutlineOptions.ExpandedOutlineLevels = 9;

doc.Save(MyDir + "Out.pdf", options);

<!–[if gte mso 9]>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0in; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;}

<![endif]–>If you still face problem, please share your expected output Word and Pdf documents here for our reference. We will investigate how you want your final output be generated like. We will then provide you more information on this along with code.