I want to add a PNG image to a PDF file, but I've read that PNG files aren't supported in PDF.
Does this mean that I can't use PNG files when using iText?
iText supports JPEG, JPEG2000, GIF, PNG, BMP, WMF, TIFF, CCITT and JBIG2 images. This doesn't mean that these images types are also supported in PDF. If a specific image type (for instance PNG) isn't supported in PDF, iText will convert it to an image type that is defined in the PDF specification.
Imagein iText with a path to a GIF file, you'll get an image with filter
/FlateDecodein your PDF.
/CCITTFaxDecode. Otherwise, the filter
/FlateDecodewill be used.
/CCITTFaxDecodefilter will be used. These are typically monochrome images with one bit per pixel.
Normally, you don't need to worry about the image type. The
Image class takes care of choosing the right compression method for you.
Extra remark: PDF supports transparency, but please be aware that transparent images as such aren't supported in PDF. A single image that contains transparent areas will be converted to two different images:
The opaque image,
An image mask.
This is inherent to PDF. If you add a transparent image to a PDF file, you can't extract that image from the PDF. Instead you'll have to abstract two images, the opaque version and its image mask.