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

Free Support Forum - aspose.com

Highlight Color not visible


I have a problem is using the highlight color for the specific words in my document.
The working code line producing the gray color which is darker than I want to I tried the other options but not working well for me.
I am using the following code lines for the highlight color.

'run.Font.HighlightColor = System.Drawing.Color.FromArgb(255, 223, 223, 223) ’ this is working
run.Font.HighlightColor = System.Drawing.Color.FromArgb(255, 230, 230, 230) ’ this is not working

Now I am not understanding why the same thing not applicable for the two colors. Even I tried with other lighter shades like whiteSmoke an Linen but these too were not shown after processing the document.

run.Font.HighlightColor = System.Drawing.Color.Linen ’ this is not working
run.Font.HighlightColor = System.Drawing.Color.WhiteSmoke ’ this is not working

The surprising thing is that the first code line is working and when I tried to increase the values to 230 from 223 all goes wrong…

I am using ReplaceEvaluator.

Please help ASAP.

Thanks for your inquiry. I managed to reproduce the problem and created new issue #6440 in our defect database. We will investigate the issue and provide you more information.
I think that this is restriction of MS Word. As a workaround you can try using BackgroundPatternColor as shown in the following code:

builder.Font.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(255, 230, 230, 230);
builder.Write("test ");
builder.Font.Shading.BackgroundPatternColor = System.Drawing.Color.Linen;
builder.Write("test ");
builder.Font.Shading.BackgroundPatternColor = System.Drawing.Color.WhiteSmoke;
builder.Write("test ");

Best regards.

ok. thanks.
This is working for me. but in some systems the shade color is not visible while on some it is visible. Is there is a restriction by MS word ? and if there is such restriction than whats the way to enable the shading color.

Thanks for your inquiry. This could be a restriction of your monitor. On my working machine only first color (FromArgb(255, 230, 230, 230)) is visible. But on my laptop all colors are visible. So I think you should use more vivid colors.
Best regards.

oh… ok I will check for my minitor settings.

I am using so much light background because the font color of the word
which is going to be highlighted may be Pink, Blue, Red, BlueViolet,
Orange, Brown, Turquoise, SkyBlue or DarkCyan. So I am trying to use lighter color so that all the words are visible with font color and highlighted colors.

If aspose support other colors for which I can use a lighter background
color that is visible for all all font colors with word then please
suggest. I can change those 9 colors and highlight color.


Thanks for your inquiry. Gray color is the best choice in your case I think. Could you please attach document that contains all these colors.
Best regard.

one more problem using color patterns…
I am using the background at the two places using the below code lines
(1) at the time of checking each words-

run.Font.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(255, 241, 241, 241)

(2) at the time of creating a new document

builder.Font.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(255, 241, 241, 241)

I am using the both in the same application and adding the created document as a section in original document…

Now what is surprising me is that after the document is processed the code line in above point (1) is not showing the background while the code in point (2) showing the background.

Please suggest where i am doing wrong…


Thanks for your inquiry. builder.Font.Shading.BackgroundPatternColor get/sets background of the current node (node where DocumentBuilder cursor is placed at the moment). And run.Font.Shading.BackgroundPatternColor gets/sets the color of particular run.
Could you please show me the code that will allow me to reproduce the issue?
Best regards.

i am sending you the code.
The first sub is used in replace evaluator. and after complete processing of the document the second sub is used to add the words and later i am adding the created section in the original document.

’’’ the subroutine below match each word from the database and if the word found it highlight the word.

Private Sub MarkSubstituteWords(ByVal run As Run)
Dim flagIsSynonym As Boolean = False
Dim word As String = run.Text

sqlCommand.CommandTimeout = 0
sqlCommand = New SqlCommand("Select Words from Synonyms where Words=’" + Replace(Replace(word, "’", "’’"), "’", "’’") + "’", sqlConnection)
dataReader = sqlCommand.ExecuteReader()
While dataReader.Read()
‘run.Font.HighlightColor = System.Drawing.Color.FromArgb(255, 223, 223, 223) ‘working
‘run.Font.HighlightColor = System.Drawing.Color.FromArgb(255, 230, 230, 230) ‘not working
run.Font.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(255, 241, 241, 241)
End While
End Sub


’’’ Subroutine to create document for the highlighted words by rarity…

Private Sub CreateDocumentSubWords(ByVal builder As DocumentBuilder)

If sqlConnection.State = ConnectionState.Closed Then
End If

builder.Font.Name = "Verdana"
builder.Font.Size = 10
builder.Font.Bold = True
builder.Writeln("Highlighted Words")
builder.Font.Bold = False
builder.CellFormat.Width = 140
builder.Font.Bold = True
builder.Write("Original Word")
builder.Font.Bold = False
builder.Font.Bold = True
builder.Write("Substitute Word(s)**")
builder.Font.Bold = False

’ method call. the below method have two arguments- ‘’ colorCode is the color (from 9 colors) which will use to color the table
’ and create the table cell for all words with respective color
NewGetWordsFromDataBase(builder, colorCode) 

builder.Font.Bold = False
builder.Write("** Words with suggested substitutes have ")
'builder.Font.HighlightColor = System.Drawing.Color.FromArgb(255, 223, 223, 223)
builder.Font.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(255, 241, 241, 241)
builder.Write("gray background")
'builder.Font.HighlightColor = System.Drawing.Color.White
builder.Font.Shading.BackgroundPatternColor = System.Drawing.Color.White
builder.Write(". Please try some more documents and get the facility to color specify the words using different colors")
End Sub

I have attached a document which have all the colors which I am using
please check this and help me asap.

Thank you for additional information. If you need to highlight words in your document you can try using the following code:

Sub Main()
Dim lic As License = New License()
'Open document
Dim doc As Document = New Document("C:\Temp\sampledoc.doc")
'create string array that contains words that should be highlighted
Dim words As String() = {"Trial", "Unlimited", "splicing", "term", "migration", "among", "lean", "first", "scan"}
For Each word As String In words
Dim regex As Regex = New Regex(word)
doc.Range.Replace(regex, New ReplaceEvaluator(AddressOf ReplaceAction_HighlightWord), True)
'Save output doc
'Dim doc As Document = New Document("C:\Temp\CNkk_masterPageBreak.doc")
End Sub
Private Function ReplaceAction_HighlightWord(ByVal sender As Object, ByVal e As ReplaceEvaluatorArgs) As Aspose.Words.ReplaceAction
Dim run1 As Run = CType(e.MatchNode, Run)
Dim run2 As Run = CType(e.MatchNode.Clone(True), Run)
Dim run3 As Run = CType(e.MatchNode.Clone(True), Run)
run3.Text = run1.Text.Substring(0, run1.Text.IndexOf(e.Match.Value))
run2.Text = e.Match.Value
run1.Text = run1.Text.Substring(run1.Text.IndexOf(e.Match.Value) + e.Match.Value.Length)
'highlight the word
run2.Font.Shading.BackgroundPatternColor = Color.LightGray
run1.ParentParagraph.InsertBefore(run3, run1)
run1.ParentParagraph.InsertBefore(run2, run1)
Return ReplaceAction.Skip
End Function

Hope this helps.
Also Color.LightGray looks good with colors in your document.
Best regards.

this in not working correctly.
how long can expect the resolution for the issue #6440?
I am not getting the shading color for all of the words. There is background with the words using builder.Font…, while there is no highlight color for the words using run.Font…

Thanks for your request. I can’t provide you any estimate. Also if this is MS Word restriction then this issue can’t be fixed in Aspose.Words.
The code I provided works correctly on my side. All words are highlighted. Could you please attach your document and your code? Also list of words you have to highlight could be useful.
Best regards.

ok, thanks for the quick response.
I will prepare a sample document and will send you processed document soon.

If this is a MS words restriction from my side than whats the way to deactivate this restriction. Please let me know if there is any way so that I can produce the same required result as you are getting from your side.

Thanks for your inquiry. I didn’t tell that this is restriction on your side. I told that maybe this is restriction of MS Word. Some colors really are not visible when set HighlightColor (issue #6440).
I use Shading.BackgroundPatternColor and all works fine.
Waiting for your document.
Best regards.

Please find the attachments.
1.) Original Document - SampleTestDoc2.doc
2.) Processed Document - SampleTestDoc2Processed.doc

I am using the above code in my application. (The above code is a part of whole app.)
I am using the

run.Font.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(255, 241, 241, 241)

to process the input document. And to append a page in the processed document I am using

builder.Font.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(255, 241, 241, 241)

Now the thing surprising me is that I am able to see the background color on the created page (on the phrase “Gray Background”) but not on the input document.

hope this is enough…

Thanks for your inquiry. I tested your document and all words in the output document are highlighted. See the attached document.
Also I can see that words “Trial”, “term”, “scan” are also highlighted in your output document. If you can’t see this color you can select word, then select Borders and Shading from Format menu in MS Word and select Shading tab to see code of shading color. (But select word only, without paragraph break)
Best regards.

Hi Alexey,

have you fix the issue "Some colors not visible when set HighlightColor (Issue #6440) in the new** release ( Aspose.Words for .NET 6.0.1 )?


Thank you for your patience.
Issue #6440 has not been resolved yet. As my colleague wrote earlier this is most probably a restriction of MS Word. You can choose other highlight colors experimentally so they get visible. MS Word doesn’t allow selecting any of 24-bit colors for highlighting. But only a subset can be selected. Maybe that’s the matter of the issue: not all of them can be rendered as highlight colors even if set programmatically with Aspose.Words.