I'm trying to export my IPython notebook to pdf, but somehow I can't figure out how to do that. I searched through stackoverflow and already read about nbconvert, but where do I type that command? In the notebook? In the cmd prompt? If someone can tell me, step by step, what to do? I'm using Python 3.3 and IPython 1.1.0. Thank you in advance :)
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
Convert the IPython notebook file to html.
This will convert the IPython document file notebook.ipynb into the html output format.
Convert the html file notebook.html into a pdf file called notebook.pdf. In Windows, Mac or Linux, install wkhtmltopdf. wkhtmltopdf is a command line utility to convert html to pdf using WebKit. You can download wkhtmltopdf from the linked webpage, or in many Linux distros it can be found in their repositories.
I was facing the same problem. I tried to use the option select File --> Download as --> Pdf via LaTeX (.pdf) in the notebook but it did not worked for me(It is not working for me). I tried other options too still not working.
I solved it by using the following very simple steps. I hope it will help you too:
You can do it by 1st converting the notebook into HTML and then into PDF format:
Following steps I have implemented on: OS: Ubuntu, Anaconda-Jupyter notebook, Python 3
1 Save Notebook in HTML format:
Run the following command from the notebook itself:
!jupyter nbconvert --to html notebook_name.ipynb
After execution will create HTML version of your notebook and will save it in the current working directory. You will see one html file will be added into the current directory with
your_notebook_name.html
name(
notebook_name.ipynb
-->notebook_name.html
).2 Save html as PDF:
notebook_name.html
file (click on it). It will be opened in a new tab of your browser.Note that from print option we also have the flexibility of selecting a portion of a notebook to save in pdf format.
If you are using sagemath cloud version, you can simply go to the left corner,
select File
-->Download as
-->Pdf via LaTeX (.pdf)
Check the screenshot if you want.
If it dosn't work for any reason, you can try another way.
select File
-->Print Preview and then on the preview
right click
-->Print and then select save as pdf
.ipython nbconvert mynotebook.ipynb --to latex --post PDF
ipython nbconvert notebook.ipynb --to pdf
Other suggested approaches:
Using the 'Print and then select save as pdf.' from your HTML file will result in loss of border edges, highlighting of syntax, trimming of plots etc.
Some other libraries have shown to be broken when it comes to using obsolete versions.
Solution: A better, hassle-free option is to use an online converter https://www.sejda.com/html-to-pdf which will convert the *.html version of your *.ipynb to *.pdf.
Steps: