[reportlab-users] Transparent PNG support

Tim Roberts timr at probo.com
Tue Dec 11 12:24:07 EST 2007


Darryl Woods wrote:

> Hi all,

>

> I am creating a report with ReportLab, and as part of this I have

> extended the Table class to do some custom drawing for table borders

> and such. Part of the design, however, is that the right side of the

> tables "fade out" to white, using a gradient. (The report was designed

> by a graphic designer...)

>

> I've tried various things:

>

> - placing a dithered black/white GIF image and setting the

> transparency mask (looks very bad)

> - placing a PNG with transparency (transparency doesn't appear)

> - drawing a series of vertical lines, getting increasingly lighter (no

> transparency though)

>

> Is there any way I can accomplish this?


How good does it need to be? In my view, your last option is the best one:

from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import LETTER
inch = 72

canv = canvas.Canvas( 'try.pdf', pagesize=LETTER )
canv.setPageCompression( 0 )

# Rectangle from 72,72 to 360,360 in 20 steps.

for i in range(20):
d = i
canv.setStrokeGray( i/20.0 )
canv.rect( 72+d, 36+d, 360-d-d, 360-d-d )
canv.setStrokeGray( 1.0-i/20.0 )
canv.rect( 72+d, 396+d, 360-d-d, 360-d-d )

canv.showPage()
canv.save()

This is drawing in units of 1 pixel. You could reduce the stroke width
to 0.5 and do twice as many steps.

--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the reportlab-users mailing list