[reportlab-users] Integrate "Flowable" (SVG) with caching
Yannick Gosteli @ PETZI
yannick.gosteli at petzi.ch
Thu Nov 16 06:56:47 EST 2017
Thx to Patrick & Robin for your suggestions.
After some tests, my current conclusion is that the workaround I
suggested below (rendering the SVG into a PIL and use Canvas.drawImage)
is the easiest way to go.
Main issue here is that Reportlab seems not able to work with vectorial
component (you need to rendering your vectorial image to implement it in
your doc - please correct me if I'm wrong).
Working with pdfrw to build the SVG into a PDF and then implement this
PDF into another looks a bit experimental and complicated. I don't have
time to spend now to go deeper in this solution.
The most interesting examples I found using this solution would be
those: http://ralsina.me/weblog/posts/BB753.html &
https://stackoverflow.com/questions/4690585/is-there-a-matplotlib-flowable-for-reportlab/13870512#13870512
Working with a "form" seems not do what I need since rendering the SVG
via RenderPDF.draw() between a beginForm/endForm make the rendering in a
fix position (didn't find a way to set a x/y position).
Then rendering the SVG via RenderPM.drawToPIL() (via a "form" or not),
comes back to the same workaround I suggested below.
Let me know if you have any other suggestions or better analyses.
Best Regards
Yannick
Yannick Gosteli
PETZI - Association suisse des clubs de musiques actuelles
Billetterie/Petzitickets
yannick.gosteli at petzi.ch
www.petzi.ch - www.petzitickets.ch
Le 15. 11. 17 à 22:23, Yannick Gosteli @ PETZI a écrit :
> Dear,
>
> I generate a document that contains a SVG repeated several times.
> I wonder if there is a way to integrate this SVG with "caching" the
> same way it works with Canvas.drawImage*.
>
> My problem is the PDF file size blows up when I integrate a SVG dozens
> or even hundreds times.
> I "abstracted" my problem here:
> https://github.com/Gostich/reportlab_test_svg/blob/master/test.py
>
> I currently found a workaround that is not that bad by rendering my
> SVG into a PIL image and then use Canvas.drawImage.
> You can check my workaroud here:
> https://github.com/Gostich/reportlab_test_svg/blob/master/test2.py
>
> Does anybody has a better way to do that?
>
> Best regards
> Yannick
>
> * From the reportlab userguide about Canvas.drawImage: "However, we
> use a caching system; a given image will only be stored the first time
> it is used, and just referenced on subsequent use"
>
More information about the reportlab-users
mailing list