nbconvert_reportlab: Alternative to convert notebooks to PDFs

121 views
Skip to first unread message

Thomas Kluyver

unread,
Sep 29, 2016, 9:29:56 AM9/29/16
to Project Jupyter
In the last few days, I've put together an nbconvert plugin that uses Reportlab to generate PDFs directly, rather than building a Latex document and converting it to PDF.

This is very new and experimental, and there are lots of things it doesn't support yet, but it has the potential to avoid a lot of the complexity that arises from generating and compiling Latex. It can also be entirely installed with pip, as the functionality it needs is all in Python packages.

Example output: https://github.com/takluyver/nbconvert-reportlab/blob/master/Trapezoid%20Rule.pdf

So far, it supports:

- Code cells
- Plain text output
- PNG image output
- Basic Markdown (no tables or footnotes yet)
- Block maths (using matplotlib's mathtext renderer)

Install with:
pip install nbconvert_reportlab
And use with:
jupyter nbconvert --to pdf-rl MyNotebook.ipynb
This also forms an example of shipping an exporter outside the nbconvert package, and of an
exporter which does not use a template.
Feel free to kick the tyres!
Thomas

Brian Granger

unread,
Sep 29, 2016, 9:51:13 AM9/29/16
to Project Jupyter
Ohhhh, very nice!!!
> --
> You received this message because you are subscribed to the Google Groups
> "Project Jupyter" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jupyter+u...@googlegroups.com.
> To post to this group, send email to jup...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jupyter/CAOvn4qg1fnpRoAyqS8uyPFhQMEqEQVk3fXpxMThSWxtbpQtReA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.



--
Brian E. Granger
Associate Professor of Physics and Data Science
Cal Poly State University, San Luis Obispo
@ellisonbg on Twitter and GitHub
bgra...@calpoly.edu and elli...@gmail.com

jmarcell...@ufpi.edu.br

unread,
Sep 29, 2016, 8:38:16 PM9/29/16
to Project Jupyter
hi takowl
this error occurs:
from html import escape
ImportError: No module named html

Thomas Kluyver

unread,
Sep 30, 2016, 9:05:50 AM9/30/16
to Project Jupyter
On 30 September 2016 at 01:38, <jmarcell...@ufpi.edu.br> wrote:
this error occurs:
from html import escape
ImportError: No module named html

Thanks for trying it. I forgot to mention that it requires Python 3.

Kyle Kelley

unread,
Sep 30, 2016, 11:00:48 AM9/30/16
to jup...@googlegroups.com
That looks beautiful.

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.



--
Kyle Kelley (@rgbkrklambdaops.com)

Thomas Kluyver

unread,
Sep 30, 2016, 11:42:02 AM9/30/16
to Project Jupyter
On 30 September 2016 at 16:00, Kyle Kelley <rgb...@gmail.com> wrote:
That looks beautiful.

Thanks! I was pleasantly surprised by how easily all the pieces came together to make something that worked. There are still a lot of rough edges, but I could get it to a basically working state quite quickly.

jmarcell...@ufpi.edu.br

unread,
Sep 30, 2016, 11:50:07 PM9/30/16
to Project Jupyter
I have python 3 installed, but still the error occurs :(

Thomas Kluyver

unread,
Oct 2, 2016, 4:14:04 AM10/2/16
to Project Jupyter
On 1 October 2016 at 04:50, <jmarcell...@ufpi.edu.br> wrote:
I have python 3 installed, but still the error occurs :(

If it's the same error message as you got before, then you are probably not running it in Python 3, because the html module is part of the standard library:
https://docs.python.org/3/library/html.html

If in doubt, create a new conda env or virtualenv using Python 3, and install into that.

You also currently need a development installation of the package pdfrw; I'll try to push the author of that to make a new release.
Reply all
Reply to author
Forward
0 new messages