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

3 Answers 3


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

  • 1
    Leo, you better use <code> ... </code> blocks for the command line and similar text to avoid the TeX syntax highlighter. Feb 16, 2011 at 8:41
  • @Martin: I did not realise that the two were handled differently
    – Joseph Wright
    Feb 16, 2011 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. Feb 16, 2011 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

  • It may be too tricky for new TeXers, with no actual advantage. BTW, ImageMagick may be overkill, bmeps is enough.
    – Leo Liu
    Feb 16, 2011 at 11:34
  • 1
    no, it isn't, and ImagaMagick can be used for any other conversion, hence it is no overkill.
    – user2478
    Feb 16, 2011 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 \includegraphics{filename}; latex compiler then loads filename.eps whereas pdflatex takes filename.pdf. MikTeX automatically converts eps into pdf on fly if the epstopdf package is loaded.

Import png graphics with \includegraphics[nathwith=<XX>bp, natheight=<YY>bp, width=<width>]{filename.png} with .png extension explicitly 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.

  • Does this work with plain DVI-producing latex, not just pdflatex?
    – einpoklum
    Jul 6, 2014 at 15:52
  • @Igor Kotelnikov: I can't do "two-character swaped edits"; maybe fix nathwith
    – U. Windl
    Mar 4, 2019 at 2:37
  • @U.Windl if possible neither natwidth nor natheight are recommended You should try to use the natural PNG dpi default of 96dpi in both directions then simply control image import placement with width OR if necessary height
    – user170109
    Mar 4, 2019 at 3:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .