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 :)
问题:
回答1:
Convert the IPython notebook file to html.
ipython nbconvert --to html notebook.ipynb
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.
wkhtmltopdf notebook.html notebook.pdf
回答2:
ipython nbconvert mynotebook.ipynb --to latex --post PDF
回答3:
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
.
回答4:
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:
- First, from your Jupyter notebook interface convert your *.ipynb to *.html using
File > Download as > HTML(.html)
- Upload the newly created *.html file to https://www.sejda.com/html-to-pdf and then select the option HTML to PDF.
- Your pdf file is now ready for download.
回答5:
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:
- Start the jupyter notebook that you want to save in HTML format. First save the notebook properly so that HTML file will have a latest saved version of your code/notebook.
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:
- Now open that
notebook_name.html
file (click on it). It will be opened in a new tab of your browser. - Now go to print option. From here you can save this file in pdf file format.
Note that from print option we also have the flexibility of selecting a portion of a notebook to save in pdf format.
回答6:
ipython nbconvert notebook.ipynb --to pdf