Nova Kwok's Awesome Blog

Solve the problem Jupyter Notebook failed to export to PDF with images

On dealing documents with images using Jupyter Notebook, we can easily find that the default export to PDF selection will produce the PDF without any images. While as on the GitHub Issue page many suggest the method of exporting to Tex first and then convert it to PDF with xelatex manually, simply exporting to Tex and compile it to PDF without any modification will not work.

In this article I would like to share a working solution that works for me.

Let’s first talk about the error on generating those PDFs.

Using Image Link

In the Tex version of export, the images are rendered as the following line:


Compiling with the file like this will most likely to produce the problem as below:

LaTeX Warning: File `' not found
 on input line 407.

! Unable to load picture or PDF file '
<to be read again> 
l.407 .../}

Importing Images in Jupyter Notebook

Looks good in Jupyter Notebook, but will still meet errors in compile stage.

LaTeX Warning: File `attachment:1c8573bf621ef3a18687ad4aeb50df32.jpg.png' not f
ound on input line 409.

! Unable to load picture or PDF file 'attachment:1c8573bf621ef3a18687ad4aeb50df
<to be read again> 
l.409 ...1c8573bf621ef3a18687ad4aeb50df32.jpg.png}

Current Solution

The current solution that works for me is to export the Notebook to Tex, then manually dealing with the images (and document title, author, date as well) in the Tex file, as an example, I place the image in the path ./images/enron.jpg to the exported Tex file, then replace the wrong image path generated by Jupyter Notebook to the form as below:

        \caption{Visualized Data of Enron Database.}

Then use xelatex to compile the Tex file.

#Jupyter #English #Tex