Clip shape in reportlab

To clip Drawing instead of Canvas.

Since Path and ʻArcPath have a property called ʻisClipPath, you can create a clip path area with it and ʻadd. First add the clip path ʻadd and then add the contents. By default, stroke and fill are drawn, so if you just want to clip it, delete it manually.

clip.py


from reportlab.graphics.shapes import *

width = 300
height = 200

d = Drawing(width,height)

clip = Path(fillColor=None, strokeColor=None, isClipPath=True)
clip.moveTo(0,0)
clip.lineTo(width,0)
clip.lineTo(width,height)
clip.lineTo(0,height)
clip.closePath()

d.add(clip)

Even with the same Shapes, you can't do something like Rect. I wish I could do it.

Reference material

Recommended Posts

Clip shape in reportlab
Image addition memo in reportlab
Arrange the numbers in a spiral shape