Free Support Forum - aspose.com

Multi-Level Bookmarks

So I basically want to nest two or more bookmarks as follows:

Matt
Steve

Here is the code I have. Both bookmarks are being added, but they are at the same level.

Dim editor As PdfContentEditor = New PdfContentEditor()
editor.BindPdf(“C:\Documents and Settings\marrington\Desktop\test.pdf”)
Dim bookma As BookMarks = New BookMarks

Dim aaa As BookMark = New BookMark
aaa.PageNumber = 5
aaa.Level = 1
aaa.PageDisplay = “Fit”
aaa.Title = “Matt”

bookma.Add(aaa)

Dim bbb As BookMark = New BookMark
bbb.PageNumber = 4
bbb.Level = 2
bbb.PageDisplay = “Fit”
bbb.Title = “Steve”

bookma.Add(bbb)

For i As Integer = 0 To bookma.Count - 1
editor.CreateBookmarks(bookma(i))
Next

editor.Save(“C:\Documents and Settings\marrington\Desktop\testafter.pdf”)

Hello Matt,

Thanks for considering Aspose.

I am pleased to inform you that multi-level bookmarks are supported in Aspose.Pdf.Kit. Please use ChildItem property of BookMark class for this purpose. I have made changes to your code, Please use following code snippet.

Dim editor As Aspose.Pdf.Kit.PdfContentEditor = New Aspose.Pdf.Kit.PdfContentEditor()
editor.BindPdf("C:\\pdftest\\1\\business.pdf")
Dim bookma As Aspose.Pdf.Kit.BookMarks = New Aspose.Pdf.Kit.BookMarks()

Dim aaa As Aspose.Pdf.Kit.BookMark = New Aspose.Pdf.Kit.BookMark()
aaa.PageNumber = 5
aaa.PageDisplay = "Fit"
aaa.Title = "Matt"

Dim bbb As Aspose.Pdf.Kit.BookMark = New Aspose.Pdf.Kit.BookMark()
bbb.PageNumber = 4
bbb.PageDisplay = "Fit"
bbb.Title = "Steve"

bookma.Add(bbb)
aaa.ChildItem = bookma

editor.CreateBookmarks(aaa)
editor.Save("C:\\pdftest\\1\\Bookmarks.pdf")