How to change text/font color in reportlab.pdfgen

后端 未结 3 595
执念已碎
执念已碎 2021-02-01 19:02

I want to use a different color of text in my auto-generated PDF.

According to the reportlab docs all I need to do is:

self.canvas.setFillColorRGB(255,0,         


        
3条回答
  •  暖寄归人
    2021-02-01 19:29

    I can't verify this at the moment, but if you look in the linked example whenever they set the color before calling drawCenteredString they always do it with setFillColor, never setFillColorRGB, only using the latter to set the color of rects. So try instead changing it to

    self.canvas.setFillColor(red)
    self.canvas.drawCenteredString(...)
    

    I don't know if it says this in that doc or not, but the variable red is defined as a constant in one of the ReportLab modules, so if you have any errors with that, just be sure to include the appropriate module (the exact name escapes me at the moment).

提交回复
热议问题