Problem creating a custom Drawing Flowable to use with RML
Ray Côté <[email protected]> Tue, 20 Jun 2023 09:22:22 -0400
| Newsgroups | gmane.comp.python.reportlab.user |
|---|---|
| Message-ID | <CAG5tnzrRPJV3-aRNmw76kxBzR0K1vuD0_LEWiwwp+T=HHP-LTQ@mail.gmail.com> |
--===============5862534744288921063==
Content-Type: multipart/alternative; boundary="0000000000003118b605fe8f8ca0"
--0000000000003118b605fe8f8ca0
Content-Type: text/plain; charset="UTF-8"
I'm trying to create an SVG Flowable to use as a plugInFlowable with RML.
I've looked at several online examples and they all show how to add the
Diagram when generating the report directly with Python code.
My RML template contains the following:
<plugInFlowable module="path.to.charts"
function="chart">xyx</plugInFlowable>
When I try to draw the Flowable using the following class I get an error
that the Drawing does not contain a canv. There's a self.canv object that
has various draw commands (drawImage, drawString, etc.) but none of them
draw a Drawing object.
I appreciate any guidance as to what the draw function should be doing.
--Ray
class SvgFlowable(Flowable):
"""Convert stream containing SVG instructions to a Reportlab
flowable."""
def __init__(self, svg: BytesIO) -> None:
"""Convert SVG to RML drawing on initialization."""
svg.seek(0)
self.drawing: Drawing = svg2rlg(svg) # Convert SVG to Drawing
self.width: int = self.drawing.minWidth()
self.height: int = self.drawing.height
self.drawing._showBoundary = True
def wrap(self, *args):
return (self.width, self.height)
def draw(self) -> "Drawing":
"""Draw the chart."""
self.drawing.draw(). # Error
###
--0000000000003118b605fe8f8ca0
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_default" style=3D"font-family:arial,sa=
ns-serif">I'm trying to create an SVG Flowable to use as a plugInFlowab=
le with RML. I've looked at several online examples and they all show h=
ow to add the Diagram when generating the report directly with Python code.=
</div><div class=3D"gmail_default" style=3D"font-family:arial,sans-serif"><=
br>My RML template contains the following:<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 &=
lt;plugInFlowable module=3D"path.to.charts" function=3D"char=
t">xyx</plugInFlowable><br><br>When I try to draw the Flowabl=
e using the following class I get an error that the Drawing does not contai=
n a canv. There's a self.canv object that has=C2=A0various draw command=
s (drawImage, drawString, etc.) but none of them draw a=C2=A0Drawing object=
.=C2=A0</div><div class=3D"gmail_default" style=3D"font-family:arial,sans-s=
erif"><br></div><div class=3D"gmail_default" style=3D"font-family:arial,san=
s-serif">I appreciate any guidance as to what the draw function should be d=
oing.<br>--Ray<br><br>class SvgFlowable(Flowable):<br>=C2=A0 =C2=A0 "&=
quot;"Convert stream containing SVG instructions to a Reportlab flowab=
le."""<br><br>=C2=A0 =C2=A0 def __init__(self, svg: BytesIO)=
-> None:<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Convert SVG t=
o RML drawing on initialization."""<br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 svg.seek(0)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.drawing: Drawing =3D=
svg2rlg(svg) # Convert SVG to Drawing<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.=
width: int =3D self.drawing.minWidth()<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.=
height: int =3D self.drawing.height<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.dra=
wing._showBoundary =3D True<br><br>=C2=A0 =C2=A0 def wrap(self, *args):<br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return (self.width, self.height)<br><br>=C2=A0 =
=C2=A0 def draw(self) -> "Drawing":<br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 """Draw the chart."""<br>=C2=A0 =C2=A0=
=C2=A0 =C2=A0self.drawing.draw().=C2=A0 # Error<br><br>###<br></div></div>
--0000000000003118b605fe8f8ca0--
--===============5862534744288921063==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline