Images are not stored inside a PDF file as Tiff or PNG or JPG images. They are stored as the binary pixel data along with the Colorspace used by that data. This allows a lot of flexibilty. For example, a CMYK image can be stored as a block of binary data (4 bytes for each pixel) and a specified as using a CMYKColorspace. The actual image data can be compressed in different ways to best suit the data (DCT for colour images, CCITT or JBIG2 for black and white 1 bit images). The image is scaled to fit the slot of the page so it can often be of a higher resolution.
There are 2 image commands for drawing images (ID and DO). The ID command allows the binary image data to be embedded in the command stream. This is not as flexible as the DO command which stores the image in a separate PDF object of type XObject or XForm. So the DO command tells to be far more common. It allows better data compression, offers more functionality and you can edit the image object without having to alter the command stream.
Each image has a name (like Im4). In the stream, you would see the command
which draws the image at this point with the current graphics Matrix.
The actual image IM4 is defined in a separate object which is listed in the Resources table. In this case it is Object 20 0 R.
XObject<</Im4 20 0 R/Im3 21 0 R>>
Object 20 contains the information on the image and the compressed binary pixel data
20 0 obj <<
ColorSpace 17 0 R/
stream (binary pixel data follows)
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!
Latest posts by Mark Stephens (see all)
- NetBeans Day 2016 – First 2 sessions - September 18, 2016
- IDRsolutions at Business of Software (Boston) and JavaOne (San Francisco) in September - August 18, 2016
- Removal of signed JPedal Java PDF Library SDK jars from August 2016 release - August 16, 2016
- 3 enhancements for our free online PDF to HTML5 and SVG converter - July 5, 2016
- NetCat 8.2 – what it is and why you should care… - June 28, 2016