nbconvert: Pdf doesn't include images
When exporting to PDF it does not include images inserted via markdown
When using the markdown 
I got this error:
LaTeX Warning: File `pb1.png' not found on input line 320.
! Unable to load picture or PDF file 'pb1.png'.
<to be read again>
}
l.320 \includegraphics{pb1.png}
?
! Emergency stop.
<to be read again>
}
l.320 \includegraphics{pb1.png}
No pages of output.
Transcript written on notebook.log.
When using the image html tag <img src=\"pb1-bfs.png\"/>
I got no image as an output
Everything is displayed correctly in the notebook for both case.
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 42
- Comments: 36 (8 by maintainers)
Hi, I had the same issue, but I solved it by modifying the path of image file. Below is what I did:
Background:

, the path is kind of relative path; and the notebook can not convert it to PDFHow I solved it:

. Notice that I removed./
which is to represent the current path.My guess:
image/ex2.13.png
to a ``base_dir’'. And if we used./
at the head of path, it will raise errors.In case it helps people out, a surprisingly works-great workaround for this issue is to use the Print Preview, then save that to a .pdf.
That’s:
Plots, images, everything, should be in there no problem
Another note: an additional benefit of this method is that is automatically handles text wrapping. The .pdf from latex does not do text wrapping in the code cells
Updated to prefer Print Preview rather than saving to .html. The latter may have issues embedding external images, but not the former
I fixed it by converting:
<img src="loss.png" />
to:

All the comments by @mpacer and @kangwonlee are spot on and were very helpful. I’m just adding this example because I missed those on my first pass. I’m hoping this will help somebody in the future if they are scanning this issue.
I think the issue here is that our PDF conversion produces latex in a temporary directory, and then runs xelatex on it there. It extracts images embedded in the notebook to a location where it can refer to them, but it doesn’t copy images referenced from Markdown cells to a matching location in the temporary directory, so the references to them in the generated Latex break.
See also #52.
This is still a problem in version 6.0.7. The workaround of converting to latex then building it myself is working fine though.
Could you try converting first to
.tex
(with the--to latex
exporter invocation) and then manually converting to pdf usingxelatex
?Do you run into the same error?
We don’t support pdf export from general HTML markup in markdown cells. I’m not sure if this is within or outside the purview of our intended coverage area.
nbconvert --to latex even does not detect figure place if it uses html syntax in markdown cell:
For anyone experiencing this issue I found what seems to be a workaround after none of the above did.
Download the notebook as an HTML file.
Move the HTML file to a directory where ALL of your pictures are and make sure you are just using either ./ or just the image name. Then open the HTML doc
Press Ctrl+p and save to PDF
I am facing the same issue anyone has a solution or workaround?
In my case I needed to use the html
img
tag so that I could set the size of the image using thewidth
attribute, which can’t be done with the pure markdown syntax. However, I found a work-around that allowed the image size to be set and the image would be included in the output pdf. This is based on the solution by @tashrifbillah https://github.com/jupyter/nbconvert/issues/1079#issuecomment-1012601618 and this Stack Overflow answer:Image
object (which allowswidth
andheight
to be set):The pdf should now contain the image!
@SebastianSager re 1 we got image export working using matplotlib image
Hi!
I am also using
jupyter nbconvert --to latex $name.ipynb
and “lose” the markup included images, e.g.,
<img width="75%" src="png/rosenbrock2.png"></img>
is not included at all in the tex document. What I did not get from the current discussion:
<!-- ... -->
do not work, unfortunately, as they are also not exported.I use the export on a large number of lecture scripts and have some sed-based postprocessing of the LaTeX files, so I would really appreciate some way to export the file information into the tex file (even if it were commented out, then I could include it myself via sed).
Thanks a lot, best regards
Edit: I found a way around the issue. Ugly, but at least it works. I add
$$ %imagePostProcess png/rosenbrock2.png $$
to my markup text and replace it then afterwards using sed:
sed -r -i 's/\\\[ %imagePostProcess (.+) \\\]/\n\n\\begin\{center\} \\adjustimage\{max size=\{0.9\\linewidth\}\{0.9\\paperheight\}\}\{..\/\1\} \\end\{center\} \{ \\hspace*\{\\fill\} \\\\\}/' $name.tex