This article is all about color in PDF images, and exactly what the depth of an image means in practice.
All PDF images will specify a width, a height, a ColorSpace and the number of bits per color component (a color depth). This is the number of bits used to store each color component for each pixel. It is usually 8 bits (ie a byte), 1 bit or sometimes 2 or 4 bits. I have only very occasionally seen a value or a number greater that 8. If the number is less that 8, the bits are packed together into pixels (so a single byte would contain 2 values).
To get a real indication of the total number amount of memory used, you also need to look at the type of color (the PDF ColorSpace). An RGB image will have 3 ‘channels’ (Red, Green and Blue) so an 8 bit RGB pixel needs 24 bits (3 bytes) in total. A CMYK 8 bit image would need 4 bytes.
Some Colorspaces only define one channel so an 8 bit Grayscale image needs 1 byte per pixel.
Indexed, Separation and DeviceN colorspaces work slightly differently. They still have a set number of pixels but this specifies the number of ‘palette colors’ you can choose from. So a 1 bit indexed or Separation colorspace PDF image can only contain TWO colors, but they can be any TWO colors defined by the user. They are very useful if you want to use a limited number of colors and reduce the size of the image data.
Now that you understand exactly how PDF image color depth works you can see how to interpret it and also how you can choose different ColorSpaces to optimise your images in different scenarios.
Are you a Developer working with PDF files?
Our developers guide contains a large number of technical posts to help you understand the PDF file Format.
Do you need to solve any of these problems?
|Display PDF documents in a Web app|
|Use PDF Forms in a web browser|
|Convert PDF Documents to an image|
|Work with PDF Documents in Java|
2 Replies to “How does image color depth work in PDF files?”
I want to detect the images in a pdf file and get the pixel color of the images. How it can be done??
You best bet would be to look at the XObjects in the Resources directly with a tool like IText.
If you just want to extract the images as sRGB, we have some newly updated examples for JPedal which are documented at https://support.idrsolutions.com/jpedal/tutorials/extract-images/extract-images-from-pdf
Comments are closed.