We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Removing white space in Word document

We are using Aspose Word in order to perform an IMailMerge in a word document. In places there is some conditional formatting required such that if data set A exists then data set B should be removed (and vice versa) and the corresponding section should be removed in the document template.
We have employed bookmarks as a way of removing the information in the document, however this leaves the white space in the document and pagination looks awful. How can we remove the text AND the white space ?
Thanks

This message was posted using Aspose.Live 2 Forum

Hi
Thanks for your request. Could you please attach your document and provide me your code? I will investigate this issue and try to help you.
Best regards.

Uunfortunately company policy doesn’t allow me to share the source.
I can however descibe the problem more exactly.
Your description of bookmark.Remove() found at https://reference.aspose.com/words/net/aspose.words/bookmark/remove/
“Removes the bookmark from the document. Does not remove text inside the bookmark”
I would an equivalent to remove the text AND the white space it occupies.

Hi
Thanks for your inquiry. You can remove content of bookmark using the following simple code:

doc.Range.Bookmarks["book"].Text = string.Empty;
Also your can try remove parent paragraph of bookmark.
doc.Range.Bookmarks["book"].Text = string.Empty;
doc.Range.Bookmarks["book"].BookmarkStart.ParentNode.Remove();

Hope this helps.
Also note that only you and Aspose staff members can download documents attached in this forum.
Best regards.