Using Aspose.Pdf for .NET v24.9.0, I am trying to collapse all bookmarks in a PDF document using the below code:
private void MyMethod(myParams)
{
//...stuff happens....
foreach (OutlineItemCollection bookmark in doc.Outlines)
{
CollapseBookmark(bookmark);
}
doc.Save(myLocation);
doc.Dispose();
}
private void CollapseBookmark(OutlineItemCollection bm)
{
bm.Open = false;
// Collapse all child bookmarks recursively
foreach (OutlineItemCollection childBM in bm)
CollapseBookmark(childBM);
}
The Open property of each outline in doc.Outlines is set to False successfully. However when the code reaches doc.Save(), the Open property shows as True in my debugger and the bookmarks are all expanded when I view the saved file in Adobe.
Why is the Open state being changed when the file is saved?
@bkramerQTCM
It seems that you are experiencing an issue where the bookmarks in your PDF document do not retain their collapsed state after saving. The code you provided correctly sets the Open
property of each bookmark to false
, but it appears that this state is not being preserved when the document is saved.
This behavior may be related to a known issue with the Aspose.PDF library, where the bookmark state does not reflect the changes made in the code after saving the document. The internal handling of bookmarks might be causing the Open
property to revert to its default state upon saving.
To address this, you might want to check if there are any updates or patches available for the Aspose.PDF library that could resolve this issue. Additionally, it has been noted that similar problems have been reported by other users, and the Aspose team is actively looking into it. They have opened an internal ticket to track this issue, which may lead to a fix in future releases.
In the meantime, you could consider reaching out to Aspose support for further assistance or to inquire about the status of the issue. If you need immediate help, you might also explore the possibility of using a different approach to manage the bookmarks or check if there are any workarounds suggested by the community.
If you have any further questions or need additional assistance, feel free to ask!
Sources:
[1]: Bookmarks are not expanded
[2]: Bookmarks are not expanded