TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a tex file with \includegraphic elements for some PNG images. I use MikTeX on Windows and the PDF is fine.

Now, I need a DVI so I tried using: \pdfoutput=0 This creates a DVI, but only after I remove all the PNG images… Otherwise I get errors like:

! LaTeX Error: Cannot determine size of graphic in math-box-plot.png (no BoundingBox).
share|improve this question
You should also consider compiling to PDF rather than DVI. – Juan A. Navarro Feb 16 '11 at 10:06
I converted the PNG files to EPS and used those in includegraphics and it works. – Hagai Cibulski Feb 18 '11 at 9:17

TeX is text based, it cannot determine the size of PNG image itself by default.

A quick solution:


And use


It is better to use extractbb (also named ebb, xbb) program to produce .bb or .xbb file for LaTeX. Use this command in 'Command Prompt':

for %i in (*.png) do xbb %i

(or for %i in (*.png) do extractbb -x %i, I'm not sure about MiKTeX.)

And use


(I use TeX Live, only dvipdfmx supports png images. But MiKTeX seems different, I can't remember well.)

share|improve this answer
Leo, you better use <code> ... </code> blocks for the command line and similar text to avoid the TeX syntax highlighter. – Martin Scharrer Feb 16 '11 at 8:41
@Martin: I did not realise that the two were handled differently – Joseph Wright Feb 16 '11 at 9:28
@Joseph: The syntax highlighting is done in <pre class="prettyprint lang-tex"> tags around <code>. Therefore single <code> tags on their own are not highlighted. – Martin Scharrer Feb 16 '11 at 9:36

Install the program ImageMagick, then you can do it on the fly:


\DeclareGraphicsRule{.png}{eps}{.bb}{`convert #1 eps:-}
\DeclareGraphicsRule{.gif}{eps}{.bb}{`convert #1 eps:-}


  \IncludeGraphics{lion}\qquad % a png image
  \IncludeGraphics{knuth-tex}  % a gif image

btw: you do not need the \pdfoutput=0 simply run latex instead of pdflatex

share|improve this answer
It may be too tricky for new TeXers, with no actual advantage. BTW, ImageMagick may be overkill, bmeps is enough. – Leo Liu Feb 16 '11 at 11:34
no, it isn't, and ImagaMagick can be used for any other conversion, hence it is no overkill. – Herbert Feb 16 '11 at 12:07

I always make portable latex source equally suitable for compiling both with latex and pdflatex. My remedy is rather simple.

Put \usepackage{graphicx} into preample (without any driver specified).

Import eps or pdf graphics with \includegrpahics{filename}; latex compiler then loads filename.eps whereas pdflatex takes filename.pdf. MikTeX automatically converts eps into pdf on fly if the epstopdf packege is loaded.

Import png graphics with \includegrpahics[nathwith=<XX>bp, natheight=<YY>bp, width=<width>]{filename.png} with .png extension explicitely shown; in that case you dont need to invent \DeclareGraphicsRule. Natural height and width of bitmap graphics can be determined from file properties in Windows Explorer or any graphics editor, e.g. Windows Paint.

share|improve this answer
Does this work with plain DVI-producing latex, not just pdflatex? – einpoklum Jul 6 '14 at 15:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.