[reportlab-users] Problem creating a custom Drawing Flowable to use with RML

Ray Côté ray+rl at appropriatesolutions.com
Thu Jun 29 11:05:51 EDT 2023


I've created an example RML plugInFlowable for Matplotlib charts.
Available at:
https://github.com/rgacote/reportlab-flowable-for-rml/tree/main

On Tue, Jun 20, 2023 at 12:01 PM Ray Côté <ray+rl at appropriatesolutions.com>
wrote:

> Found the solution.
>
>     def draw(self) -> None:
>         """Draw the chart."""
>         renderPDF.draw(self.drawing, self.canv, 0, 0)
>
> I'll write the full implementation up as a Gist.
>
> On Tue, Jun 20, 2023 at 9:22 AM Ray Côté <ray+rl at appropriatesolutions.com>
> wrote:
>
>> 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
>>
>> ###
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist2.pair.net/pipermail/reportlab-users/attachments/20230629/aec64826/attachment.htm>


More information about the reportlab-users mailing list