title: Java image scaling
body: <p>I am outputting images to a PDF file using iText.  The images always appear larger than they are supposed to.  According to the book (iText in Action), this is because iText always displays the images at a resolution of 72 dpi, regardless of what the actual dpi property of the image is.  The book suggests using image.getDpiX() to find the dpi of the image, and then using image.scalePercent(72 / actualDpi * 100) to display the image properly.  So far, the getDpiX() property of all my images have returned 0 (I've tried 2 gifs and 1 jpg).  Is there another way to figure out the actual DPI so that my images scale properly?  </p>
  
  <pre><code>com.lowagie.text.Image graphic = com.lowagie.text.Image.getInstance(imgPath);
  float actualDpi = graphic.getDpiX();
  if (actualDpi &gt; 0)
    //Never gets here
    graphic.scalePercent(72f / actualDpi * 100);
  </code></pre>