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 https://docs.aspose.com/words/net/working-with-bookmarks/

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.StartBookmark("MyBookmark");
builder.Writeln("Text inside a bookmark.");
builder.StartBookmark("NestedBookmark");
builder.Writeln("Text inside a NestedBookmark.");
builder.EndBookmark("NestedBookmark");
builder.Writeln("Text after Nested Bookmark.");
builder.EndBookmark("MyBookmark");
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 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.