简体   繁体   中英

Extract TIFF images from PDF without decoding

With the help of iText 5 I would like to extract all TIFF images from given PDF file and save them as TIFF files. Examples and other posts ( 1 , 2 ) use the following method:

  1. Create PdfImageObject from PDF stream which in line 189 decodes the image stream (if corresponding filter implementation is present).
  2. Call PdfImageObject#getImageAsBytes() which returns JPEG (original), PNG (re-encoded) or TIFF (in case of 8 bits per pixel).

As a result TIFF image with 1 bit color depth is converted to PNG, which is not what I need.

Another approach would be to call PdfImageObject#getBufferedImage() which will decode the image in step (2) into raster and afterwards encode it again as TIFF using ImageIO.write(bufferedImage, "tiff", file) .

As one can see this is not efficient. Another solution shown in this post demonstrates how to save encoded TIFF image stream to file by prepending it a TIFF header – that is the solution I am looking for.

Can iText help here?

PDF images are not TIFF images.

PDFs however can contain images that use compression techniques that are also used in TIFF, eg Flate, CCITT, LZW, JPEG.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM