I’m creating a document with nested bookmarks. Everything works fine, except when I try to delete the first child bookmark within a nested (parent) bookmark. Even that works fine if I first insert another child, before deleting the first one. Let me illustrate it with the following code sample:
public void testBmDelete1() {
var doc = new Document();
doc.Pages.Add((new Document(“path1”)).Pages);
doc.Pages.Add((new Document(“path2”)).Pages);
// Create the parent bookmark
var parentBm = new OutlineItemCollection(doc.Outlines);
parentBm.Title = “Parent Bookmark”;
parentbm.Open = true;
doc.Outlines.Add(parentBm);
// Create the child bookmarks
var childBm1 = new OutlineItemCollection(doc.Outlines);
childBm1.Title = “Child Bookmark 1”;
childBm1.Destination = new InteractiveFeatures.GoToAction(doc.Pages.[1]);
parentBm.Add(childBm1);
// Remove the first child bookmark, this won’t work as intended
doc.Outlines.Delete(“Child Bookmark 1”);
var childBm2 = new OutlineItemCollection(doc.Outlines);
childBm2.Title = “Child Bookmark 2”;
childBm2.Destination = new InteractiveFeatures.GoToAction(doc.Pages.[2]);
parentBm.Add(childBm2);
// Save the document
doc.Save(“BookmarkTest.pdf”);
}
This will not work as intended. The second child bookmark doesn’t get inserted. If I move the removing of the first bookmark after the insertion of the second child bookmark, it will work. Also, I tried inserting the first one, then the second one, then removing the second one right after that, and it did what it was supposed to.