【问题标题】:Adding backround color to certain part of text with MIGRADOC AND PDFSHARP使用 MIGRADOC 和 PDFSHARP 将背景颜色添加到文本的某些部分
【发布时间】:2016-10-11 19:04:24
【问题描述】:

我正在努力在句子(文本)的某些部分添加背景颜色,使用 MIGRADOC 和 PDFSHARP 的单词。有什么建议吗?

par.addText(coloredText);

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

谢谢

【问题讨论】:

  • 请添加您目前尝试过的代码
  • @Vini.g.fer 我将代码添加到帖子中。谢谢

标签: c# pdf pdfsharp migradoc


【解决方案1】:

使用FormattedText 可以确定文本的颜色(不幸的是不是背景) 使用下面的代码可以做到这一点:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-24
    • 1970-01-01
    • 2016-08-22
    • 2017-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多