Repository navigation
PDF20 Spec 07 Content Streams
Part of: PDF20-Spec-07-Syntax
Navigation: PDF20-Spec-07-Document-Structure | PDF20-Spec-Index | PDF20-Spec-07-Common-Data
7.8
name tree
(Optional; PDF 1.4; deprecated in PDF 2.0) A name tree mapping name strings to alternate presentations (see 13.5, "Alternate presentations"). (Optional; PDF 1.5) A name tree mapping name strings (which shall have Unicode encoding) to rendition objects (see 13.2.3, "Renditions").
Content streams and resources
7.8.1 General Content streams are the primary means for describing the appearance of pages and other graphical elements. A content stream depends on information contained in an associated resource dictionary; in combination, these two objects form a self-contained entity. This subclause describes these objects.
7.8.2 Content streams A content stream is a PDF stream object whose data consists of a sequence of instructions describing the graphical elements to be painted on a page. The instructions shall be represented in the form of PDF objects, using the same object syntax as in the rest of the PDF file. However, whereas the file as a whole is a static, random-access data structure, the objects in the content stream shall be interpreted and acted upon sequentially. Each page of a document shall be represented by one or more content streams. Content streams shall also be used to package sequences of instructions as self-contained graphical elements, such as forms (see 8.10, "Form XObjects"), patterns (8.7, "Patterns"), certain fonts (9.6.4, "Type 3 fonts"), and annotation appearances (12.5.5, "Appearance streams"). A content stream, after decoding with any specified filters, shall be interpreted according to the PDF syntax rules described in 7.2, "Lexical conventions". It consists of PDF objects denoting operands and operators. The operands needed by an operator shall precede it in the stream. See Example 4 in 7.4, "Filters" for an example of a content stream. An operand is a direct object belonging to any of the basic PDF data types except a stream. Dictionaries 110
© ISO 2020 – All rights reserved
ISO 32000-2:2020(E)
shall be permitted as operands only by certain specific operators. Indirect objects and object references shall not be permitted at all. An operator is a PDF keyword specifying some action that shall be performed, such as painting a graphical shape on the page. An operator keyword shall be distinguished from a name object by the absence of an initial SOLIDUS character (2Fh) (/). Operators shall be meaningful only inside a content stream. NOTE 1
Annex A, "Operator Summary" provides a summary of all PDF operators.
NOTE 2
This postfix notation, in which an operator is preceded by its operands, is superficially the same as in the PostScript language. However, PDF has no concept of an operand stack as the PostScript language has.
In PDF, all of the operands needed by an operator shall immediately precede that operator. Operators do not return results, and operands shall not be left over when an operator finishes execution. NOTE 3
Most operators have to do with painting graphical elements on the page or with specifying parameters that affect subsequent painting operations. The individual operators are described in the clauses devoted to their functions:
Clause 8, "Graphics" describes operators that paint general graphics, such as filled areas, strokes, and sampled images, and that specify device-independent graphical parameters, such as colour. Clause 9, "Text" describes operators that paint text using character glyphs defined in fonts. Clause 10, "Rendering" describes operators that specify device-dependent rendering parameters. Clause 14, "Document interchange" describes the marked-content operators that associate higher-level logical information with objects in the content stream. These operators do not affect the rendered appearance of the content; they specify information useful to applications that use PDF for document interchange. Ordinarily, when a PDF reader encounters an operator in a content stream that it does not recognise, an error shall occur. A pair of compatibility operators, BX and EX (PDF 1.1), shall modify this behaviour (see "Table 33 — Compatibility operators"). These operators shall occur in pairs and may be nested. They bracket a compatibility section, a portion of a content stream within which unrecognised operators shall be ignored without error. This mechanism enables a PDF processor to use operators defined in later versions of PDF without sacrificing compatibility with older applications. It should be used only in cases where ignoring such newer operators is the appropriate thing to do. The BX and EX operators are not themselves part of any graphics object (see 8.2, "Graphics objects") or of the graphics state (8.4, "Graphics state").
© ISO 2020 – All rights reserved
111
ISO 32000-2:2020(E)
Table 33 — Compatibility operators Operands
Operator
Description
—
BX
(PDF 1.1) Begin a compatibility section. Unrecognised operators (along with their operands) shall be ignored without error until the balancing EX operator is encountered.
—
EX
(PDF 1.1) End a compatibility section begun by a balancing BX operator. Ignore any unrecognised operands and operators from previous matching BX onward.
7.8.3 Resource dictionaries As stated in 7.8.2, "Content streams" the operands supplied to operators in a content stream shall only be direct objects; indirect objects and object references shall not be permitted. In some cases, an operator shall refer to a PDF object that is defined outside the content stream, such as a font dictionary or a stream containing image data. This shall be accomplished by defining such objects as named resources and referring to them by name from within the content stream. Named resources shall be meaningful only in the context of a content stream. The scope of a resource name shall be local to a particular content stream and shall be unrelated to externally known identifiers for objects such as fonts. References from one object outside of content streams to another outside of content streams shall be made by means of indirect object references rather than named resources. A content stream’s named resources shall be defined by a resource dictionary, which shall enumerate the named resources needed by the operators in the content stream and the names by which they can be referred to. EXAMPLE 1
If a text operator appearing within the content stream needs a certain font, the content stream’s resource dictionary can associate the name F42 with the corresponding font dictionary. The text operator can use this name to refer to the font.
A resource dictionary shall be associated with a content stream in one of the following ways: •
For a content stream that is the value of a page’s Contents entry (or is an element of an array that is the value of that entry), the resource dictionary shall be designated by the page dictionary’s Resources entry or is inherited, as described under 7.7.3.4, "Inheritance of page attributes" from some ancestor node of the page object. PDF writers should not use this inheritance feature of PDF as its use can cause undue complexity for a PDF reader. A PDF writer should only include resource definitions for resources that are actually referenced by the content streams of the associated page in the Resources dictionary. If the content streams of multiple pages require exactly the same set of resources, a single Resources dictionary may be shared between them by using indirect references. If each page requires different sets of resources, then each should be written with its own Resources dictionary.
•
Content streams that define the glyph descriptions of a Type 3 font shall include a Resources entry in the Type 3 font dictionary specifying all the resources used by all the content streams in the CharProcs dictionary of a Type 3 font.
•
For other content streams, a PDF writer shall include a Resources entry in the stream's dictionary specifying the resource dictionary which contains all the resources used by that
112
© ISO 2020 – All rights reserved
ISO 32000-2:2020(E)
content stream. This shall apply to content streams that define form XObjects, patterns, and annotation appearances. •
PDF files written obeying earlier versions of PDF may have omitted the Resources entry in all form XObjects and Type 3 fonts used on a page. All resources that are referenced from those forms and fonts shall be inherited from the resource dictionary of the page on which they are used.
NOTE
The above bulleted list was clarified in this document (2020).
In the context of a given content stream, the term current resource dictionary refers to the resource dictionary associated with the stream in one of the ways described above. Each key in a resource dictionary shall be the name of a resource type, as shown in "Table 34 — Entries in a resource dictionary". The corresponding values shall be as follows: •
For all resource types, the value shall be a subdictionary. Each key in the subdictionary shall be the name of a specific resource, and the corresponding value shall be a PDF object associated with the name. Table 34 — Entries in a resource dictionary Key
Type
Value
ExtGState
dictionary
(Optional) A dictionary that maps resource names to graphics state parameter dictionaries (see 8.4.5, "Graphics state parameter dictionaries").
ColorSpace
dictionary
(Optional) A dictionary that maps each resource name to either the name of a device-dependent colour space or an array describing a colour space (see 8.6, "Colour spaces").
Pattern
dictionary
(Optional) A dictionary that maps resource names to pattern objects (see 8.7, "Patterns").
Shading
dictionary
(Optional; PDF 1.3) A dictionary that maps resource names to shading dictionaries (see 8.7.4.3, "Shading dictionaries").
XObject
dictionary
(Optional) A dictionary that maps resource names to external objects (see 8.8, "External objects").
Font
dictionary
(Optional) A dictionary that maps resource names to font dictionaries (see 9, "Text").
ProcSet
array
(Optional; deprecated in PDF 2.0) An array of predefined procedure set names (see 14.2, "Procedure sets").
Properties
dictionary
(Optional; PDF 1.2) A dictionary that maps resource names to property list dictionaries for marked-content (see 14.6.2, "Property lists").
© ISO 2020 – All rights reserved
113
ISO 32000-2:2020(E)
EXAMPLE 2
The following shows a resource dictionary containing fonts, and external objects. The fonts are specified with a subdictionary associating the names F5, F6, F7, and F8 with objects 6, 8, 10, and 12, respectively. Likewise, the XObject subdictionary associates the names Im1 and Im2 with objects 13 and 15, respectively.
<</Font <</F5 6 0 R /F6 8 0 R /F7 10 0 R /F8 12 0 R
/XObject <</Im1 13 0 R /Im2 15 0 R
Navigation: PDF20-Spec-07-Document-Structure | PDF20-Spec-Index | PDF20-Spec-07-Common-Data