This is a migrated thread and some comments may be shown as answers.

coloring the particular text in the paragraph

1 Answer 153 Views
WordsProcessing
This is a migrated thread and some comments may be shown as answers.
zake
Top achievements
Rank 1
zake asked on 27 Nov 2018, 07:02 AM

I am attempting to give color of the particular text in the paragraph. But I am still failed. This is my code. Any help would be appreciated.

01.List list = document.Lists.Add(ListTemplateType.NumberedDefault);
02. 
03.                var section = document.Sections.AddSection();
04. 
05.                var paragraphTop = section.Blocks.AddParagraph();
06.                paragraphTop.Inlines.AddRun("Note that the numbering reference within the document content in the sample above contains a direct reference to the level to be applied because the <w:numPr> contains both the reference to the numbering definition (numId) and a reference to the level (ilvl). See Paragraph Properties for more on <w:numPr>. The other possible way to reference a level in content is through the referenced paragraph style. That is, in the <w:abstractNum> the appropriate subsidiary level (lvl) could contain a pStyle with a value of ListParagraph. In that case, the content contains only a reference to the numbering definition instance (numId), but it also references the paragraph style. The same style will be found in the numbering definition referenced and that level will be used for the paragraph.");
07. 
08.                var paragraphTop1 = section.Blocks.AddParagraph();
09.                paragraphTop1.Inlines.AddRun("okeh <p color=\"red\">this is red color</p> <font color=\"red\">This is some text!</font>");
10. 
11. 
12.                var paragraph1 = section.Blocks.AddParagraph();
13.                paragraph1.Inlines.AddRun("Note that the numbering reference within the document content in the sample above contains a direct reference to the level to be applied because the <w:numPr> contains both the reference to the numbering definition (numId) and a reference to the level (ilvl). See Paragraph Properties for more on <w:numPr>. The other possible way to reference a level in content is through the referenced paragraph style. That is, in the <w:abstractNum> the appropriate subsidiary level (lvl) could contain a pStyle with a value of ListParagraph. In that case, the content contains only a reference to the numbering definition instance (numId), but it also references the paragraph style. The same style will be found in the numbering definition referenced and that level will be used for the paragraph.");
14.                paragraph1.ListId = list.Id;
15.                paragraph1.ListLevel = 0;
16. 
17.                var paragraph2 = section.Blocks.AddParagraph();
18.                paragraph2.Inlines.AddRun("Line Two, Note that the numbering reference within the document content in the sample above contains a direct reference to the level to be applied because the <w:numPr> contains both the reference to the numbering definition (numId) and a reference to the level (ilvl). See Paragraph Properties for more on <w:numPr>. The other possible way to reference a level in content is through the referenced paragraph style. That is, in the <w:abstractNum> the appropriate subsidiary level (lvl) could contain a pStyle with a value of ListParagraph. In that case, the content contains only a reference to the numbering definition instance (numId), but it also references the paragraph style. The same style will be found in the numbering definition referenced and that level will be used for the paragraph.");
19.                paragraph2.ListId = list.Id;
20.                paragraph2.ListLevel = 1;
21. 
22.                var paragraph3 = section.Blocks.AddParagraph();
23.                paragraph3.Inlines.AddRun("Line three, Note that the numbering reference within the document content in the sample above contains a direct reference to the level to be applied because the <w:numPr> contains both the reference to the numbering definition (numId) and a reference to the level (ilvl). See Paragraph Properties for more on <w:numPr>. The other possible way to reference a level in content is through the referenced paragraph style. That is, in the <w:abstractNum> the appropriate subsidiary level (lvl) could contain a pStyle with a value of ListParagraph. In that case, the content contains only a reference to the numbering definition instance (numId), but it also references the paragraph style. The same style will be found in the numbering definition referenced and that level will be used for the paragraph.");
24.                paragraph3.ListId = list.Id;
25.                paragraph3.ListLevel = 1;
26. 
27.                var paragraph4 = section.Blocks.AddParagraph();
28.                paragraph4.Inlines.AddRun("Line four, Note that the numbering reference within the document content in the sample above contains a direct reference to the level to be applied because the <w:numPr> contains both the reference to the numbering definition (numId) and a reference to the level (ilvl). See Paragraph Properties for more on <w:numPr>. The other possible way to reference a level in content is through the referenced paragraph style. That is, in the <w:abstractNum> the appropriate subsidiary level (lvl) could contain a pStyle with a value of ListParagraph. In that case, the content contains only a reference to the numbering definition instance (numId), but it also references the paragraph style. The same style will be found in the numbering definition referenced and that level will be used for the paragraph.");
29.                paragraph4.ListId = list.Id;
30.                paragraph4.ListLevel = 2;
31. 
32.                var paragraphBottom = section.Blocks.AddParagraph();
33.                paragraphBottom.Inlines.AddRun("Note that the numbering reference within the document content in the sample above contains a direct reference to the level to be applied because the <w:numPr> contains both the reference to the numbering definition (numId) and a reference to the level (ilvl). See Paragraph Properties for more on <w:numPr>. The other possible way to reference a level in content is through the referenced paragraph style. That is, in the <w:abstractNum> the appropriate subsidiary level (lvl) could contain a pStyle with a value of ListParagraph. In that case, the content contains only a reference to the numbering definition instance (numId), but it also references the paragraph style. The same style will be found in the numbering definition referenced and that level will be used for the paragraph.");

1 Answer, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 29 Nov 2018, 01:52 PM
Hi Zake,

I am assuming that you mean the code from line number 9 from the snippet you shared. Please, correct me if I am wrong.

All the content passed to the AddRun() method is treated as a string and directly added to the document content, without parsing it. If you would like to merge HTML content in the already generated in RadFlowDocument content, you can use the Import Document Element functionality - it will help you in parsing and inserting the parsed content into the RadFlowDocument instance.

Hope this is helpful.

Regards,
Tanya
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
WordsProcessing
Asked by
zake
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Share this question
or