Tiffs are supported directly, see TiffImage. > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On > Behalf Of Ch, Phaniraj (GE Consumer & Industrial, consultant) > Sent: Thursday, March 03, 2005 3:18 PM > To: [email protected] > Subject: [iText-questions] (no subject) > > Hi, > I have a problem. > I am converting a TIF_G4 format file to pdf but the > convetrted pdf displaying the blank pages. > Can u help me in this? > > Here is the code... > > private void readTiffs(Object[] fileNames, String > imageFileName, String mergeLocation) throws IOException > { > java.io.File file = null; > SeekableStream ss = null; > ImageDecoder decoder = null; > Vector tiles = new Vector(); > BufferedImage firstImage = null; > boolean assignFirstImage = true; > Raster rstr = null; > DataBuffer dataBuffer = null; > try { > // creation of the different writers > Document document = new Document(PageSize.A4, > 50, 50, 50, 50); > > PdfWriter writer = > PdfWriter.getInstance(document, new > FileOutputStream(imageFileName+".pdf")); > > writer.setFullCompression(); > document.open(); > PdfContentByte cb = > writer.getDirectContent(); > for (int j = 0; j < fileNames.length; j++) > { > file = new java.io.File(strStorePath + > java.io.File.separator + fileNames[j].toString()); > if(!file.exists()){ > errorLog.write(" while merging == " > + file +"not found"); > System.out.println("while merging == > " + file +"not found"); > continue; > } > File ch = new > File(imageFileName+fileNames[j].toString()+".tif"); > file.renameTo(ch); > // PlanarImage img2 = > JAI.create("fileload", strStorePath + java.io.File.separator > + fileNames[j].toString()); > PlanarImage img2 = > JAI.create("fileload", imageFileName+fileNames[j].toString()+".tif"); > //Image img = > (Image)JAI.create("fileload", strStorePath + > java.io.File.separator + fileNames[j].toString()); > //start pdf > // creation of the document with a > certain size and certain margins > > //Document.compress = false; > > > > //File file = new File("D:/test.txt"); > //SeekableStream s = new > FileSeekableStream(file); > > //TIFFDecodeParam param = null; > //param = new TIFFDecodeParam(); > // ImageDecoder dec = > ImageCodec.createImageDecoder("tiff", s, param); > > //System.out.println("dec: " + dec); > // 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(); > > //for (int k = 0; k < total; ++k) { > //RenderedImage ri = > dec.decodeAsRenderedImage(k); > // System.out.println("ri: " + ri); > Raster ra = img2.getData(); > BufferedImage bi = new > BufferedImage(img2.getColorModel(), > > Raster.createWritableRaster(img2.getSampleModel(), > ra.getDataBuffer(), null), false, new Hashtable()); > // System.out.println("bi: " + bi); > > Image img = > Image.getInstance(bi, null, true); > System.out.println("img: " + img); > //img.scalePercent(72f / 200f * 100); > //img.setAbsolutePosition(0, 0); > img.scalePercent(36F); > img.setAbsolutePosition(0.0F, 0.0F); > //System.out.println("Image: " + k); > cb.addImage(img); > System.out.println("cb: " + cb); > System.out.println("document: " > + document); > document.newPage(); > System.out.println("document: " > + document); > > > //} > > > > //end of pdf > > > /*ss = new FileSeekableStream(file); > decoder = > ImageCodec.createImageDecoder("tiff", ss, null); > int numPages = decoder.getNumPages(); > for (int i = 0; i < numPages; i++) > { > rstr = decoder.decodeAsRaster(i); > dataBuffer = rstr.getDataBuffer(); > PlanarImage rfmtImage = > reformatImage(img, new Dimension(rstr.getWidth(), rstr.getHeight())); > SampleModel sampleModel = > rfmtImage.getSampleModel(); > ColorModel colorModel = > rfmtImage.getColorModel(); > WritableRaster wr = > Raster.createWritableRaster(sampleModel, dataBuffer, new Point(0, 0)); > BufferedImage bi = new > BufferedImage(colorModel, wr, > colorModel.isAlphaPremultiplied(), null); > if (assignFirstImage) > { > firstImage = bi; > assignFirstImage = false; > } > else > tiles.addElement(bi); > }*/ > > } > document.close(); > } > catch (Exception de) { > de.printStackTrace(); > //System.err.println(de.getMessage()); > } > try > { > //String tiffFile = > saveAsMultipageTIFF(tiles, firstImage, imageFileName); > > } > catch (Exception e) > { > errorLog.write(" while merging == " + e); > e.printStackTrace(); > } > > } > thanks & regards > Phani > > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from > real users. > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_ide95&alloc_id396&op=ick > _______________________________________________ > iText-questions mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/itext-questions >
------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_ide95&alloc_id396&op=click _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions
