JAI: How do I extract a single page input stream from a multipaged TIFF image container?

后端 未结 1 1722
梦毁少年i
梦毁少年i 2021-01-15 08:51

I have a component that converts PDF documents to images, one image per page. Since the component uses converters producing in-memory images, it hits the JVM heap h

相关标签:
1条回答
  • 2021-01-15 09:53

    I could be wrong, but don't think JAI has support for splitting TIFFs without decoding the files to in-memory images. And, sorry for promoting my own library, but I think it does exactly what you need (the main part of the solution used to split TIFFs is contributed by a third party).

    By using the TIFFUtilities class from com.twelvemonkeys.contrib.tiff, you should be able to split your multi-page TIFF to multiple single-page TIFFs like this:

    TIFFUtilities.split(tempFile, new File("output"));
    

    No decoding of the images are done, only splitting each IFD into a separate file, and writing the streams with corrected offsets and byte counts.

    Files will be named output/0001.tif, output/0002.tif etc. If you need more control over the output name or have other requirements, you can easily modify the code. The code comes with a BSD-style license.

    0 讨论(0)
提交回复
热议问题