New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pdf doesn't include images #552

Open
xNok opened this Issue Mar 20, 2017 · 13 comments

Comments

Projects
None yet
10 participants
@xNok
Copy link

xNok commented Mar 20, 2017

When exporting to PDF it does not include images inserted via markdown

When using the markdown ![Description](pb1.png) 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.

@mpacer

This comment has been minimized.

Copy link
Member

mpacer commented Mar 20, 2017

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.

@takluyver

This comment has been minimized.

Copy link
Member

takluyver commented Mar 21, 2017

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.

@xNok

This comment has been minimized.

Copy link

xNok commented Mar 22, 2017

@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?

@mpacer

This comment has been minimized.

Copy link
Member

mpacer commented Mar 22, 2017

@mpacer

This comment has been minimized.

Copy link
Member

mpacer commented Mar 22, 2017

@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

@mpacer

This comment has been minimized.

Copy link
Member

mpacer commented Mar 24, 2017

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.

@jmarcoscosta

This comment has been minimized.

Copy link

jmarcoscosta commented Apr 14, 2017

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...

@hagger98

This comment has been minimized.

Copy link

hagger98 commented Aug 9, 2017

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.

@xiaoleihuang

This comment has been minimized.

Copy link

xiaoleihuang commented Feb 4, 2018

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 ![ex 2.13](./image/ex2.13.png), the path is kind of relative path; and the notebook can not convert it to PDF

How I solved it:

  • I changed the format of the path to ![ex 2.13](image/ex2.13.png). 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.png to a ``base_dir''. And if we used ./ at the head of path, it will raise errors.
@peteflorence

This comment has been minimized.

Copy link

peteflorence commented Feb 21, 2018

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:

  • File --> Print Preview
  • "Print" this preview in your browser, but really save it to a .pdf

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

@paulperry

This comment has been minimized.

Copy link

paulperry commented Mar 2, 2018

@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.

@kangwonlee

This comment has been minimized.

Copy link

kangwonlee commented Oct 10, 2018

In my case, I added a .png file using a website URL. Currently it does not work.

Hope my comment helps.

@KuangcongLiu

This comment has been minimized.

Copy link

KuangcongLiu commented Jan 14, 2019

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 ![ex 2.13](./image/ex2.13.png), the path is kind of relative path; and the notebook can not convert it to PDF

How I solved it:

  • I changed the format of the path to ![ex 2.13](image/ex2.13.png). 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.png to 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 "./"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment