I’m trying to figure out what is the best way to remove bookmarks and their content. bookmark.Text = “”; or RemoveBookmarkWithContent( bookmark ); ?
Easiest place to look for discrepancies, is in the AcmeStmt.doc under the ‘Compensation’ section, except for ‘Base Pay’, each row is bookmarked. It also contains the trailing empty paragraph so that when appropriate bookmarks/content are removed, the section should be rendered remaining line items with each having a blank paragraph following it.
You can run my sample code both ways to see different behaviors (and maybe my source document is corrupt, but I’m hoping not).
I have the following questions/concerns:
- I read this post: https://blog.aspose.com/2007/03/13/70192 but am curious why the code seems so ‘greedy’ in that it removes ‘extra’ stuff (as you’ll see in my demo).
For example, the code even states “// Bookmark nodes located immediately before start of our bookmark should also be included in the removal process.”. Why are these included? If you run my sample code using the ‘RemoveBookmarkWithContent’ method, you’ll see that some of the paragraphs between line items are removed. Some remain (correctly) and I can’t figure out what the pattern is. This illustrates some sort of problem, but you can then run my code using the bookmark.Text = “”; to compare the resulting documents and see all the differences. Note: the current code only attempts to clear/remove bookmarks in that first Compensation section, but if you uncomment the line that starts with // bookmarksToDelete = bookmarksToDelete.Concat you will then see full document processed and see other problem areas if you compare the output documents.
- I read this post: http://stackoverflow.com/questions/9776030/aspose-words-delete-nodes-in-a-bookmark where Shahzad Latif seems to say bookmark.Text = “”;
The reason I’m asking is that we are having other problems that I won’t go into when using bookmark.Text = “” and wondering if RemoveBookmarkWithContent is the ‘correct’ way and we should get that working and have our ‘document authors’ then adjust the way they do bookmarking to fit the appropriate pattern.
- I opened my document with your sample Document Explorer app and if you examine the ‘Compensation’ section, I’m confused if I have corrupt document or what. But if you look at the Word document, it looks like none of the bookmarks overlap. Not even on same lines. But if you look in your explorer, and almost every one of the bookmarks in that little section overlap by ‘one node’. Wondering if that is leading to any problems.
Thanks in advance,
Terry