# Unknown Graphics Extension PNG/PDF

I was having no problem with this until a couple of hours ago. Everything was working perfectly, until pdftex suddenly decided to throw errors on including graphics (example is png, but was originally pdf).

The following are the packages I'm using:

\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{colortbl}
\usepackage{placeins}
\usepackage[margin=2.5cm]{geometry}
\usepackage{multirow}


The following is the code I'm using to load the image:

\begin{figure}[h]
\centering
\includegraphics[width=0.8\textwidth]{ test.png }
\end{figure}


geometry driver: auto-detecting geometry detected driver: pdftex

LaTeX Warning: No \author given.

./.Report.tex.swp:15: LaTeX Error: Unknown graphics extension : .png .

See the LaTeX manual or LaTeX Companion for explanation. Type H for immediate help. ...

l.15 ...egraphics[width=0.8\textwidth]{ test.png

./.Report.tex.swp:15: ==> Fatal error occurred, no output PDF file produced! Transcript written on /tmp/.Report.tex.log.

I've also tried specifying the type and extension, but it provides me with a different error. So, for the code...

\begin{figure}[h]
\centering
\includegraphics[width=0.8\textwidth, type=png, ext=.png]{ test }
\end{figure}


with the following error...

geometry driver: auto-detecting geometry detected driver: pdftex

LaTeX Warning: No \author given.

./.Report.tex.swp:15: LaTeX Error: Cannot determine size of g raphic in test .png (no size specifed).

See the LaTeX manual or LaTeX Companion for explanation. Type H for immediate help. ...

l.15 ...0.8\textwidth, type=png, ext=.png]{ test } ./.Report.tex.swp:15: ==> Fatal error occurred, no output PD F file produced! Transcript written on /tmp/.Report.tex.log.

Few things of note: I'm using Gummi, but pdflatex has the same errors when I run it in a terminal. The images are generated by python's matplotlib library. This all seemed to start when I first used the grffile package (as my original files had multiple ., now removed) but it's definitely not being used anymore.

I presume something has gone wrong with the installation here, but I thought I would ask in case I'm missing something. Please let me know if you want any additional details.

Thanks

• Please show the beginning of the log-file as well. Mar 15 '15 at 17:17
• Don't use spaces in your file names, or even the argument that you pass.
– Werner
Mar 15 '15 at 17:19
• The error message is pretty clear: the unknown extension is “.png ” (with a space at the end). The input should be \includegraphics[<options>]{test.png} (or without the extension, but no space). Mar 15 '15 at 17:33
• Out of curiosity, why are you running pdflatex on a swap file (.Report.tex.swp) instead of a regular (non-hidden) .tex file? (Nothing to do with your error, just curious. It seems a dangerous naming scheme, if intentional. The only swap files that I know of are binary temporary lock files, such as those created by vim.) Mar 15 '15 at 20:01
• @egreg Ah, I didn't realise that you couldn't use spaces. I'm far too used to whitespace languages. If you say this as an answer I'll accept it. Mar 15 '15 at 20:28

Rarely use spaces in file names, and be extra careful when including images that have spaces in their names. So, your use of

\includegraphics[..]{ test }


is interpreted as looking for file  test .ext - note the space before and after (where .ext is one of the approved graphic file extensions associated with your driver). Similarly,

\includegraphics[..]{ test.png }


can't find a file extension .png  - note the space at the end. So, use

\includegraphics[..]{filename}


where the driver will look for the appropriate file name filename (no spaces).

A work-around for when you actually do have spaces in your file names, are provided by the grffile package.

Somewhat unrelated, but the following will also be problematic:

\documentclass{<class><space>}


as in \documentclass{article }. However, it's fine to use

\usepackage{ <package> , <package> , ... }