Problem solved. Use this code:

    public static void convert2(File inputFile, File outputFile) {
        // creation of the document with a certain size and certain margins
        Document document = new Document(PageSize.LETTER, 0, 0, 0, 0);
        Document.compress = false;
        try {
            // creation of the different writers
            PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream(outputFile));

            SeekableStream s = new FileSeekableStream(inputFile);
            TIFFDirectory dir = new TIFFDirectory(s, 0);
            long IFDOffset = dir.getIFDOffset();
            document.open();

            PdfContentByte cb = writer.getDirectContent();
            while (IFDOffset != 0L) {
                System.err.println("entering loop");

                dir = new TIFFDirectory(s, IFDOffset, 0);
                IFDOffset = dir.getNextIFDOffset();
                long h =
dir.getFieldAsLong(TIFFImageDecoder.TIFF_IMAGE_LENGTH);
                long w =
dir.getFieldAsLong(TIFFImageDecoder.TIFF_IMAGE_WIDTH);
                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 params = 0;
                if
(dir.isTagPresent(TIFFImageDecoder.TIFF_PHOTOMETRIC_INTERPRETATION)) {
                    long photo =
dir.getFieldAsLong(TIFFImageDecoder.TIFF_PHOTOMETRIC_INTERPRETATION);
                    if (photo == 1)
                        params |= Image.CCITT_BLACKIS1;
                }
                int compression = (int)
dir.getFieldAsLong(TIFFImageDecoder.TIFF_COMPRESSION);
                switch (compression) {
                    case 32771:
                    case TIFFImage.COMP_FAX_G3_1D:
                        System.err.println("TIFFImage.COMP_FAX_G3_1D");
                        compression = Image.CCITTG3_1D;
                        params |= Image.CCITT_ENCODEDBYTEALIGN |
Image.CCITT_ENDOFBLOCK;
                        break;
                    case TIFFImage.COMP_FAX_G3_2D:
                        System.err.println("TIFFImage.COMP_FAX_G3_2D");
                        compression = Image.CCITTG3_1D;
                        if
(dir.isTagPresent(TIFFImageDecoder.TIFF_T4_OPTIONS)) {
                            int g3options = (int)
dir.getFieldAsLong(TIFFImageDecoder.TIFF_T4_OPTIONS);
                            if ((g3options & 1) != 0)
                                compression = Image.CCITTG3_2D;
                            if ((g3options & 4) != 0)
                                params |= Image.CCITT_ENCODEDBYTEALIGN;
                        }
                        break;
                    case TIFFImage.COMP_FAX_G4_2D:
                        System.err.println("TIFFImage.COMP_FAX_G4_2D");
                        compression = Image.CCITTG4;
                        break;
                    default:
                        throw new Exception("Compression type " +
compression + " not supported");
                }
                long rowsLeft = h;
                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, params, im);
                    rowsLeft -= rowsStrip;
                    img.scalePercent(72f / 600f * 100);
                    //img.setAbsolutePosition(0, 0);
                    //cb.addImage(img);
                    document.add(img);
                }
                boolean result = document.newPage();
                System.err.println("result of document.newPage = "+result);

                System.err.println("exiting loop");
            }
            document.close();
        }
        catch (Exception de) {
            de.printStackTrace();
            //System.err.println(de.getMessage());
        }
    }

Best Regards,
Paulo Soares


----- Original Message -----
From: "Aaron Kelley" <[EMAIL PROTECTED]>
To: "'Paulo Soares'" <[EMAIL PROTECTED]>
Sent: Saturday, March 22, 2003 19:37
Subject: RE: [iText-questions] Group 3 TIFF compression


> Can you give me more details (you don't have to go too much into
> detail)?  I just would like to have some idea what the problem is.
>
> Thanks.
>
> -----Original Message-----
> From: Paulo Soares [mailto:[EMAIL PROTECTED]
> Sent: Friday, March 21, 2003 6:50 PM
> To: Aaron Kelley
> Subject: Re: [iText-questions] Group 3 TIFF compression
>
> You are out of luck for this compression, Acrobat also can't read it
> directly from file.
>
> Best Regards,
> Paulo Soares
>
> ----- Original Message -----
> From: "Aaron Kelley" <[EMAIL PROTECTED]>
> To: "'Paulo Soares'" <[EMAIL PROTECTED]>
> Sent: Saturday, March 22, 2003 0:34
> Subject: RE: [iText-questions] Group 3 TIFF compression
>
>
> > Here is one example.
> >
> > Thanks for looking at it.
> >
> > Aaron
> >
> > -----Original Message-----
> > From: Paulo Soares [mailto:[EMAIL PROTECTED]
> > Sent: Friday, March 21, 2003 5:24 PM
> > To: Aaron Kelley; [EMAIL PROTECTED]
> > Subject: Re: [iText-questions] Group 3 TIFF compression
> >
> > Please send me privately the tiff.
> >
> > Best Regards,
> > Paulo Soares
> >
> > ----- Original Message -----
> > From: "Aaron Kelley" <[EMAIL PROTECTED]>
> > To: "'Paulo Soares'" <[EMAIL PROTECTED]>;
> > <[EMAIL PROTECTED]>
> > Sent: Friday, March 21, 2003 20:33
> > Subject: RE: [iText-questions] Group 3 TIFF compression
> >
> >
> > > 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

Reply via email to