Question

I'm using reportlabs library of python to generate PDF reports. I need to understand which format of color code is needed to be passed.

When I pass RGB code for light green (178,255,102), to the_canvas.setFillColorRGB(178,255,102) it gives me white. And if I provide universal RGB color code for any color, it still gives me the same white color.

If I provide (25,51,0) , it gives me yellow, which is not RGB code for yellow.

How should I provide color codes to the reportlab in order to get the color I wanted. Which format is it using?

Was it helpful?

Solution

From what I can tell, using the 256 color space won't work. The manual states that using 1 is 'all lights on full'. So, to create 256,256,256 is actually done by using (1,1,1). Thus, to get something in between, you'll have to use decimals. For me, I wanted the RGB: (75,116,156) so I had to write: setFillColorRGB(0.29296875,0.453125,0.609375). That's the equivelant to: 75/256, 116/256, 156/256. A bit ridiculous IMO, but it came out perfect

OTHER TIPS

In case anyone wants an example I did this.

from reportlab.lib import colors
...
...
other code
...
...
customColor = colors.Color(red=(255.0/255),green=(204.0/255),blue=(153.0/255))

I used this color for a Table Style

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top