Inserting images other than JPEGs

Help
2012-11-29
2013-03-28
  • Rudy Gireyev
    Rudy Gireyev
    2012-11-29

    I seem to be unable to insert any images other than JPEGs into my PDF. Is this a known limitation or am I doing something wrong? Here's the code I use that does work for JPEGs:

                   byte[] imageBytes = getImage();
                   Image image = Image.get(new Buffer(imageBytes));
                   builder.showXObject(image.toXObject(myDocument), 
                                       new Point2D.Double(xCoord, yCoord),
                                       new Dimension(image.getWidth(), image.getHeight()));
    

    But when I use GIFs or PNGs the image object is null after the Image.get() statement :(
    Any workarounds for this?
    Thanks
    Rudy

     
  • Hi Rudy,
    there's no magic about non-JPEG images: no implemented codec == no support. PNG is a pending activity I haven't scheduled yet. GIF is not considered.
    As a simple workaround you can obviously convert your images to JPEG before submitting to the library.
    Stefano

     
  • Rudy Gireyev
    Rudy Gireyev
    2012-12-03

    Thank you Stefano.

    So does that mean only JPEG images are supported at the time?

    The conversion to JPEG would have to happen on the fly, and without the user involvement. :(
    Not sure how I'm going to mechanize that.

    Rudy

     
    • James Kelly Jr
      James Kelly Jr
      2013-03-28

      Hi Rudy!

      You could try using the DevIL library to do the conversion for you: http://openil.sourceforge.net/

      I'm not sure if you're using the C# or the Java library but if you're using C# you could P/Invoke that library and the plus side is that it handles practically every image format you can imagine from the obscure to the very common.

       
  • No, the contingent absence of a codec due to pending development activities doesn't make any sense in considering (temporary) support to format conversion: at this stage, it's upon the user to fill the gap either pipelining an external converter or contributing code/money to speed up the project's evolution.