1 Reply Latest reply on Aug 3, 2010 2:00 PM by 843802

    How is bitsPerRate set for PDF to TIFF conversion?

      I need to convert a PDF to a group 4 TIFF. I found certain objects I need to set to accomplish this (code is below). I am getting the exception below when performing the "write sequence" methon on the TIFF writer. I am wondering if anyone can offer any insight on how the bits per sample property is set and how can i change it?<br>:<br>



      javax.imageio.IIOException: Bits per sample must be 1 for T4 compression!<br>

      at com.sun.media.imageioimpl.plugins.tiff.TIFFT4Compressor.encode(TIFFT4Compressor.java:219)<br>

      at com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter.writeTile(TIFFImageWriter.java:1256).<br>

      at com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter.write(TIFFImageWriter.java:1555)<br>

      at com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter.writeInsert(TIFFImageWriter.java:1683)<br>

      at com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter.writeToSequence(TIFFImageWriter.java:1598)<br>


      public static byte[] PDFToImage(byte[] bai, String imageType) <br>
      byte[] out = null; <br>
      try <br>
           PdfDecoder decoder = new PdfDecoder();<br>

           if(decoder.isFileViewable()) <br>
                ByteArrayOutputStream baos = new ByteArrayOutputStream();<br>
                ImageOutputStream ios = ImageIO.createImageOutputStream(baos);<br>

                boolean foundWriter = false;<br>                    
                Iterator writerIter = ImageIO.getImageWritersByMIMEType("image/" + imageType);<br>
                while (writerIter.hasNext() && !foundWriter) <br>
                     foundWriter = true;<br>
                     TIFFImageWriter writer = (TIFFImageWriter)writerIter.next();<br>
                     TIFFImageWriteParam param = new TIFFImageWriteParam(new Locale("en"));<br>
                     param.setCompressionType("CCITT T.4");<br>

                     for (int i = 0; i < decoder.getPageCount(); i++) <br>
                          int pageNumber = i + 1;<br>
                          BufferedImage image = decoder.getPageAsImage(pageNumber);<br>
                          IIOImage iioImage = new IIOImage(image, null, null);<br>

                               writer.writeToSequence(iioImage, param);<br>

                          }catch(Exception e){<br>
                               throw e;<br>

                     out = baos.toByteArray();<br>
                if (!foundWriter) <br>
                     throw new RuntimeException("Error: no writer found for image type '"
                                         + imageType
                                         + "'");<br>
      } <br>
      catch (Exception e) <br>
      return out;<br>

      Message was edited by: