Looking for an exhaustive list of the colors in ReportLab, I was surprised that there wasn’t a list of them — with examples — in the ReportLab docs. Then, when I didn’t quickly find one with Google, I thought I would turn this into a test of my coding chops.
So, this might seem simple to you, but I needed quite a few tries to get it going. Which means, of course, that I’m pretty proud of it.
Here’s the code I wrote:
from reportlab.lib.pagesizes import A4 from reportlab.lib.enums import TA_LEFT from reportlab.platypus import SimpleDocTemplate, Paragraph from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle from reportlab.lib.colors import getAllNamedColors doc =  document = SimpleDocTemplate('colors.pdf', pagesize = A4, rightMargin = 72, leftMargin = 72, topMargin = 72, bottomMargin = 34) styles = getSampleStyleSheet() for color in getAllNamedColors(): styles.add(ParagraphStyle(name=color, alignment=TA_LEFT, fontSize=12, leading=22, fontName='Helvetica', backColor=color)) doc.append(Paragraph('Test color '+color, styles[color])) document.build(doc)
And here is the result of the code: colors.pdf