Professional Documents
Culture Documents
2.8 Colors: Figure 2-6: Mirror Images
2.8 Colors: Figure 2-6: Mirror Images
)5.2 ,4(
sehcni ni )1,5.2(
2.8 Colors
There are generally two types of colors used in PDF depending on the media where the PDF will be used.
The most commonly known screen colors model RGB can be used in PDF, however in professional printing
another color model CMYK is mainly used which gives more control over how inks are applied to paper.
More on these color models below.
RGB Colors
The RGB or additive color representation follows the way a computer screen adds different levels of the red,
green, and blue light to make any color in between, where white is formed by turning all three lights on full
(1,1,1).
There are three ways to specify RGB colors in pdfgen: by name (using the color module, by
red/green/blue (additive, RGB) value, or by gray level. The colors function below exercises each of the four
methods.
def colorsRGB(canvas):
from reportlab.lib import colors
from reportlab.lib.units import inch
black = colors.black
y = x = 0; dy=inch*3/4.0; dx=inch*5.5/5; w=h=dy/2; rdx=(dx-w)/2
rdy=h/5.0; texty=h+2*rdy
canvas.setFont("Helvetica",10)
for [namedcolor, name] in (
[colors.lavenderblush, "lavenderblush"],
[colors.lawngreen, "lawngreen"],
[colors.lemonchiffon, "lemonchiffon"],
[colors.lightblue, "lightblue"],
[colors.lightcoral, "lightcoral"]):
canvas.setFillColor(namedcolor)
canvas.rect(x+rdx, y+rdy, w, h, fill=1)
canvas.setFillColor(black)
canvas.drawCentredString(x+dx/2, y+texty, name)
x = x+dx
y = y + dy; x = 0
for rgb in [(1,0,0), (0,1,0), (0,0,1), (0.5,0.3,0.1), (0.4,0.5,0.3)]:
r,g,b = rgb
canvas.setFillColorRGB(r,g,b)
canvas.rect(x+rdx, y+rdy, w, h, fill=1)
canvas.setFillColor(black)
Page 21