Automating ipython output to pdf

前端 未结 2 796
没有蜡笔的小新
没有蜡笔的小新 2021-02-15 04:30

I have a little program that basically does all kinds of statistical calculation and prints out results and charts.

At present, a convenient way to get a nice pdf output

2条回答
  •  爱一瞬间的悲伤
    2021-02-15 05:18

    As of now there's not a programming language API to convert notebooks to PDF. However, a command line utility exists called nbconvert. It has the same functionality as the web interface's format converters. To convert to PDF, you can do jupyter nbconvert notebook.ipynb --to pdf.

    Luckily, Python has a handy subprocess module which allows you to spawn new processes, check their inputs and outputs, and get their return codes. So you could do something like:

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

    Kind of a hacky way, but it will work. If you're using Windows, you may need to add the additional kwarg shell=True to subprocess.call()

提交回复
热议问题