Below is a function that I am trying to add a bookmark to a parent that already has bookmark children. But everytime I have the child bookmark added to the parent, all the pre existing bookmarks get erased.
public static void AddBookmarkForPage(Document document, string title, int pageNumber, string parentBookmarkTitle = null)
{
bool foundParentMatch = false;
OutlineItemCollection pdfOutline = new OutlineItemCollection(document.Outlines);
pdfOutline.Title = title;
pdfOutline.Action = new Aspose.Pdf.InteractiveFeatures.GoToAction(document.Pages[pageNumber]);
if (parentBookmarkTitle != null)
{
foreach (OutlineItemCollection parentOutline in document.Outlines)
{
if (parentOutline.Title.Equals(parentBookmarkTitle, StringComparison.CurrentCultureIgnoreCase))
{
foundParentMatch = true;
parentOutline.Add(pdfOutline);
break;
}
}
}
if (foundParentMatch == false)
document.Outlines.Add(pdfOutline);
}