Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

Understanding the PDF file Format – PDF image color depth

1 min read

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 not seen an odd 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 ‘palete 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.

This post is part of our “Understanding the PDF File Format” series. In each article, we aim to take a specific PDF feature and explain it in simple terms. If you wish to learn more about PDF, we have 13 years worth of PDF knowledge and tips, so click here to visit our series index!

Did you know...

IDRsolutions offers a whole range of online file converters to convert PDF and Microsoft Excel, Word and Office Documents to HTML5, SVG or image formats?

It is free to use for single file conversions and also includes Developer links if you want to use our commercial software for bulk conversions. Find out more on this page

Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

How to convert WMF files to SVG in java…

This article will show you how to convert WMF files into SVG files using our JDeli Java Image library. What is WMF? WMF is...
Amy Pearson
1 min read

How to write WebP images in Java

In this article, I will walk you through how to write out images as WebP images in Java. ImageIO does not support WebP images...
Mark Stephens
1 min read

How to convert EMF files to SVG in Java…

This article shows you how to convert EMF files into SVG files using our JDeli Java Image library. What is EMF? EMF is a...
Mark Stephens
1 min read

2 Replies to “Understanding the PDF file Format – PDF image color…”

  1. Hi,
    I want to detect the images in a pdf file and get the pixel color of the images. How it can be done??

Leave a Reply

Your email address will not be published. Required fields are marked *

IDRsolutions Ltd 2020. All rights reserved.