Remove the blank space in the bookmark

I have a image associated to a bookmark, when i remove the association the image gets deleted but the image blank space is retained. So would want to know how to get rid of this problem.
In another senario, if i have a normal text say a tabular data associated to a bookmark and if i remove the association, then the blank space also gets removed.
Kindly let me know how to handle this for image.
Code snippet is attached with the sample document
In the attachment, 2nd page i had an image, but after clearing the content of bookmark, the blank page is still existing.

if (document == null) return null;
if (bookmarkName == null || bookmarkName.trim().length() <= 0) return null;
Bookmark bm = document.getRange().getBookmarks().get(bookmarkName.trim());
if (bm != null)
return bm;


Thanks for your request. You should just avoid inserting empty section at the end of the document. You should check whether you finished the document and do not insert section break if so.
Also, you can remove the last section from your document if it is empty. Please see the attached screenshot.
Best regards,