/// <summary> /// Redact a range, replacing all marked text. /// </summary> /// <param name="range">A range to redact.</param> /// <param name="rangeData">A RangeDataEx containing properties about the range.</param> private void RedactRange(Word.Range range, RangeDataEx rangeData) { object ParagraphNumber = Word.WdNumberType.wdNumberParagraph; foreach (Word.Paragraph p in range.Paragraphs) { //get the para's range Word.Range ParagraphRange = p.Range; //trim to the selection, if needed if (range.Start > ParagraphRange.Start) { ParagraphRange.Start = range.Start; } if (range.End < ParagraphRange.End) { ParagraphRange.End = range.End; } if (ParagraphRange.End == p.Range.End - 1 && ParagraphRange.Start == p.Range.Start) { p.Range.ListFormat.ConvertNumbersToText(ref ParagraphNumber); //if the whole para was redacted, redact the numbering } //make it black on black ParagraphRange.Font.Shading.BackgroundPatternColor = Word.WdColor.wdColorAutomatic; ParagraphRange.HighlightColorIndex = Word.WdColorIndex.wdBlack; //moving to highlighting instead of text background ParagraphRange.Font.Color = Word.WdColor.wdColorBlack; //get rid of links and bookmarks foreach (Word.Hyperlink Hyperlink in ParagraphRange.Hyperlinks) { Hyperlink.Delete(); } foreach (Word.Bookmark Bookmark in ParagraphRange.Bookmarks) { Bookmark.Delete(); } //BUG 110: suppress proofing errors ParagraphRange.NoProofing = -1; //finally, replace the text Debug.Assert(ParagraphRange.ShapeRange.Count == 0, "Some Shapes were not redacted by RedactShapes."); if (ParagraphRange.InlineShapes.Count > 0) { //if there are images, then split into subranges and process text and images separately List <RangeData> Subranges = RedactCommon.SplitRange(ParagraphRange); for (int j = Subranges.Count - 1; j >= 0; j--) { //set start and end ParagraphRange.Start = Subranges[j].Start; ParagraphRange.End = Subranges[j].End; if (ParagraphRange.InlineShapes.Count > 0) { RedactInlineShape(ParagraphRange.InlineShapes[1]); } else { ParagraphRange.Text = RedactCommon.BuildFillerText(ParagraphRange, rangeData); } } } else { ParagraphRange.Text = RedactCommon.BuildFillerText(ParagraphRange, rangeData); } } }