iText DITO

iText DITO simplifies the process of creating multiple data-driven templates. An intuitive front end gives you the ability to design your own templates and forms, tied to a powerful back end. iText DITO handles everything from HTML5 input form creation and data processing, to the output of PDFs. This reduces workload for developers by offering a way to get results without wasting time writing lines of code.

A big thank you to our Q3 top contributors!

There are so many people that contribute information to us in order to help improve our code, products and projects. We want to make sure that our top contributors are being recognized for the help they give and that they know how much we appreciate them.

Top menu

Breadcrumb

Which image types are supported by iText?

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?

31st May 2016

admin-marketing

iText supports JPEG, JPEG2000, GIF, PNG, SVG, 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.

JPEG images are kept as is by iText. You can take the content stream of an Image XObject of type JPEG, copy it into a file and you'll have a valid JPEG image. You can recognize these images by their filter: /DCTDecode.

JPEG2000 is supported since PDF 1.5. The name of the filter is JPXDecode.

Although PDF supports images with LZW compression (used for GIFs), iText decodes GIF images into a raw image. If you create an Image in iText with a path to a GIF file, you'll get an image with filter /FlateDecode in your PDF.

PNG isn't supported in PDF, which is why iText will also decode PNG images into rw images. If the color space of the image is DeviceGray and if the image only has 1 bit per component, CCITT will be used as compression and you'll recognize the filter /CCITTFaxDecode. Otherwise, the filter /FlateDecode will be used.

SVG support was initially added in iText 7.1.2, and significantly improved in iText 7.1.6 with support for SVG transparency and elliptical, cubic, and quadratic Bézier paths.

BMP files will be stored as a series of compressed pixels using /FlateDecode as filter.

WMF is special. If you insert a WMF file into a PDF document using iText, iText will convert that image into PDF syntax. Instead of adding an Image XObject, iText will create a form XObject.

When the image data is encoded using the CCITT facsimile standard, the /CCITTFaxDecode filter will be used. These are typically monochrome images with one bit per pixel.

TIFFs will be examined by iText. Depending on the TIFFs parameters, iText can decide to use /CCITTFaxDecode, /FlateDecode or even /DCTDecode as filter.

JBIG2 uses the /JBIG2Decode filter.

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. An 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.

Click this link if you want to see how to answer this question in iText 5.

Ready to use iText?

As always, if you have any technical questions, you can contact support with your valid support subscription or head over to one of our community support pages on Stack Overflow to see if your question has already been answered for our AGPL users.