views:

490

answers:

3

When programmatically creating a PDF document using iText, I'm able to insert a JPG image into the document's header on my local environment (Windows XP). However, when executing the same code on our test environment (Linux based), iText throws an exception claiming the image file "is not a recognized imageformat", in com.lowagie.text.Image.getInstance(...). I have verified the following:

  • The image files on the local and test environment are identical JPG files
  • The iText JAR file on both environments is the same (version 1.4.3)
  • The JPG really does show up in the created PDF on my local/Windows environment
  • The JVM in both environments is 1.5.0_09

Can anybody think of anything else I should try and/or verify? Is there some weird difference between the ways the JPG is loaded between Windows and Linux environments?

Thanks

EDIT: Updated to reflect that the JVM is the same in both environments.

A: 

You fail to mention the make, model, and year of your Java runtime. That's the key to this mystery, Watson.

Jonathan Feinberg
+1  A: 

I recently had an almost identical problem, in my case a PNG image i used could not the used on Java version 1.5 but worked perfectly on 1.6. If you have different JVMs on your machines that might be the issue.

I suggest picking a different image altogether or change the file format and see it works.

n002213f
Good point, but alas they're the same JVM =( I updated the question accordingly. I might play around with different image formats and update back if it works.
Ross
+1  A: 

Turns out that iText was accessing images by URL. The URL was invalid in certain situations. In my environment, I ran localhost so I never had issues. Our testing department ran a more production-like setup, meaning it was tested by connecting to a non-localhost web server.

I think what was happening was that iText was trying to get the image file and getting an error page instead (we have a custom error page shown rather than just returning a generic 404). So, I think it was telling me that I was using an unsupported format because, well, (error) web-pages are not a supported image format.

The lesson learned here is that when iText gives you the "is not a recognized imageformat" exception, it might not be describing the issue that you think it is!

Ross