在reportlab中为段内标记颜色定义我们自己的颜色(RGB?)

时间:2016-03-15 18:37:33

标签: python colors reportlab

为了使用reportlab / python生成PDF文件,可以使用所谓的"段落XML标记标记",非常容易地定义文本的颜色(以及很多其他东西)。例如绿色文字:

rapport.append(Paragraph('<font size = 14 color = "green" > <b> Toto is a naugthy boy </b></font>', styles['Left']))

但是,是否可以定义我们自己的颜色(例如使用RGB代码)?

1 个答案:

答案 0 :(得分:5)

它实际上非常简单,您只需将green替换为任何十六进制RGB颜色,如#424242。所以在你的例子中它看起来像这样:

rapport.append(Paragraph('<font size=14 color="#424242"><b>Toto is a naugthy boy</b></font>', styles['Left']))

但也可以使用大多数HTML颜色,如:

rapport.append(Paragraph('<font size=14 color="rgb(191, 255, 0)"><b>Toto is a naugthy boy</b></font>', styles['Left']))
rapport.append(Paragraph('<font size=14 color="hsl(75, 100%, 50%)"><b>Toto is a naugthy boy</b></font>', styles['Left']))