The last version of iText supports TIFF directly. See the example
read_tiffs.java at itextpdf.sf.net. You can also use
Image.getInstance("file.tif") to just read the first image.

Best Regards,
Paulo Soares

> -----Original Message-----
> From: HASSANI Maher SG/DIT [SMTP:[EMAIL PROTECTED]
> Sent: Wednesday, November 05, 2003 14:01
> To:   [EMAIL PROTECTED]
> Subject:      [iText-questions] Problem while converting a tiff to  pdf
> 
> Hello,
> i'm using this program to convert a tiff file to a pdf on the fly, but it
> doesn't work, can you help please : 
>  
>  
> protected ByteArrayOutputStream tiff2Pdf(
>   final HttpServletRequest req, File file,
>   final ServletContext ctx)
>   throws DocumentException{
>    
>  
>   ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
>   
>      
>   // creation of the document with a certain size and certain margins
>   Document document = new Document(PageSize.A4, 50, 50, 50, 50);
>   //Document.compress = false;
>   try {
>    // creation of the different writers
>    PdfWriter writer = PdfWriter.getInstance(document, baosPDF);
>    
>    SeekableStream s = new FileSeekableStream(file);
>    
>    TIFFDecodeParam param = null;
>    
>    ImageDecoder dec = ImageCodec.createImageDecoder("tiff", s, param);
>    
>    System.out.println("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.scalePercent(72f / 200f * 100);
>     img.setAbsolutePosition(0, 0);
>     System.out.println("Image: " + k);
>     cb.addImage(img);
>     document.newPage();
>    }
>    document.close();
>   }
>   catch (Exception de) {
>    de.printStackTrace();
>    //System.err.println(de.getMessage());
>   }
>  
>   return baosPDF;
>  }


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?   SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to