IPython / Jupyter Problems Saving Laptop in PDF

So, I tried to save the jupyter notepad in PDF format, but I just can't figure out how to do this. The first thing I'm trying to do from the file menu is just to download in PDF format, but this leads to:

nbconvert failed: PDF creating failed 

The next thing I'm trying to do is try to do a conversion from the command line like this

 $ ipython nbconvert --to latex --post PDF MyNotebook.ipynb 

but again, this leads to an error message

 ImportError: No module named 'PDF' 

and if I try

 $ ipython nbconvert --to latex MyNotebook.ipynb 

it leads to

 IPython.nbconvert.utils.pandoc.PandocMissing: Pandoc wasn't found: Please check that pandoc is installed 

if i try to install pandoc ( pip install pandoc ) it gives me

 ImportError: No module named 'ConfigParser' 

and that’s where I get stuck because I just don’t know what else to do. Does anyone have an idea how to fix something wrong?

+69
pdf ipython jupyter
Mar 19 '15 at 23:12
source share
15 answers

If you are on a Mac and you have Homebrew installed, open a terminal shell and install pandoc by typing:

brew install pandoc

To be patient, the time to install and compile may take some time on slow Internet connections or older systems.

+27
Apr 10 '15 at 13:51 on
source share
— -

To make it work, I installed latex, typical latex extra and pandoc.

With ubuntu:

 sudo apt-get install texlive texlive-latex-extra pandoc 

several times required: several 100 MB to download. I read somewhere that you can use --no-install-recommends for texlive and extra to reduce to dl.

+23
Apr 13 '16 at 12:35
source share

2015-4-22: IPython update seems to mean that --to latex --post PDF should be used instead of --to latex --post PDF . There is a related Github issue.

+11
Apr 22 '15 at 22:08
source share

To convert notebooks to PDF, you must first install nbconvert.

 pip install nbconvert # OR conda install nbconvert 

Further, if you are not using Anaconda or have not done so already, you must install pandoc by following the instructions on their website or on Linux as follows:

 sudo apt-get install pandoc 

After that, you need to install XeTex on your computer:

Now you can go to the folder containing your IPython Notebook and run the following command:

 jupyter nbconvert --to pdf MyNotebook.ipynb 

For further reference, please check this link .

+8
Oct 21 '18 at 8:30
source share

As stated in the commentary on the question, you will need pandoc and latex (e.g. TeXShop). I installed pandoc with Homebrew, it only took a second. With pandoc and TeXShop, I could create latex, but not pdf (on the command line).

 ipython nbconvert --to latex mynotebook.ipynb 

Examining the latex (.tex) file using TeXShop, the failure occurred due to the lack of stylesheets and defs. After setting all these parameters (adjustbox.sty, adjcalc.sty, trimclip.sty, collectbox.sty, tc-pgf.def, ucs.sty, uni-global.def, utf8x.def, ucsencs.def), he finally , Work.

However, the result looks a little too scared for my taste. It is very bad that printing html from Safari loses syntax coloring. Otherwise, it doesn’t look so bad. (All this on OS X).

+4
Nov 06 '15 at 14:42
source share

This Python script has a graphical interface for selecting with the Ipython Notebook Explorer you want to convert to pdf. The wkhtmltopdf approach is the only approach I have found that works well and provides high quality pdf files. The other approaches described here are problematic, syntax highlighting does not work or corrupted graphics.

You will need to install wkhtmltopdf: http://wkhtmltopdf.org/downloads.html

and nbconvert

 pip install nbconvert # OR conda install nbconvert 

Python script

 # Script adapted from CloudCray # Original Source: https://gist.github.com/CloudCray/994dd361dece0463f64a # 2016--06-29 # This will create both an HTML and a PDF file import subprocess import os from Tkinter import Tk from tkFileDialog import askopenfilename WKHTMLTOPDF_PATH = "C:/Program Files/wkhtmltopdf/bin/wkhtmltopdf" # or wherever you keep it def export_to_html(filename): cmd = 'ipython nbconvert --to html "{0}"' subprocess.call(cmd.format(filename), shell=True) return filename.replace(".ipynb", ".html") def convert_to_pdf(filename): cmd = '"{0}" "{1}" "{2}"'.format(WKHTMLTOPDF_PATH, filename, filename.replace(".html", ".pdf")) subprocess.call(cmd, shell=True) return filename.replace(".html", ".pdf") def export_to_pdf(filename): fn = export_to_html(filename) return convert_to_pdf(fn) def main(): print("Export IPython notebook to PDF") print(" Please select a notebook:") Tk().withdraw() # Starts in folder from which it is started, keep the root window from appearing x = askopenfilename() # show an "Open" dialog box and return the path to the selected file x = str(x.split("/")[-1]) print(x) if not x: print("No notebook selected.") return 0 else: fn = export_to_pdf(x) print("File exported as:\n\t{0}".format(fn)) return 1 main() 
+3
Jun 30 '16 at 19:23
source share

I am using Anaconda-Jupyter laptop on OS: Ubuntu 16.0 for programming in Python.

Install Nbconvert, Pandoc and Tex:

Open a terminal and execute the following commands in it.

Install Nbconvert: Although it is part of the Jupyter ecosystem, install it again

 $conda install nbconvert 

Or

 $pip install nbconvert 

But I recommend using conda instead of pip if you use anaconda

Install Pandoc: because Nbconvert uses Pandoc to convert markdowns to formats other than HTML. Enter the following command

 $sudo apt-get install pandoc 

Install TeX: nbconvert uses TeX to convert to PDF. Enter the following command

 $sudo apt-get install texlive-xetex 

After executing these commands, close the open notebooks, refresh the home page, or restart the kernel of the open notebook. Now try to download notepad in PDF format :)

Note: for more details, please refer to the official documentation:
https://nbconvert.readthedocs.io/en/latest/install.html

+3
Aug 13 '18 at 6:17
source share

To convert any Jupyter laptop to PDF, please follow the instructions below:

( Being in a Jupyter notebook ):

On Mac OS :

+ P command → you will get a print dialog → change destination in PDF → click print

On Windows :

Ctrl + P → you get a print dialog → change destination in PDF → click print

If the steps above do not generate the full PDF of the Jupyter laptop (possibly because Chrome sometimes doesn’t print all the output, because Jupyter scrolls for large output),

Try the following steps to remove auto-scroll in the menu : -

Credits: @ AngeloPolotto

  1. In a Jupyter notebook, click Cellular at the top of the Jupyter notebook enter image description here

  2. Next, click All WeekendToggle Scrolling to delete autoscrolling.

enter image description here

+2
Apr 23 '19 at 2:50
source share

This issue has occurred with both Ubuntu and Mac OSX. After an insane set of searches and trials, they were both resolved. This requires both tex and pandoc ; both jumbo external programs cannot be installed by python pip .

Mac OSX: using MacPorts to install pandoc

port install pandoc

It will take about an hour (in the usual case). If the problem persists, you may need to install the MacTeX distribution. TeXLive.

For Ubuntu: install vanilla TeXLive from a network installer - not through apt-get . Then install pandoc using apt-get.

sudo apt-get install pandoc

A full TeXLive installation will require up to 4.4 GB of disk space.

To save all these problems, the recommended way to use IPython / Jupyter Notebook would be to install the Anaconda Python distribution.

+1
Jan 29 '16 at 4:51 on
source share

If you are using the sagemath cloud version, you can just go to the left corner,
select File → Download as → Pdf via LaTeX (.pdf)
Check the screenshot if you want.

Convert ipynb to pdf screenshot

If it does not work for any reason, you can try a different way.
select File -> Preview, and then Preview
right-click → Print, and then select save as pdf.

+1
Dec 23 '16 at 7:46
source share

As a new member, I could not just add a comment to the post, but I want to say that the solution proposed by Philippe Schwartz worked for me. We hope that people in a similar situation are more likely to try this way with an accent. Lack of page breaks has been a problem for a long time, so I am grateful for the discussion above.

As Philippe Schwartz said: “You need to install wkhtmltopdf: [ http://wkhtmltopdf.org/downloads.html†[1]

and Nbconvert "

Then you add a cell of type "rawNBConvert" and include:

<p style="page-break-after:always;"></p>

It looks like it helped me, and the generated PDF had a page break in the appropriate places. You do not need to run custom code, as it seems that the “normal” way to load a notebook in HTML format, open it in a browser and print to PDF works after installing these utilities.

+1
Jan 13 '18 at 19:29
source share

I had all kinds of problems with this. I don’t know if it will provide exactly what you need, but I downloaded my laptop as an HTML file, then pulled it out in my Chrome browser and printed it as a PDF file, which I saved. It captured all my code, text and graphics. That was enough for what I needed.

0
Apr 02 '16 at 19:00
source share

I found that nbconvert / utils / pandoc.py had a code error that led to an error for my machine. The code checks to see if pandoc is in your environment variable path. For my car, the answer is no. However, pandoc.exe is!

The solution was to add ".exe" to the code on line 69

 if __version is None: if not which('pandoc.exe'): raise PandocMissing() 

The same thing for xelatex is not installed. Add to nbconvert / exporters / pdf.py on line 94

  cmd = which(command_list[0]+'.exe') 
0
Nov 02 '17 at 22:51
source share

To convert .ipynb to pdf, your system must contain 2 components:

  1. nbconvert : is part of jupyter allows you to convert ipynb to pdf

     pip install nbconvert OR conda install nbconvert 
  2. XeTeX: Convert ipynb to .tex format and then convert to pdf.

     sudo apt-get install texlive-xetex 

Then you can use the command below to convert to PDF,

 ipython nbconvert --to pdf YOURNOTEBOOK.ipynb 

In case this does not work, install pandoc and try again.

 sudo apt-get install pandoc 
0
Jun 30 '19 at 9:36
source share

For Ubuntu users, the answer can be found here . I also quote this:

The most likely reason is that you have not installed the appropriate dependencies. Your Ubuntu system must have several packages installed to convert LaTeX and XeTeX files to save your notepad in PDF format. You can install them:

 sudo apt-get install texlive texlive-xetex texlive-generic-extra texlive-generic-recommended pandoc 

In addition, nbconvert is another dependency that is usually automatically installed with Jupyter. But you can install it to be sure while activating the virtual environment:

 pip install -U nbconvert 
0
Sep 27 '19 at 15:27
source share



All Articles