Skip to content

TIFF Images Support

galkahana edited this page Aug 15, 2011 · 4 revisions

TIFF Image support is provided via LibTiff. Tiff 6.0 images are supported. refer to libtiff for specific details. Note that for the time being the PDF Library does not provide support for JPG compressed tiffs, although libtiff does.

Features supported for tiff images:

  • Page selection of multipage tiffs
  • 1-0 colors setting for B/W TIFF Images
  • Range colors setting for Grayscale TIFF Images

Usage

To use TIFF Image support create a form xobject representing the TIFF image with the following method:
PDFFormXObject* CreateFormXObjectFromTIFFFile(const string& inTIFFFilePath , const TIFFUsageParameters& inTIFFUsageParameters)

The first parameter inTIFFFilePath is the file path to the TIFF image. Path should be UTF8 encoded.
The second parameter inTIFFUsageParameters is optional and is used for setting parameters for the creation of the TIFF image. See next section for details.

The returned object is a PDFFormXObject, which holds a reference to the form XObject ID. This ID may be used With a page, or a form resource dictionary to receive a name, which in turn can be placed with a Do command in a content stream.

See TIFFImageTest for usage sample.

Note that creation method has a override receiving ObjectIDType as input. This variant is to be used when forward referencing is sought after (first usage of form, then creation of it). consult Forward Referencing for information.

Using inTIFFUsageParameters

The 2nd parameter of CreateFormXObjectFromTIFFFile is a structure of type TIFFUsageParameters allows you to control 3 properties of the creation:

  1. PageIndex – when displaying multi-page TIFF images this parameter should be used to indicate which image to display. 0 based.
  2. BWTreatment – a parameter for handling Black and White images. It is of structure TIFFBiLevelBWColorTreatment. This will allows turning a black and white image to an imagemask, where the “Black” values are set by the color, and the “White” values show through. TIFFBiLevelBWColorTreatment structure has two members:
    AsImageMask – when true, the image will become an imagemask, with the color defined by OneColor as a “Black” value.
    OneColor – parameter of type CMYKRGBColor that sets the black values for the mask.
  3. GrayscaleTreatment – a parameter for handling Grayscale images. It is of structure TIFFBiLevelGrayscaleColorTreatment. This allows turning a Grayscale image to a play between a color defined as “White”, and a color defined as “Black”, where each level of gray determines the mix (obviously, you can choose to leave white as white, which would make this an image moving between levels of the color defined as black). TIFFBiLevelGrayscaleColorTreatment has 3 members:
    AsColorMap – when true, the image will become colored, where each Grayscale value determines a level of play between “Black” and “White” color.
    OneColor – “Black” color.
    ZeroColor – “White” color.

When leaving the default for CreateFormXObjectFromTIFFFile , the first image is displayed for a multipage image. also, grayscale image will appear grayscale, and black and white image apperas as black and white.

for a usage example check TiffSpecialsTest

Note that image input can come from any stream, and not just files. For a discussion of custom stream input see Custom input and output

Clone this wiki locally