Here is a code snippet:
- Code: Select all
Document doc = new Document();
var paraInserted = new Paragraph(doc);
var sd = new StructureDocumentTagInline(doc);
paraInserted.ChildObjects.Add(sd);
sd.SDTProperties.SDTType = SdtType.Text;
var text = new SdtText(true);
sd.SDTProperties.ControlProperties = text;
sd.SDTProperties.Tag = "sample";
var rt = new TextRange(doc);
rt.CharacterFormat.Hidden = true;
rt.Text = "sample text";
sd.SDTContent.ChildObjects.Add(rt);
doc.LastSection.Paragraphs.Add(paraInserted);
doc.SaveToFile("output.docx", FileFormat.Docx);
What happens is, it only hides the text within the content control but not the content control itself. Is there a way to hide the content control itself? An alternative I could think of is hiding the paragraph where the content control resides. Is it possible to hide a paragraph itself and not just the Text?