pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tilman Hausherr <THaush...@t-online.de>
Subject Re: ImageIOUtil.writeImage and multipage TIFF
Date Thu, 06 Nov 2014 19:11:45 GMT
Here's the code I used. You have to either change the sources so that 
TIFFUtil is a public class, or copy the TIFFUtil source code, or just 
add this segment to a local copy of the PDFBox sources.

     void saveAsMultipageTIFF(ArrayList<BufferedImage> bimTab, String 
filename, int dpi)
             throws IOException
     {
         Iterator<ImageWriter> writers = 
ImageIO.getImageWritersByFormatName("tiff");
         ImageWriter imageWriter = writers.next();

         ImageOutputStream ios = ImageIO.createImageOutputStream(new 
File(filename));
         imageWriter.setOutput(ios);
         imageWriter.prepareWriteSequence(null);
         for (BufferedImage image : bimTab)
         {
             ImageWriteParam param = imageWriter.getDefaultWriteParam();
             IIOMetadata metadata = 
imageWriter.getDefaultImageMetadata(new ImageTypeSpecifier(image), param);
             param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
             TIFFUtil.setCompressionType(param, image);
             TIFFUtil.updateMetadata(metadata, image, dpi);
             imageWriter.writeToSequence(new IIOImage(image, null, 
metadata), param);
         }
         imageWriter.endWriteSequence();
         imageWriter.dispose();
         ios.flush();
         ios.close();
     }


Mime
View raw message