使用MIGRADOC和PDFSHARP为文本的特定部分添加背景颜色

4

我正在尝试使用MIGRADOC和PDFSHARP在某些句子(文本)的特定部分添加背景颜色。有什么建议吗?

par.addText(coloredText);

这是我尝试添加应该被着色的文本的方法,但除了段落(paragraph.shading.color = Color.red)没有设置颜色的方法,但我需要段落中一部分文本着色。谢谢。

请添加您已经尝试过的代码。 - Vini.g.fer
@Vini.g.fer 我已将代码添加到帖子中。谢谢。 - misha
1个回答

3
使用FormattedText可以确定文本的颜色(遗憾的是不能确定背景颜色)。使用下面的代码片段可以实现这一点:

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");

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接