Problem with Inserting a LZW compression TIFF image into the word document

Dear all,

I have the following code to insert a TIFF image ( with compression LZW ) into a word document. However , there is null pointer exception throwing out. Does anyone has any solution to handle it ?

The code:

import com.aspose.words.*;
import com.sun.media.jai.codec.ImageCodec;
import com.sun.media.jai.codec.ImageDecoder;
import javax.media.jai.JAI;
import javax.media.jai.NullOpImage;
import javax.media.jai.OpImage;
import javax.media.jai.PlanarImage;
import java.awt.image.BufferedImage;

public class HelloWorld {

    public static void main(String[] args) {

        System.out.println("Hello World");

        // step 1: creation of a document-object
        try {
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
            String file = "C:\test.tif";

            com.sun.media.jai.codec.FileSeekableStream ss = new com.sun.media.jai.codec.FileSeekableStream(file);
            ImageDecoder decoder = ImageCodec.createImageDecoder("tiff", ss, null);
            int numPages = decoder.getNumPages();
            BufferedImage image[]= new BufferedImage[numPages];
            for(int i=0;i<decoder.getNumPages();i++){

                PlanarImage op = new NullOpImage(decoder.decodeAsRenderedImage(i),
                        null,
                        OpImage.OP_IO_BOUND,
                        null);

                builder.insertImage(op.getAsBufferedImage(),
                        RelativeHorizontalPosition.MARGIN,
                        0,
                        RelativeVerticalPosition.MARGIN,
                        0,
                        450,
                        600,
                        WrapType.SQUARE);

            }

            doc.save("C:\out.doc");

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

The error:

java.lang.NullPointerException
at com.sun.media.jai.codecimpl.TIFFLZWDecoder.decode(TIFFLZWDecoder.java:105)
at com.sun.media.jai.codecimpl.TIFFImage.getTile(TIFFImage.java:1065)
at javax.media.jai.RenderedImageAdapter.getTile(RenderedImageAdapter.java:148)
at javax.media.jai.NullOpImage.computeTile(NullOpImage.java:162)
at com.sun.media.jai.util.SunTileScheduler.scheduleTile(SunTileScheduler.java:904)
at javax.media.jai.OpImage.getTile(OpImage.java:1129)
at javax.media.jai.PlanarImage.copyData(PlanarImage.java:2343)
at javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2525)
at javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2546)
at HelloWorld.main(HelloWorld.java:95)

Hi
Thanks for your request. The error occurs in jai, not in Aspose.Words. Most likely jai can’t decode your tiff. Which version of JAI are you using? Maybe you should try using the latest version.
https://docs.aspose.com/words/java/system-requirements/#optional-dependencies
Also you can attach your TIF here and I will test it on my side.
Best regards.

Hi

I have already used the latest stable version of jai ( 1.1.3 ). And I have read the document of jai that it should support the LZW compression . Thus , is it something related to the parameters that I should set but haven’t done so?

Thanks if you could help me.

Here is the attached file for your reference. ( Please notice that the file is confidential and therefore please don’t distribute it to others, many thanks ! )

Hi
Thank you for additional information. Unfortunately I am not able help you to solve this problem. You should report this JAI problem.
Best rtegards.

Not at all. Indeed you have help me a lot. Thank you alexey.noskov , you are really helpful and responsible.

Vincent