How can I convert a GIF to XOD/PDF using Java on Linux?

Q:

I want to load a GIF and convert it to XOD/PDF with the Convert interface, on linux. Also, I don’t want to touch the file system, and I want everything done in a “streaming” way to keep any one image from spiking memory usage. Also, I don’t want to use anything with complex licensing (like third party libraries). But I’ve found that the Linux PDFNet doesn’t support loading up a GIF. Can you help?

A:

You would simply need to first convert the GIF to PNG using the ImageIO library built into Java. The following shows how to do so using file paths:

Since you will likely want to stream files instead of saving to disk, you can use the equivalent function for streams:

http://docs.oracle.com/javase/6/docs/api/javax/imageio/ImageIO.html#write(java.awt.image.RenderedImage, java.lang.String, java.io.OutputStream)

Note that you would need to convert your input stream to a RenderedImage, which you can do by converting it to a BufferedImage (an implementation of RenderedImage):