We are creating a new PDF document and adding bookmarks
Code Sample:
internal class Bookmark
{
public string Title { get; set; }
public int PageNumber { get; set; }
public List<Bookmark> Children { get; set; } = new List<Bookmark>();
}
[TestMethod]
public void AsposeIssue()
{
void ConstructBookmarks(Document newDoc, OutlineItemCollection parents, Bookmark node)
{
OutlineItemCollection bookmark = new OutlineItemCollection(newDoc.Outlines);
bookmark.Open = true;
bookmark.Bold = true;
bookmark.Title = node.Title;
bookmark.Action = new GoToAction(newDoc.Pages[(int)node.PageNumber]);
if (parents != null)
{
parents.Add(bookmark);
}
else
{
newDoc.Outlines.Add(bookmark);
}
foreach (Bookmark child in node.Children)
{
ConstructBookmarks(newDoc, bookmark, child);
}
}
var bookmarks = new List<Bookmark>
{
new Bookmark
{
Title = "Parent 1",
PageNumber = 1,
Children = new List<Bookmark>
{
new Bookmark
{
Title = "Child 1",
PageNumber = 1,
Children = new List<Bookmark>
{
new Bookmark
{
Title = "Grand Child 1",
PageNumber = 1
}
}
}
}
}
};
var document = new Document();
document.Pages.Add();
foreach (var bookmark in bookmarks)
{
ConstructBookmarks(document, null, bookmark);
}
document.Save(@$"aspose-issue-{Guid.NewGuid()}.pdf");
}
We have observed that even though we have made “bookmark.Open = true;” it is not reflecting in the output PDF. All bookmarks are collapsed when the PDF is opened.