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.
Could you try converting first to .tex (with the --to latex exporter invocation) and then manually converting to pdf using xelatex?
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.
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.
@mpacer you are right once I get the latex file i can compile it manually with my latex compiler with no issues. I guess It confirms @takluyver explanation.
Why don't we have access to download as latex via the file menu? Is this intentional?
Great question! i'll make a PR and we'll find out.
On Wed, Mar 22, 2017 at 9:26 AM, Alexandre Couedelo <
[email protected]> wrote:
@mpacer https://github.com/mpacer you are right once I get the latex
file i can compile it manually with my latex compiler with no issues. I
guess It confirms @takluyver https://github.com/takluyver explanation.Why don't we have access to download as latex via the file menu? Is this
intentional?—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/jupyter/nbconvert/issues/552#issuecomment-288456048,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACXg6P9g_pgRrGez90ig_kJf34XX3O7vks5roUukgaJpZM4Mi84L
.
@xNok So made a PR, but even if that is merged, I'd still recommend using the LaTeX converter from the command line because right now the download buttons aren't exactly emulating the functionality of the command line LaTeXExporter.
Specifically, the command line LaTeX exporter will create a directory of files to represent any of your outputs that need to be called from an external source (i.e., images which are included via \begin{figure}…\end{figure}). In order to do this in the browser, we need to return a zip file (not just a TeX file) that will contain both the .tex and the appropriate images. Right now that zipping utility doesn't seem to be being triggered for either the LaTeX or the Markdown exporter (didn't test others but I'm guessing its the same). There are utilities for creating that zip file, but they aren't being used right now; I'm not sure why.
This happens to be part of a more general project I'm going to be working on re: better in browser conversion capabilities. Keep an eye out for my PRs on the notebook repo in the coming weeks for updates.
edit: Corrected earlier mistakes
Correction — the LaTeX file will grab outputs and instead with download a zip if there are outputs. I just didn't realise that my test notebook for this didn't have any output images.
What sintax should I use to include the images correctly into the notebooks? I've tried the latex suggestion, but it did not work...By the way, there was no command into the .tex file to include the image. (The images are correctly rendered if the notebook is opened on my browser)
I import images to my notebooks with this sintax: 
If I use the image's URL instead of its path, the pdf output does not include the image as well...
Please see the following code of auto generated Latex file created by Jupyter Notebook (ipynb) file. You can open the .tex extension file in the editor and go to the line 32 or 33 where you will find the bold line and comment it out. Your problem will be partially solved.
Code:
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
\else\Gin@nat@width\fi}
\makeatother
\let\Oldincludegraphics\includegraphics
% Set max figure width to be 80% of text width, for now hardcoded.
(%)\renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=.8\maxwidth]{#1}}
After commenting it out, find the image attachment command in .tex file. When you find that lines where compiler stops usually. replace the line of:
adjustmentbox
with:
\includegraphics[scale=0.5 or whatever you desire]{yourimage.png}
Hope it solves your problem, mine is solved and i generated pdf from latex including graphics.
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
@peteflorence Print Preview doesn't work for me for a full slide deck, it will only prepare a pdf of the slide being viewed. nbconvert would/should produce the full deck.
In my case, I added a .png file using a website URL. Currently it does not work.
Hope my comment helps.
Hi,
I had the same issue, but I solved it by modifying the path of image file. Below is what I did:Background:
- Previously, I set
, the path is kind of relative path; and the notebook can not convert it to PDFHow I solved it:
- I changed the format of the path to
. Notice that I removed./which is to represent the current path.My guess:
- I did not check the source code and how it works, but I guess it append the path
image/ex2.13.pngto a `base_dir''. And if we used./` at the head of path, it will raise errors.
Thank you so much! Solved my issue by deleting "./"
Hi, I succeed to include image when converting ipynb to pdf.
However, some funny thing showed up, the image doesn't belong where they're supposed to be.
Like, the picture I insert in the first markdown cell shows up in the next md cell or somewhere strange.
I don't quite know about latex, so I haven't consider manually edit the tex file, I wonder if there is any easy solution?
Much thanks
@1uciusy I think I have a solution: add
\usepackage{float}
\floatplacement{figure}{H}
somewhere to the top of the latex file, but after the \documentclass.
Ultimately, I think that issue is worth a bug report of it's own. I'll working on submitting some of my fixes some one of my other repos back to nbconvert and this will be one of them.
Interestingly, if the latex file to be manually converted to a pdf is created by using the JupyterLab File>Export Notebook As... conversion. TeXworks will not find any embedded .png files.
I advise to always create the latex files in the command line as:
jupyter nbconvert --to latex notebook_name.ipynb
nbconvert --to latex
even does not detect figure place if it uses html syntax in markdown cell:
<img src='images/denoising.png' />
nbconvert --to latex
even does not detect figure place if it uses html syntax in markdown cell:<img src='images/denoising.png' />
see mpacer's comment on mar 20 2017 above, support for general html in markdown cells is not guaranteed
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
@SebastianSager re 1 we got image export working using matplotlib image
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.
Some of theses issues are a real pain to fix in nbconvert. I'm planning to get some fixes in for the 6.0 release that will help with some, but no one's really spending the significant time to refactor and address some of the fundamental issues causing these (many aren't even in jupyter). If someone has some time and a will to dig into the topic I'll gladly help review / advise where I can / know what's wrong, but I and the other current maintainers are unlikely to find the time to solve all of these for some time.
Hi,
I am also fighting with this issue, which, for me, roots in the relative/absolute path structures inside the provided source code. In my experience, classical file system approaches with the "file path based locating" algorithm will become more and more a problem. But alternatives a on the rise...
...Great ideas based on a somehow "contend based location system" for files, like IPFS, are a refreshing alternative to this. I would see myself interested in tackling this "Notebook - Latex - PDF - Image" issue, but I would like to know, if a IPFS based file scheme could be possibly added to Jupyter.
Since the browser support is very good for IPFS and beyond this "technical issue", thing will become much simpler to organize and allocate. I think this could be a great investment in the portability of notebooks in general, if for instance IPFS will get included.
I'm not having the full picture in mind yet, but a good gut feeling about this.
IPFS based file scheme is a pretty experimental concept, probably would be a challenge to adopt across jupyter projects as a whole. The underlying issue is with associated assets in different contexts. Filesystems have 60+ years of established precedent that we should still be trying to make usable. The main issue is with the dependent tools being so working directory constrained that they're inflexible to setting working directories / accessing relative file paths in a consistent manner. They make a lot of assumptions that don't hold up well for nbconvert's execution model.
I am facing the same issue anyone has a solution or workaround?
Same issue here. None of the solutions above works for me.
Also by doing this in a Markdown cell:
\begin{figure}[h!]
\includegraphics{myImage.png}
\end{figure}
the exported PDF does not show any image, but an empty blank space instead, by the look of it exactly of the size of the referenced image.
It seems they have an open issue for this:
https://github.com/jupyter/nbconvert/issues/1079
open since August 2019.
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.
For instance if you have a file "picture.png"
Either img src = "picture.png" or img src = "./picture.png" will both work. (Don't forget the "<" and ">" I excluded them so the comment wouldn't try to render an image)
Now assuming the HTML is in the same folder as the images and they all use the path format specified above, open the HTML in Chrome (only tested in Chrome) and the images will be there.
Press Ctrl+p and save to PDF
This is still a problem in version 6.0.7. The workaround of converting to latex then building it myself is working fine though.
Most helpful comment
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.pngto a `base_dir''. And if we used./` at the head of path, it will raise errors.