Free Support Forum -

How can I dynamically hide one or more paragraphs


I have several documents that need to be adapted for different companies. Basically, I have multiple versions of a few paragraphs in each document, which each contain merge codes, if that matters, and I need to, based on which company I am generating this for, hide one version of the paragraph and leave the other version and if it;s the other company, show the other.

My thought is to keep both versions of the paragraph in the document and always hide one or the other based on the company. Can someone tell me if this is possible and what the easiest way to achieve this might me?


Hi Brad,

Thanks for your inquiry. If you need to conditionally remove/hide part of content in your document, then maybe you can consider using IF fields. For instance, please see the attached template. If you press Alt+F9 you will see field codes. If condition is true you will see the first text if false the second. Here is a simple code I used for testing:

Document doc = new Document(@"Test001\in.doc");

doc.MailMerge.Execute(new string[] {"test"}, new object[] {"true"});


Hope this approach could help you.

Best regards,

Thanks for the reply. The paragraphs in the template document will be updated by someone else from time to time and will contain merge codes, so I can’t always replace the same static string. I saw some reference in the forums to bookmarks. Would that work? I never used bookmarks before.


Thanks for your request. Yes, in your case you can try using bookmarks. Please see the following link to learn how to work with bookmarks in Aspose.Words:

Please see the following code example:

Document doc = new Document("your.doc");

// Use the indexer of the Bookmarks collection to obtain the desired bookmark.

Bookmark bookmark = doc.Range.Bookmarks["MyBookmark"];

// Set the text of the bookmark.

bookmark.Text = "This is a new bookmarked text.";

Best regards,


The bookmarks worked great. One other thing I want to to is have the text for the bookmarks be different colors in the actual document for those staff members editing the docs, so they know which will be shown for which company.

When I use the word file via the Aspose components and delete the unwanted bookmarks, I would like to set the font color for the entire document to black before I do the merge. Is there an easy way to set the color for all text in the document?



Hi Brad,

Thanks for your inquiry.

You can use the technique similar to the code here. All you need to change is the one line so the color of the text is changed instead of the font name.

If you have any troubles we will be glad to assist you.


I guess I want the FontChanger class then? The other thread says the code is available there, but I don't see where to get it. Is FontChanger not in the Aspose library? Where do I find this class?

Got it. I wasn’t logged in at first.

Hi Brad,

It's great it's working for you. If we can help you with anything else, please feel free to ask.