[reportlab-users] SVG and EPS
rschall at callone.net
Tue Aug 29 12:03:32 EDT 2006
Wow, most of that definitely went way over my head. The code below I
assume will make a "object" from scratch. If I already have an svg file
or eps file, there isn't a function, or set of functions to simply
convert it to a drawing object, in which i can do things like drawOn? I
came across a svglib.py file, which allows me to import it and
supposedly draw it, but that isn't quite working.
Thanks again for your time.
Robin Becker wrote:
> Rob Schall wrote:
>> One more question for anyone who might know how svg or eps would work
>> with report magic.
>> My boss would like to reduce the size of the pdf. The only real area
>> to do this, is to remove the jpg logo from the pdf and replace it
>> with an EPS or SVG logo. By replace, I simply mean future pdfs to be
>> I can't find much on the forums or in the documentation on how/if
>> this might be possible. Right now, I have the graphic in eps format,
>> but I assume with some work, I could get it into svg format.
>> Can reportlab handle this?
>> Thanks again!
> Well if you have the curves then the logo can be drawn directly by
> reportlab's canvas operations. It usually depends on whether you're
> brave enough to go playing with the curves lines etc etc. We don't
> embed eps or svg into pdf, but both formats are pretty readable. SVG
> drawings should probably be more parseable as the operations are well
> known. With eps there's aleays the chance that the postscript defines
> strange operators etc etc.
> Typically I end up with something that looks like this
> class MyLogo(Drawing):
> _attrMap = AttrMap(BASE=Drawing,
> logoFillColor = AttrMapValue(isColorOrNone),
> logoStrokeColor = AttrMapValue(isColorOrNone),
> logoStrokeWidth = AttrMapValue(isNumber),
> backgroundColor = AttrMapValue(isColorOrNone),
> ops = AttrMapValue(isListOfNumbersOrNone),
> pts = AttrMapValue(isListOfNumbersOrNone),
> sizeScale = AttrMapValue(isNumber),
> pts = [
> def __init__(self,width=417.279,height=287.154,*args,**kw):
> self._w0 = width
> self._h0 = height
> self.backgroundColor = None
> self.logoStrokeColor = None
> self.sizeScale = self.logoStrokeWidth = 1
> self.logoFillColor = colors.red
> def getContents(self):
> = self.logoStrokeColor or self.logoFillColor),'P')
> if self.backgroundColor:
> self.background =
> return Drawing.getContents(self)
> The MyLogo class can be added as a flowable Drawing or used in some
> more comples way to draw onto a canvas.
More information about the reportlab-users