[reportlab-users] Display drawings in Jupyter notebooks

Dinu Gherman gherman at darwin.in-berlin.de
Tue Mar 17 12:51:03 EDT 2020


Hello and long time no see!

I was looking at the GitHub issue tracker,  
https://github.com/MrBitBucket/reportlab-mirror/issues, but found only  
one (closed) one, so maybe this mailing list is still the better place  
to go (?).

I'm using JupyterLab a lot these days and recently used some of  
ReportLab, again. So I've quickly found that drawings don't render  
implicitly in Jupyter notebook output cells. Sure you can do it with  
one line of code, but you don't want to do that again and again.

But making such drawings display nicely in output cells is really easy  
by adding methods like "Drawing._repr_svg_(self)" or  
"Drawing._repr_png_(self)" or even "Drawing._repr_pdf_(self)" which  
will trigger http://mozilla.github.io/pdf.js to render the PDF output.  
I have created a sample notebook gist to illustrate this (only one  
interactive bit, a slider, is missing when you see it on GitHub):

https://gist.github.com/deeplook/baaf91b1f79f5f5290e22283d17c6d6b

My questions appear at the bottom of this notebook and are repeated  
here. They are all related to the fact that one could implement  
multiple displaying options for different formats at once and I can't  
figure out an ideal way of choosing between them:

- Add one or more methods like _repr_svg_, _repr_png_, and _repr_pdf_  
(they do have some ranking inside Jupyter cells)?
- How to choose between multiple methods (if given) like _repr_svg_,  
_repr_png_, and _repr_pdf_ at runtime?
- Use a flag passed during object instantiation, Drawing(...,  
display_format="PNG")?

Any ideas?

Thanks,

Dinu





More information about the reportlab-users mailing list