May I mention that the body.clear () method does not delete bookmarks because they are associated with the document.
This worked for me:
scratchBody = scratchDoc.getBody(); scratchBody.clear(); bookmarks = scratchDoc.getBookmarks(); while ( bookmarks.length ) { bookmarks.shift(); }
I have not tried this yet, but, as with bookmarks, there may be HeaderSection, FooterSection, and FootnoteSections sections in the document.
source share