[reportlab-users] SVG and EPS

Rob Schall 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.
Rob

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 
>> created.
>>
>> 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),
>             )
>     ops=[0,2,2,1,1,1,2,1,1,2,1,2,2,2,1,1,1,2,2,2,2,2,2,1,2,2,2,2,
>         2,2,3,0,2,1,1,1,1,2,3,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
>         1,1,1,1,1,1,1,1,1,1,1,3,0,1,1,1,3,0,1,1,1,1,1,1,1,1,1,1,3,
>         0,1,1,1,1,1,1,1,1,1,1,3,0,2,1,1,1,1,1,2,1,1,1,1,1,1,1,1,3,
>         0,2,2,2,2,2,3,0,2,2,2,2,2,2,3,0,1,1,1,2,2,2,1,1,1,1,1,1,1,
>         1,1,1,1,2,2,2,2,1,1,1,1,3]
>     pts = [ 
> 188.519,219.814,196.405,219.814,203.756,217.962,209.370,216.478,
>             
> 197.476,218.565,179.026,215.539,169.497,208.030,169.497,166.822,
>             
> 204.480,166.822,204.480,213.696,212.046,212.318,217.763,209.254,
>             
> 219.730,206.889,219.730,166.822,228.869,166.822,221.717,158.753,
>             
> 208.334,153.831,196.801,155.646,196.801,153.962,196.801,153.962,
>             196.798,153.962,196.801,153.962,230.05......
>            ]
>     def __init__(self,width=417.279,height=287.154,*args,**kw):
>         Drawing.__init__(self,width,height,*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.add(Path(self.pts,self.ops,fillColor=self.logoFillColor,strokeWidth=self.logoStrokeWidth,strokeColor 
> = self.logoStrokeColor or self.logoFillColor),'P')
>         if self.backgroundColor:
>             self.background = 
> Rect(0,0,self._w0,self._h0,fillColor=self.backgroundColor,strokeWidth=self.logoStrokeWidth,strokeColor=self.backgroundColor) 
>
>         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 mailing list