【问题标题】:How to change font color and fontsize of FreeTextAnnotations (itext 7)?如何更改 FreeTextAnnotations (itext 7) 的字体颜色和字体大小?
【发布时间】:2019-10-06 15:18:40
【问题描述】:

我创建了一个PdfFreeTextAnnotation,但setColor-Method 只是注释的背景。

如何设置实际的fontcolorfontsize和字体?

Dim rec As iText.Kernel.Geom.Rectangle = ...

Dim anno As Annot.PdfFreeTextAnnotation = New 
Annot.PdfFreeTextAnnotation(rec, New PdfString(_annotation.Text))

anno.SetName(New PdfString(_annotation.Name))
anno.SetFlags(192)

anno.SetBorder(New iText.Kernel.Pdf.PdfAnnotationBorder(0, 0, 0))

pdfDoc.GetPage(_annotation.PageNumber).AddAnnotation(anno)

【问题讨论】:

    标签: pdf annotations itext itext7


    【解决方案1】:

    FreeText 注释具有RC 键,允许设置富文本字符串,用于生成注释的外观。基本上,您可以使用纯 HTML 作为富文本字符串,例如您可以将一些文本包装在 <span> 中,并在该范围的 style 属性中设置文本颜色,就像在 HTML 中一样。

    下面是 C# 中的代码:

    anno.SetRichText(new PdfString("<span style=\"color:#10FF10;\">Hello world</span>"));
    

    【讨论】:

    • 不错!非常感谢你。我在考虑使用 SetRichText 功能,但纪录片只在谈论弹出文本。但无论如何它都适用于正常外观。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多