Hi,

  

I have some problems with a tiff-compression. What I use is tiff2pdf converter. 
For most 
tiff’s (b&w FaxG4) everything’s working just fine. BUT with all colored tiff’s, 
I get 
IllegalArgumentException or RuntimeException (see bottom please). I can open 
that tiff 
with IrfanView, so the file (buffer) is not corrupted.

  

What am I doing wrong? Thanx in advance

  

Vedran

Germany

  

p.s.: IrfanView says (“Compression: Old JPEG (in TIFF)”?!?

  

  

  

public byte[] tiff2pdf(byte[] tifBuffer)

   {

     byte[] pdfBuffer = null;



     try

     {

       Image img2 = Image.getInstance(tifBuffer);    //cause 
IllegalArgumentException

  

       // creation of the document with a certain size and certain margins

       Document document = new Document(new 
Rectangle(img2.width(),img2.height()), 0, 0, 
0, 0);



       // creation of the different writers

       ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();

       PdfWriter writer = PdfWriter.getInstance(document, byteArrayOut);

       SeekableStream s = new ByteArraySeekableStream(tifBuffer);

  

       TIFFDecodeParam param = null;

  

       ImageDecoder dec = ImageCodec.createImageDecoder("tiff", s, param); // 
cause 
RuntimeException

       logger.info("Number of images in this TIFF: " + dec.getNumPages());

  

       // Which of the multiple images in the TIFF file do we want to load

       // 0 refers to the first, 1 to the second and so on.

       int total = dec.getNumPages();

       document.open();

       PdfContentByte cb = writer.getDirectContent();

       for (int k = 0; k < total; ++k)

       {

         RenderedImage ri = dec.decodeAsRenderedImage(k);

         Raster ra = ri.getData();

         BufferedImage bi = new BufferedImage(ri.getColorModel(),

             Raster.createWritableRaster(ri.getSampleModel(),

                 ra.getDataBuffer(), null), false, new Hashtable());

         Image img = Image.getInstance(bi, null, true);

         img.setAbsolutePosition(0, 0);

         cb.addImage(img);

         document.newPage();

       }

       document.close();

       pdfBuffer = byteArrayOut.toByteArray();

     }

     catch (Exception de)

     {

       de.printStackTrace();

     }

     return pdfBuffer;

   }

  

java.lang.IllegalArgumentException: The compression 6 is not supported.

         at com.lowagie.text.pdf.codec.TiffImage.getTiffImageColor(Unknown 
Source)

         at com.lowagie.text.pdf.codec.TiffImage.getTiffImage(Unknown Source)

         at com.lowagie.text.pdf.codec.TiffImage.getTiffImage(Unknown Source)

         at com.lowagie.text.Image.getInstance(Unknown Source)

  

java.lang.RuntimeException: Planar (band-sequential) format TIFF is not 
supported.

         at com.sun.media.jai.codecimpl.TIFFImage.<init>(TIFFImage.java:340)

         at 
com.sun.media.jai.codecimpl.TIFFImageDecoder.decodeAsRenderedImage(TIFFImageDecoder.java:112)

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to