I figured out the issue. The exception was expected as  CCITTFactory
supported only specific encoding.
I instead used the LosslessFactory . I had use com.sun.media.jai.codec.
ImageCodec since ImageIO returned null as jdk doesn't recogonize the tiff
format (both for reading and writing)


SeekableStream stream = new ByteArraySeekableStream(pngByteArray);
String[] names = ImageCodec.getDecoderNames(stream);
ImageDecoder decoder = ImageCodec.createImageDecoder(names[0], stream,
null);
RenderedImage im =  decoder.decodeAsRenderedImage();
BufferedImage img = PlanarImage.wrapRenderedImage(im).getAsBufferedImage();



PDImageXObject ximage3 = LosslessFactory.createFromImage(doc, img);

Thanks,
Vikram

On Thu, Apr 19, 2018 at 7:01 PM, VikramSrinivasan Venkatakrishnan <
[email protected]> wrote:

> Hello,
>
> I am trying to convert tiff files to PDF and I get the below exception.I
> get the same exception with all the tif files I have tried.
> Kindly assist.
>
>
> byte[] pngByteArray = FileUtils.readFileToByteArray(new
> File("C:\\CCITT_1.TIF"));
> InputStream contentStream = new ByteArrayInputStream(pngByteArray);
> PDDocument doc = new PDDocument();
>
>         PDImageXObject ximage3 = CCITTFactory.createFromByteArray(doc,
> pngByteArray);
>
>
> Exception in thread "main" java.io.IOException: FillOrder 2 is not
> supported
> at org.apache.pdfbox.pdmodel.graphics.image.CCITTFactory.
> extractFromTiff(CCITTFactory.java:408)
> at org.apache.pdfbox.pdmodel.graphics.image.CCITTFactory.
> createFromRandomAccessImpl(CCITTFactory.java:261)
> at org.apache.pdfbox.pdmodel.graphics.image.CCITTFactory.
> createFromByteArray(CCITTFactory.java:133)
> at org.apache.pdfbox.pdmodel.graphics.image.CCITTFactory.
> createFromByteArray(CCITTFactory.java:109)
>
> Thanks,
> Vikram
>

Reply via email to