Skip to Content
PDF Explained
book

PDF Explained

by John Whitington
December 2011
Beginner
140 pages
2h 59m
English
O'Reilly Media, Inc.
Content preview from PDF Explained

Chapter 5. Graphics

In this chapter, we’ll run through the main ways to build graphics in the content stream of a PDF page. All of the examples are based on the same PDF we created manually in Chapter 2 and processed into valid PDF documents with pdftk in the same fashion. All the examples are included in the online resources.

Looking at Content Streams

A PDF page is made up of one or more content streams, defined by the /Contents entry in the page object, together with a shared set of resources, defined by the /Resources entry. In all our examples, there will only be a single content stream. Multiple content streams are equivalent to a single stream containing their concatenated content.

Here’s an example page, with no resources and a single content stream:

3 0 obj
<<
  /Type /Page
  /Parent 1 0 R
  /Resources << >>
  /MediaBox [ 0 0 792 612 ]
  /Rotate 0
  /Contents [ 2 0 R ]
>>
endobj

Here’s the associated content stream, consisting of the stream dictionary and the stream data.

2 0 obj
<< /Length 18 >> Stream dictionary
stream
200 150 m 600 450 l S Stream data
endstream
endobj

We’ll discover what the m, l and S operators do in a moment. The numbers are measurements in points—a point (or pt) is 1/72 inch. The result of loading this document into a PDF viewer (after processing with pdftk as per Chapter 2) is shown in Figure 5-1.

The full manually created file (before processing with pdftk) is shown in Example 5-1. We’re going to be using variations on this file for the rest of this chapter. For the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Developing with PDF

Developing with PDF

Leonard Rosenthol
Accelerate

Accelerate

Nicole Forsgren, Jez Humble, Gene Kim
LLM Engineer's Handbook

LLM Engineer's Handbook

Paul Iusztin, Maxime Labonne

Publisher Resources

ISBN: 9781449321581Errata Page