Chapter 2. PDF Imaging Model

In this chapter you’ll begin your exploration into the PDF imaging model—that is, the various types of graphic operations that can be carried out on the pages of a document. You’ll learn not only the language used to describe those operations, but also about various graphic and imaging concepts that accompany it.

Content Streams

As described in the previous chapter, a PDF file is composed of one or more pages (of a fixed size), and the visible elements on each page come from either the page content or a series of annotations that sit on top (visibly) of the content. This chapter discusses the page content.

Page content is described using a special text-based syntax (related to, but different from the PDF file syntax that you learned about in Chapter 1) that is stored in the PDF inside of a special type of stream object called a content stream. The content syntax is derived from Adobe’s Postscript language and is comprised of a series of operators and their operands, where each operand can be expressed as a standard PDF object (see PDF Objects). A simple example, for drawing a rectangle filled with the color blue, is given in Example 2-1.

Example 2-1. Drawing a simple rectangle
Simple Blue Rectangle
0 0 1 rg               % set the color to blue in RGB
0 0 100 100 re         % draw a rectangle 100x100 with the bottom left at 0,0
F                      % fill it

We’ll look at the various operators themselves shortly, but for ...

Get Developing with PDF now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.