Code snippets are bits of re-usable code submitted by the ReportLab community. We don't promise that they are accurate, up-to-date or correct - use them at your own risk!

We'd love it if you could participate by submitting your own snippets and sharing your experience with others by commenting. You will need to create a user account by filling out our very simple form.

View all snippets


CMYK and Pantone ink overprinting
opensourcerl-toolkit

RLIMG: CMYK and Pantone ink overprinting
Author:
damian
Posted:
Sept. 23, 2010
Language:
Python
Tags:
opensource rl-toolkit

Overprinting is a technique used in professional printing that allows the designer more control over the inks that are layered on a page.

Your PDF viewer may not simulate the overprint effect by default and instead knock out the colour underneath. If you use Adobe Acrobat 9 or later version you can turn on overprint preview via Preferences > Page Display > Use Overprint Preview: Always.

To use overprinting in a PDF generated by reportlab, you first need to define a separated CMYK colour with a spot name. If the colour is a separate ink used in the printer (e.g. Pantone) then the CMYK values are just to provide an on screen representation and do not need to be accurate, more important is the spot name which is a string that printers can identify such as 'PMS_288'.

c.setFillOverprint(True) turns on overprint for the drawing operations that follow. You can then set this property to False when you want to go back into the default knock-out mode.

There are many reasons you may use overprinting such as using it to print a richer black than black ink alone or mixing more than one Pantone colour. Give it a try and see what you can produce.

"""
Example of overprinting inks on top of one another to mix colours.
Used in professional printing but your PDF viewer may not simulate it correctly on your monitor.
"""
from reportlab.graphics.shapes import Rect, Circle
from reportlab.pdfgen.canvas import Canvas
from reportlab.lib.colors import CMYKColorSep

filename = 'cmyk_overprint.pdf'

cyan =    CMYKColorSep(1, 0, 0, 0, spotName='cyan')
magenta = CMYKColorSep(0, 1, 0, 0, spotName='magenta')
yellow =  CMYKColorSep(0, 0, 1, 0, spotName='yellow')
black =   CMYKColorSep(0, 0, 0, 1, spotName='black')

c = Canvas(filename, pagesize=(450,550), cropMarks=True)

c.setFillOverprint(True)


# Overlapping CMY circles

x = 75
y = 525
r = 100

c.setFillColor(cyan)
c.circle(x+(r), y-r, r, fill=True, stroke=False)

c.setFillColor(magenta)
c.circle(x+(r*2), y-r, r, fill=True, stroke=False)

c.setFillColor(yellow)
c.circle(x+(r*1.5), y-r-(0.866025404*r), r, fill=True, stroke=False)



# Gradients

x = 25
h = 25
w = 300
blocks = 5
c.setFont('Helvetica', 7)


# Red, Green, Blue

y = 185
c.setFillColor(cyan)
c.rect(x, y, w, h*0.75, fill=True, stroke=False)
for i in range(0,blocks):
    density = (1.0/(blocks-1))*i
    c.setFillColor(CMYKColorSep(0, 1, 1, 0, spotName='red', density=density))
    c.rect(x+(i*(w/blocks)), y, (w/blocks), h, fill=True, stroke=False)
c.drawString(335, y+10, 'Red overprinted on Cyan')

y = 155
c.setFillColor(cyan)
c.rect(x, y, w, h*0.75, fill=True, stroke=False)
for i in range(0,blocks):
    density = (1.0/(blocks-1))*i
    c.setFillColor(CMYKColorSep(1, 0, 1, 0, spotName='green', density=density))
    c.rect(x+(i*(w/blocks)), y, (w/blocks), h, fill=True, stroke=False)
c.drawString(335, y+10, 'Green overprinted on Cyan')

y = 125
c.setFillColor(cyan)
c.rect(x, y, w, h*0.75, fill=True, stroke=False)
for i in range(0,blocks):
    density = (1.0/(blocks-1))*i
    c.setFillColor(CMYKColorSep(1, 1, 0, 0, spotName='blue', density=density))
    c.rect(x+(i*(w/blocks)), y, (w/blocks), h, fill=True, stroke=False)
c.drawString(335, y+10, 'Blue overprinted on Cyan')


# Pantone

y = 85
c.setFillColor(CMYKColorSep(1, 0.67, 0, 0.23, spotName='PMS_288'))
c.rect(x, y, w, h*0.75, fill=True, stroke=False)
for i in range(0,blocks):
    density = (1.0/(blocks-1))*i
    c.setFillColor(CMYKColorSep(0, 0.55, 1, 0.02, spotName='PMS_717', density=density))
    c.rect(x+(i*(w/blocks)), y, (w/blocks), h, fill=True, stroke=False)
c.drawString(335, y+10, 'Pantone 717 overprinted on 288')

y = 55
c.setFillColor(CMYKColorSep(0, 1, 0.1, 0.35, spotName='PMS_7435'))
c.rect(x, y, w, h*0.75, fill=True, stroke=False)
for i in range(0,blocks):
    density = (1.0/(blocks-1))*i
    c.setFillColor(CMYKColorSep(0.5, 0.7, 0, 0, spotName='PMS_7442', density=density))
    c.rect(x+(i*(w/blocks)), y, (w/blocks), h, fill=True, stroke=False)
c.drawString(335, y+10, 'Pantone 7442 overprinted on 7449')

y = 25
c.setFillColor(CMYKColorSep(0, 0.1, 1, 0, spotName='PMS_109'))
c.rect(x, y, w, h*0.75, fill=True, stroke=False)
for i in range(0,blocks):
    density = (1.0/(blocks-1))*i
    c.setFillColor(CMYKColorSep(0.4, 0, 1, 0.38, spotName='PMS_7496', density=density))
    c.rect(x+(i*(w/blocks)), y, (w/blocks), h, fill=True, stroke=False)
c.drawString(335, y+10, 'Pantone 7496 overprinted on 109')


c.save()