Automate ipython output to pdf

I have a small program that basically performs all kinds of statistical calculations and prints the results and graphs.

Currently, a convenient way to get good pdf output from my program is to run my code in Jupyter IPython Notebook using the magic% matplotlib inline command and save it in pdf format by executing "PDF via LaTex (.pdf)"

But the problem is that I have to do this every time I run the program. In addition, I cannot deliver the program as a binary executable to other people, which is my ultimate goal.

Is there any way to do this programmatically? Just to make it clear, all I need is the output of my program in pdf format, so when I run the executable file, the output will be pdf. I do not want the end user to create an ipython notebook. The end user will not have access to the source code.

enter image description here

+8
source share
3 answers

There is currently no programming API for converting laptops to PDF. However, the command line utility exists nbconvert . It has the same functions as web interface format converters. To convert to pdf you can do jupyter nbconvert notebook.ipynb --to pdf.

, Python , , . , - :

import subprocess
subprocess.call("jupyter nbconvert notebook.ipynb --to pdf")

, . Windows, kwarg shell=True subprocess.call()

+9

IPython, bash script, , PDF . bash script :

jupyter nbconvert --ExecutePreprocessor.timeout=500 --to notebook --execute my_file.ipynb
jupyter nbconvert --to pdf my_file.nbconvert.ipynb
rm my_file.nbconvert.ipynb

, , , pandoc PDF :

jupyter nbconvert --ExecutePreprocessor.timeout=500 --to notebook --execute my_file.ipynb
jupyter nbconvert  --to markdown my_file.nbconvert.ipynb  --template="mytemplate.tpl"
pandoc --toc --template=mytemplate.tex markdown my_file.nbconvert.ipynb --latex-engine=pdflatex -o final file.pdf
+3

On Windows, if you want to convert recursively , you can use the git-bash window and do something like this:

$ find /d/we_are_on_disk_d/path_to_ipynb_files/ -name '*.ipynb' | xargs jupyter nbconvert --to [script|pdf]
0
source

All Articles