4

I'm struggling to add background color on certain part of sentence(text), word with MIGRADOC and PDFSHARP. Any suggestions how to do ?

par.addText(coloredText);

This is how I tried to add text that should be colored but there is no way to setup for color, except for paragraph (paragraph.shading.color = Color.red) but I need part of the text in the paragraph.

Thanks

misha
  • 231
  • 1
  • 2
  • 5

1 Answers1

3

With FormattedText it is possible to determine the color of the text (unfortunately not the background) With the piece of code below it is possible to do this:

enter image description here

Paragraph par = section.AddParagraph();  
par.Format.Alignment = ParagraphAlignment.Left;

// Use formatted text to specify the color
FormattedText ftext = new FormattedText();
ftext.AddText("Coloured Text");
ftext.Color = Colors.Red;

par.AddText("normal Text");
par.AddSpace(1);
par.Add(ftext);
par.AddSpace(1);
par.AddText("rest of the normal Text");
Mong Zhu
  • 23,309
  • 10
  • 44
  • 76