Programming with Quartz: 2D and PDF Graphics in Mac OS X

The last chapter discussed how to open and draw existing PDF documents. The PDF discussion continues in this chapter by showing how to use Quartz to create new PDF documents. Working with PDF in this way is straightforward because Quartz uses the PDF file format as its graphics metafile format. Creating a PDF document from Quartz drawing captures virtually all of the original drawing without lossy data compression and without down-sampling (unless required to conform with the PDF specification). Line art graphics, images, text drawing, drawing of existing PDF pages, and path-and image-based clipping can all be represented with their full fidelity in PDF documents created by Quartz.
The ability to examine the structure of an existing PDF document and access the data that corresponds to the content stream of a PDF document is important to many developers. Beginning with Panther, Quartz provides functions that allow you to extract virtually any information you want from a PDF document, including the raw data that makes up the page content stream of any page. Starting in Tiger, Quartz provides the ability to parse the content stream data. Through parsing, you can examine the drawing content of any page in a PDF document.
A special type of Quartz graphics context called a PDF context is what captures Quartz drawing as a PDF document. Like all Quartz graphics contexts, a PDF context is an opaque object of type CGContextRef. You create a PDF context and draw into it...