It is a multi-strip image and my code handles multi-strip images of Group 4 compression fine. In fact, that link you sent was a response to an older question I had (to get the multi-strip Group 4 compression working). I was able to figure everything out from what you provided last time. I now have a method that works with most of the TIFF image types I have to deal with, except the Group 3 compression. I run it through the debugger and it seems to be working fine (building the images from the strips), but the PDF is virtually empty that it creates. My method that deals with the TIFFS is below. Any thoughts where the problem is would be appreciated.
public void addPage(String imagePath) throws IOException { File inputFile = new File(imagePath); try { SeekableStream s = new FileSeekableStream(inputFile); TIFFDirectory dir = new TIFFDirectory(s, 0); long IFDOffset = dir.getIFDOffset(); while (IFDOffset != 0L) { dir = new TIFFDirectory(s, IFDOffset, 0); IFDOffset = dir.getNextIFDOffset(); long type = -1; if (dir.isTagPresent(TIFFImageDecoder.TIFF_RESOLUTION_UNIT)) { type = dir.getFieldAsLong(TIFFImageDecoder.TIFF_RESOLUTION_UNIT); if (type != 2) { System.err.println("Wrong format! Size not in inches."); } } float xres = dir.getFieldAsFloat(TIFFImageDecoder.TIFF_X_RESOLUTION); float yres = dir.getFieldAsFloat(TIFFImageDecoder.TIFF_Y_RESOLUTION); long h = dir.getFieldAsLong(TIFFImageDecoder.TIFF_IMAGE_LENGTH); long w = dir.getFieldAsLong(TIFFImageDecoder.TIFF_IMAGE_WIDTH); height = (int) h; width = (int) w; float scaledHeight = h / (yres / 72f); float scaledWidth = w / (xres / 72f); document.setPageSize(new Rectangle(scaledWidth, scaledHeight)); long rowsStrip = dir.getFieldAsLong(TIFFImageDecoder.TIFF_ROWS_PER_STRIP); TIFFField field = dir.getField(TIFFImageDecoder.TIFF_STRIP_OFFSETS); long offset[]; if (field.getType() == TIFFField.TIFF_LONG) { offset = field.getAsLongs(); } else { // must be short short temp[] = field.getAsShorts(); offset = new long[temp.length]; for (int k = 0; k < temp.length; ++k) { offset[k] = temp[k]; } } field = dir.getField(TIFFImageDecoder.TIFF_STRIP_BYTE_COUNTS); long size[]; if (field.getType() == TIFFField.TIFF_LONG) { size = field.getAsLongs(); } else { // must be short short temp[] = field.getAsShorts(); size = new long[temp.length]; for (int k = 0; k < temp.length; ++k) { size[k] = temp[k]; } } boolean reverse = false; if (dir.isTagPresent(TIFFImageDecoder.TIFF_FILL_ORDER)) { reverse = (dir.getFieldAsLong(TIFFImageDecoder.TIFF_FILL_ORDER) == 2L); } int compression = (int) dir.getFieldAsLong(TIFFImageDecoder.TIFF_COMPRESSION); switch (compression) { case TIFFImage.COMP_NONE: throw new IOException("Images without compression are not supported by iCris."); case TIFFImage.COMP_FAX_G3_1D: compression = Image.CCITTG3_1D; break; case TIFFImage.COMP_FAX_G3_2D: compression = Image.CCITTG3_1D; if (dir.isTagPresent(TIFFImageDecoder.TIFF_T4_OPTIONS)) { if (((int) dir.getFieldAsLong(TIFFImageDecoder.TIFF_T4_OPTIONS) & 1) != 0) { compression = Image.CCITTG3_2D; } } break; case TIFFImage.COMP_FAX_G4_2D: compression = Image.CCITTG4; break; default: throw new IOException("Compression type " + compression + " not supported"); } // Check if we need to create a new page if (constructedSecond) { document.newPage(); } else { constructedSecond = true; if (useImageMask) { singleMask = Image.getInstance(Toolkit.getDefaultToolkit().createImage(imageMaskPath) , null); } } long rowsLeft = h; float totatHeight = 0; float scaleX = 72f / xres * 100; float scaleY = 72f / yres * 100; document.open(); PdfContentByte cb = writer.getDirectContent(); for (int k = 0; k < offset.length; ++k) { byte im[] = new byte[(int) size[k]]; s.seek(offset[k]); s.readFully(im); Image img = Image.getInstance((int) w, (int) Math.min(rowsStrip, rowsLeft), reverse, compression, 0, im); rowsLeft -= rowsStrip; img.scalePercent(scaleX, scaleY); totatHeight += (float) scaleY / 100 * img.height(); img.setAbsolutePosition(0, scaledHeight - totatHeight); cb.addImage(img); } } } catch (DocumentException e) { e.printStackTrace(); } catch (IOException ex) { try { document.open(); document.close(); } finally { new File(pdfPath).delete(); } throw ex; } } -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Paulo Soares Sent: Friday, March 14, 2003 11:55 AM To: 'Aaron Kelley'; [EMAIL PROTECTED] Subject: RE: [iText-questions] Group 3 TIFF compression It's probably a multi-strip image. See http://www.mail-archive.com/[EMAIL PROTECTED]/msg041 82 Best Regards, Paulo Soares > -----Original Message----- > From: Aaron Kelley [SMTP:[EMAIL PROTECTED] > Sent: Friday, March 14, 2003 18:43 > To: [EMAIL PROTECTED] > Subject: [iText-questions] Group 3 TIFF compression > > I have a tiff with Group 3 compression and I am having trouble putting the > image into a PDF with iText. I have a piece of code to detect the > compression (similar to Chap0612.java) and it is coming up as compression > = Image.CCITTG3_1D; > > The PDF is being generated basically blank (very small file size compared > to the image). I have this code working with all kinds of different TIFF > formats, but I cannot seem to get it to work for Group 3. Also, the > examples (Chap0611 and Chap0612) fail to create a PDF from this image. > Any ideas? > > Aaron Kelley | Software Developer > Tyler Technologies | Eagle Division > > Phone: 303.249.1821 > Email: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > ------------------------------------------------------- This SF.net email is sponsored by:Crypto Challenge is now open! Get cracking and register here for some mind boggling fun and the chance of winning an Apple iPod: http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en _______________________________________________ iText-questions mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/itext-questions ------------------------------------------------------- This SF.net email is sponsored by:Crypto Challenge is now open! Get cracking and register here for some mind boggling fun and the chance of winning an Apple iPod: http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en _______________________________________________ iText-questions mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/itext-questions