跳转至

8.11 可选内容

Optional Content

8.11.1 概述

General

可选内容(PDF 1.5)指的是PDF文档中可以由文档作者或消费者选择性查看或隐藏的内容子句。这种功能在诸如CAD绘图、分层艺术作品、地图和多语言文档等项目中非常有用。

NOTE

以下子条款描述了用于实现可选内容的PDF结构:

8.11.2,“可选内容组”,描述了用于控制内容可见性的主要结构。

8.11.3,“使图形内容可选”,描述了文档中的个别内容如何声明自己属于一个或多个可选内容组。

8.11.4,“配置可选内容”,描述了如何设置可选内容组的状态。

Optional content (PDF 1.5) refers to sub-clauses of content in a PDF document that can be selectively viewed or hidden by document authors or consumers. This capability is useful in items such as CAD drawings, layered artwork, maps, and multi-language documents.

NOTE

The following sub-clauses describe the PDF structures used to implement optional content:

8.11.2, "Optional Content Groups", describes the primary structures used to control the visibility of content.

8.11.3, "Making Graphical Content Optional", describes how individual pieces of content in a document may declare themselves as belonging to one or more optional content groups.

8.11.4, "Configuring Optional Content", describes how the states of optional content groups are set.

8.11.2 可选内容组

Optional Content Groups

8.11.2.1 概述

General

可选内容组是一个表示图形集合的字典,用户可以通过符合规范的阅读器动态地将其显示或隐藏。属于这种组的图形可以位于文档的任何位置:它们不需要在绘制顺序上连续,也不需要属于同一个内容流。下表(表98)显示了可选内容组字典中的条目。

Table 98 – 可选内容组字典中的条目
Key Type Value
Type name (必需) 此字典描述的PDF对象类型;对于可选内容组字典,应为 OCG
Name text string (必需) 可选内容组的名称,适合在阅读器的用户界面中显示。
Intent name or array (可选) 一个意图名称或包含多个名称的数组。PDF定义了两个名称,ViewDesign,可以指示组中图形的预期用途。符合规范的阅读器可以选择仅使用具有特定意图的组并忽略其他组。默认值:View。更多信息见 8.11.2.3,"意图"。
Usage dictionary (可选) 一个描述组控制内容性质的 使用 字典。它可以被自动控制组状态的功能使用,基于外部因素。更多信息见 8.11.4.4,"使用和使用应用字典"。

在其最简单的形式中,每个字典应包含一个 Type 条目和一个用于在用户界面中显示的 Name。它还可以有一个描述其预期用途的 Intent 条目(见 8.11.2.3,"意图")和一个描述其内容性质的 Usage 条目(见 8.11.4.4,"使用和使用应用字典")。

文档中的单个内容元素可以指定影响其可见性的可选内容组或多个组(见 8.11.3,"使图形内容可选")。任何受给定可选内容组影响其可见性的内容被称为属于该组。

一个组应被分配一个状态,状态可以是 ONOFF。状态本身不是PDF文档的一部分,但可以通过程序或阅读器的用户界面进行设置,以改变内容的可见性。当符合规范的阅读器首次打开文档时,组的状态应根据文档的默认配置字典进行初始化(见 8.11.4.3,"可选内容配置字典")。

属于组的内容在组为 ON 时可见,在组为 OFF 时不可见。内容可以属于多个组,这些组可能有冲突的状态。这些情况应通过使用可选内容成员字典来描述,详见下一子条款。

An optional content group is a dictionary representing a collection of graphics that can be made visible or invisible dynamically by users of conforming readers. The graphics belonging to such a group may reside anywhere in the document: they need not be consecutive in drawing order, nor even belong to the same content stream. Table 98 shows the entries in an optional content group dictionary.

Table 98 – Entries in an Optional Content Group Dictionary
Key Type Value
Type name (Required) The type of PDF object that this dictionary describes; shall be OCG for an optional content group dictionary.
Name text string (Required) The name of the optional content group, suitable for presentation in a reader’s user interface.
Intent name or array (Optional) A single intent name or an array containing any combination of names. PDF defines two names, View and Design, that may indicate the intended use of the graphics in the group. A conforming reader may choose to use only groups that have a specific intent and ignore others. Default value: View. See 8.11.2.3, "Intent" for more information.
Usage dictionary (Optional) A usage dictionary describing the nature of the content controlled by the group. It may be used by features that automatically control the state of the group based on outside factors. See 8.11.4.4, "Usage and Usage Application Dictionaries" for more information.

In its simplest form, each dictionary shall contain a Type entry and a Name for presentation in a user interface. It may also have an Intent entry that may describe its intended use (see 8.11.2.3, "Intent") and a Usage entry that shall describe the nature of its content (see 8.11.4.4, "Usage and Usage Application Dictionaries").

Individual content elements in a document may specify the optional content group or groups that affect their visibility (see 8.11.3, "Making Graphical Content Optional"). Any content whose visibility shall be affected by a given optional content group is said to belong to that group.

A group shall be assigned a state, which is either ON or OFF. States themselves are not part of the PDF document but may be set programmatically or through the reader’s user interface to change the visibility of content. When a document is first opened by a conforming reader, the groups’ states shall be initialized based on the document’s default configuration dictionary (see 8.11.4.3, "Optional Content Configuration Dictionaries").

Content belonging to a group shall be visible when the group is ON and invisible when it is OFF. Content may belong to multiple groups, which may have conflicting states. These cases shall be described by the use of optional content membership dictionaries, described in the next sub-clause.

8.11.2.2可选内容会员词典

Optional Content Membership Dictionaries

如上所述,内容可以属于单个可选内容组,当组状态为 ON 时内容可见,为 OFF 时内容不可见。为了表达更复杂的可见性策略,内容不应直接声明其属于可选内容组,而应声明其属于一个 可选内容成员字典。下表(表99)显示了可选内容成员字典中的条目。

Table 99 – 可选内容成员字典中的条目
Key Type Value
Type name (必需) 此字典描述的PDF对象类型;对于可选内容成员字典,应为 OCMD
OCGs dictionary or array (可选) 一个字典或字典数组,指定确定受此成员字典控制内容可见性的可选内容组。
Null值或已删除对象的引用应被忽略。如果此条目不存在、为空数组或仅包含对null或已删除对象的引用,则成员字典对任何内容的可见性没有影响。
P name (可选) 指定此成员字典所属内容的 可见性策略 的名称。有效值应为:
AllOn 仅当 OCGs 中的所有条目为 ON 时可见
AnyOn 任何 OCGs 条目为 ON 时可见
AnyOff 任何 OCGs 条目为 OFF 时可见
AllOff 仅当 OCGs 中的所有条目为 OFF 时可见
默认值:AnyOn
VE array (可选; PDF 1.6) 一个指定 可见性表达式 的数组,用于基于一组可选内容组计算内容的可见性;见下文讨论。

可选内容成员字典可以通过两种方式表达其可见性策略:

  • P 条目可以指定一个简单的布尔表达式,指示 OCGs 条目指定的可选内容组如何决定受成员字典控制内容的可见性。
  • PDF 1.6引入了 VE 条目,这是一个可见性表达式,可以用于指定一个任意布尔表达式,从可选内容组的状态计算内容的可见性。

NOTE 2

由于 VE 条目更为通用,如果它存在并被符合标准的阅读器软件支持,它应该优先于 OCGsP 条目使用。然而,为了兼容性,符合标准的写入器应尽可能使用 OCGsP 条目。当需要使用 VE 来表达预期行为时,也应提供 OCGsP 条目以在不符合标准的阅读器软件中近似该行为。

可见性表达式是具有以下特征的数组:

  • 第一个元素应为表示布尔运算符的名称 (AndOr,或 Not)。
  • 后续元素应为可选内容组或其他可见性表达式。
  • 如果第一个元素是 Not,它应只有一个后续元素。如果第一个元素是 AndOr,它应有一个或多个后续元素。
  • 在评估可见性表达式时,可选内容组的 ON 状态应等同于布尔值 trueOFF 状态应等同于 false

成员字典在以下情况下很有用:

  • 某些内容可能选择在组为 ON不可见,而在组为 OFF可见。在这种情况下,内容将属于一个成员字典,该字典的 OCGs 条目包含单个可选内容组,其 P 条目为 AnyOffAllOff

NOTE 3

OCGs 条目由单个组和 P 条目为 AnyOnAllOn 组成是合法的。然而,在这种情况下,优选直接使用可选内容组,因为它使用更少的对象。

  • 某些内容可能属于多个组,并且需要在组状态冲突时指定其策略。在这种情况下,内容将属于一个成员字典,该字典的 OCGs 条目包含一组可选内容组,其 P 条目指定可见性策略,如本小节中的示例1所示。本小节中的示例2显示了使用可见性表达式的等效策略。

EXAMPLE 1

此示例显示属于一个成员字典的内容,其 OCGs 条目由一组可选内容组组成,P 条目指定可见性策略。

<< /Type /OCMD                        % 属于这个可选内容成员字典的内容
                                        % 由三个可选内容组的状态控制。
    /OCGs [12 0 R 13 0 R 14 0 R]       % 三个可选内容组。
    /P /AllOn                          % 仅当所有三个组的状态为ON时,内容可见;
>>                                    % 否则它是隐藏的。

EXAMPLE 2

此示例显示与本小节示例1等效的可见性表达式

<< /Type /OCMD
    /VE [/And 12 0 R 13 0 R 14 0 R]    % 所有三个组的状态为ON时,内容可见;
>>                                   

EXAMPLE 3

此示例显示了一个更复杂的可见性表达式,基于五个可选内容组,由对象1到5表示。它等效于:

“OCG 1” OR (NOT “OCG 2”) OR (“OCG 3” AND “OCG 4” AND “OCG 5”)


<< /Type /OCMD
    /VE [/Or                            % 可见性表达式:OR
            10R                         % OCG 1
            [/Not 2 0 R]                % 非 OCG 2
            [/And 3 0 R 4 0 R 5 0 R]    % OCG 3 且 OCG 4 且 OCG 5
        ]
>>                                    

As mentioned above, content may belong to a single optional content group and shall be visible when the group is ON and invisible when it is OFF. To express more complex visibility policies, content shall not declare itself to belong directly to an optional content group but rather to an optional content membership dictionary, whose entries are shown in Table 99.

Table 99 – Entries in an Optional Content Membership Dictionary
Key Type Value
Type name (Required) The type of PDF object that this dictionary describes; shall be OCMD for an optional content membership dictionary.
OCGs dictionary or array (Optional) A dictionary or array of dictionaries specifying the optional content groups whose states shall determine the visibility of content controlled by this membership dictionary.
Null values or references to deleted objects shall be ignored. If this entry is not present, is an empty array, or contains references only to null or deleted objects, the membership dictionary shall have no effect on the visibility of any content.
P name (Optional) A name specifying the visibility policy for content belonging to this membership dictionary. Valid values shall be:
AllOn visible only if all of the entries in OCGs are ON
AnyOn visible if any of the entries in OCGs are ON
AnyOff visible if any of the entries in OCGs are OFF
AllOff visible only if all of the entries in OCGs are OFF
Default value: AnyOn
VE array (Optional; PDF 1.6) An array specifying a visibility expression, used to compute visibility of content based on a set of optional content groups; see discussion below.

An optional content membership dictionary may express its visibility policy in two ways:

  • The P entry may specify a simple boolean expression indicating how the optional content groups specified by the OCGs entry determine the visibility of content controlled by the membership dictionary.
  • PDF 1.6 introduced the VE entry, which is a visibility expression that may be used to specify an arbitrary boolean expression for computing the visibility of content from the states of optional content groups.

NOTE 2

Since the VE entry is more general, if it is present and supported by the conforming reader software, it should be used in preference to OCGs and P. However, for compatibility purposes, conforming writers should use OCGs and P entries where possible. When the use of VE is necessary to express the intended behaviour, OCGs and P entries should also be provided to approximate the behaviour in non-conforming reader software.

A visibility expression is an array with the following characteristics:

  • Its first element shall be a name representing a boolean operator (And, Or, or Not).
  • Subsequent elements shall be either optional content groups or other visibility expressions.
  • If the first element is Not, it shall have only one subsequent element. If the first element is And or Or, it shall have one or more subsequent elements.
  • In evaluating a visibility expression, the ON state of an optional content group shall be equated to the boolean value true; OFF shall be equated to false.

Membership dictionaries are useful in cases such as these:

  • Some content may choose to be invisible when a group is ON and visible when it is OFF. In this case, the content would belong to a membership dictionary whose OCGs entry consists of a single optional content group and whose P entry is AnyOff or AllOff.

NOTE 3

It is legal to have an OCGs entry consisting of a single group and a P entry that is AnyOn or AllOn. However, in this case it is preferable to use an optional content group directly because it uses fewer objects.

  • Some content may belong to more than one group and needs to specify its policy when the groups are in conflicting states. In this case, the content would belong to a membership dictionary whose OCGs entry consists of an array of optional content groups and whose P entry specifies the visibility policy, as illustrated in EXAMPLE 1 in this sub-clause. EXAMPLE 2 in this sub-clause shows the equivalent policy using visibility expressions.

EXAMPLE 1

This example shows content belonging to a membership dictionary whose OCGs entry consists of an array of optional content groups and whose P entry specifies the visibility policy.

<< /Type /OCMD                        % Content belonging to this optional content
                                      % membership dictionary is controlled by the states
   /OCGs [12 0 R 13 0 R 14 0 R]       % of three optional content groups.
   /P /AllOn                          % Content is visible only if the state of all three
>>                                    % groups is ON; otherwise it’s hidden.

EXAMPLE 2

This example shows a visibility expression equivalent to EXAMPLE 1 in this sub-clause

<< /Type /OCMD
   /VE [/And 12 0 R 13 0 R 14 0 R]    % groups is ON; otherwise it’s hidden.
>>                                   

EXAMPLE 3

This example shows a more complicated visibility expression based on five optional content groups, represented by objects 1 through 5. It is equivalent to

“OCG 1” OR (NOT “OCG 2”) OR (“OCG 3” AND “OCG 4” AND “OCG 5”)


<< /Type /OCMD
   /VE [/Or                            % Visibility expression: OR
           10R                         % OCG 1
           [/Not 2 0 R]                % NOT OCG 2
           [/And 3 0 R 4 0 R 5 0 R]    % OCG 3 AND OCG 4 AND OCG 5
       ]
>>                                    

8.11.2.3 目标

Intent

PDF定义了两个意图:Design,可用于表示文档设计者对艺术作品的结构组织;View,可用于文档使用者的交互使用。符合标准的写入器不应使用除DesignView之外的值。

NOTE

表98中的 Intent 条目提供了一种区分可选内容不同预期用途的方法。例如,许多文档设计应用程序(如CAD软件)提供分层功能,用于将图形分组并选择性地隐藏或查看它们,以方便作者。然而,这种分层可能与文档使用者所需的分层不同(例如,更细的粒度)。因此,可以在单个文档中为可选内容组指定不同的意图。符合标准的阅读器可能会决定仅使用特定意图的组。

配置字典(见8.11.4.3,“可选内容配置字典”)也可以包含 Intent 条目。如果一个或多个组的意图包含在当前配置的意图集中,则该组应用于确定可见性。如果没有匹配,则该组对可见性没有影响。

如果配置的 Intent 是一个空数组,则不应使用任何组来确定可见性;因此,所有内容都应视为可见。

PDF defines two intents: Design, which may be used to represent a document designer’s structural organization of artwork, and View, which may be used for interactive use by document consumers. A conforming writer shall not use a value other than Design or View.

NOTE

The Intent entry in Table 98 provides a way to distinguish between different intended uses of optional content. For example, many document design applications, such as CAD packages, offer layering features for collecting groups of graphics together and selectively hiding or viewing them for the convenience of the author. However, this layering may be different (at a finer granularity, for example) than would be useful to consumers of the document. Therefore, it is possible to specify different intents for optional content groups within a single document. A conforming reader may decide to use only groups that are of a specific intent.

Configuration dictionaries (see 8.11.4.3, "Optional Content Configuration Dictionaries") may also contain an Intent entry. If one or more of a group’s intents is contained in the current configuration’s set of intents, the group shall be used in determining visibility. If there is no match, the group shall have no effect on visibility.

If the configuration’s Intent is an empty array, no groups shall be used in determining visibility; therefore, all content shall be considered visible.

8.11.3 使图形内容可选

Making Graphical Content Optional

8.11.3.1 概述

General

PDF文件中的图形内容可以通过指定其属于某个可选内容组或可选内容成员字典来使其成为可选内容。有两种主要机制来定义成员资格:

  • 通过标记内容操作符分隔的内容流段可以成为可选内容,如8.11.3.2,“内容流中的可选内容”中所述。
  • 通过字典条目可以使表单和图像XObjects以及注释在其整体上成为可选内容,如8.11.3.3,“XObjects和注释中的可选内容”中所述。

当确定PDF文件中的某段可选内容应隐藏时,将发生以下情况:

  • 内容将不被绘制。
  • 图形状态操作,如设置颜色、变换矩阵和剪切,仍将被应用。此外,来自绘制操作的图形状态副作用也将被应用;特别是,即使文本包含在可选内容中,当前文本位置也将被更新。换句话说,标记内容段结束后的图形状态参数应与可选内容是否可见无关而保持一致。

隐藏可选内容段不应更改不属于同一可选内容组的对象的颜色。

  • 该规则也适用于设置非严格图形状态的操作符,例如BXEX
  • 被设为可选内容的对象(如表单XObjects和注释)可以完全跳过,因为它们的内容被封装,以致在处理其内容流之后不会对图形状态(或其他状态)产生持久影响。

符合标准的阅读器中的其他功能(如搜索和编辑)可能会受到选择性显示或隐藏内容能力的影响。符合标准的阅读器可以选择使用文档当前的可选内容组状态(以及相应的文档可见图形),或者提供自己的可选内容组状态来控制他们处理的图形。

NOTE 4

在执行光标跟踪和鼠标点击处理时,用于选择和移动注释的工具应遵守注释的当前屏幕可见性。然而,全文搜索引擎可能需要处理文档中的所有内容,无论其当前屏幕可见性如何。导出过滤器可能选择当前屏幕可见性、完整内容,或者向用户提供一组选项以控制可见性。

NOTE 5

不支持可选内容的非符合标准的阅读器(例如仅支持PDF 1.4功能的阅读器)将绘制和处理文档中的所有内容。

Graphical content in a PDF file may be made optional by specifying membership in an optional content group or optional content membership dictionary. Two primary mechanisms exist for defining membership:

  • Sections of content streams delimited by marked-content operators may be made optional, as described in 8.11.3.2, "Optional Content in Content Streams".
  • Form and image XObjects and annotations may be made optional in their entirety by means of a dictionary entry, as described in 8.11.3.3, "Optional Content in XObjects and Annotations".

When a piece of optional content in a PDF file is determined that it shall be hidden, the following occurs:

  • The content shall not be drawn.
  • Graphics state operations, such as setting the colour, transformation matrix, and clipping, shall still be applied. In addition, graphics state side effects that arise from drawing operators shall be applied; in particular, the current text position shall be updated even for text wrapped in optional content. In other words, graphics state parameters that persist past the end of a marked-content section shall be the same whether the optional content is visible or not.

Hiding a section of optional content shall not change the colour of objects that do not belong to the same optional content group.

  • This rule shall also apply to operators that set state that is not strictly graphics state; for example, BX and EX.
  • Objects such as form XObjects and annotations that have been made optional may be skipped entirely, because their contents are encapsulated such that no changes to the graphics state (or other state) persist beyond the processing of their content stream.

Other features in conforming readers, such as searching and editing, may be affected by the ability to selectively show or hide content. A conforming reader may choose whether to use the document’s current state of optional content groups (and, correspondingly, the document’s visible graphics) or to supply their own states of optional content groups to control the graphics they process.

NOTE 4

Tools to select and move annotations should honour the current on-screen visibility of annotations when performing cursor tracking and mouse-click processing. A full text search engine, however, may need to process all content in a document, regardless of its current visibility on-screen. Export filters might choose the current on-screen visibility, the full content, or present the user with a selection of OCGs to control visibility.

NOTE 5

A non-conforming reader that does not support optional content, such as one that only supports PDF 1.4 functionality, will draw and process all content in a document.

8.11.3.2 内容流中的可选内容

Optional Content in Content Streams

内容流中的内容段(包括页面的Contents流、表单或模式的内容流、Type 3字体的字形描述(由其CharProcs条目指定)或注释的外观)可以通过将它们包含在标记内容操作符BDCEMC之间来使其成为可选内容(见14.6,“标记内容”),标记内容标签为OC。此外,可以在页面的内容流中放置一个DP标记内容操作符,以便强制引用页面上的一个或多个可选内容组,即使页面当前在该层没有内容。

与标记内容关联的属性列表应指定可选内容组或可选内容成员字典中的一个,因为组应为间接对象且成员字典包含对间接对象的引用,属性列表应为当前资源字典的Properties子字典中列出的命名资源,如本小节中的示例1和示例2所示。

虽然标记内容标签应为OC,但其他应用标记内容的方式并不排除使用OC作为标签。只有当标签为OC且字典操作数为有效的可选内容组或可选内容成员字典时,标记内容才被认为是用于可选内容的。

NOTE 1

为避免与使用标记内容的其他功能(如逻辑结构,见14.7,“逻辑结构”)发生冲突,建议采取以下策略:

当内容既要用可选内容标记又要用其他标记进行标记时,应将可选内容标记嵌套在其他标记内容内。

当可选内容和其他标记会重叠但没有严格的包含关系时,应将可选内容分成两个或多个BDC/EMC段,必要时将可选内容段嵌套在其他段内。分割可选内容段不会破坏内容的可见性,而对标记内容的其他用途则不能保证同样的效果。

NOTE 2

任何嵌套在其他标记内容内的可选内容标记,如果外层级别的设置表明内容应隐藏,则内层无论其设置如何都将被隐藏。换句话说,如果外层的设置表明内容应隐藏,内层也将被隐藏。

在以下示例中,“Show Greeting”可选内容组的状态直接控制页面上文本字符串“Hello”的可见性。当组为ON时,文本可见;当组为OFF时,文本隐藏。

EXAMPLE 1

% 在内容流中
...
/OC /oc1 BDC                        % 可选内容如下
    BT
        /F1 1 Tf
        12 0 0 12 100 600 Tm
        (Hello) Tj
    ET
EMC                                 % 可选内容结束
...

<<                                    % 在资源字典中
    /Properties << /oc1 5 0 R >>      % 该字典将名称oc1映射到一个
...                                   % 可选内容组(对象5)
>>

5 0 obj                               % 控制文本可见性的OCG
    <<                                
        /Type /OCG
        /Name (Show Greeting)
    >>
    endobj

上述示例展示了一个与单个可选内容组关联的内容片段。还有其他可能性:

  • 多个内容段可以引用同一个组或成员字典,在这种情况下,这两个段的可见性始终相同。
  • 同样,尽管效率较低,不同的内容段可以有独立的成员字典,但具有相同的OCGsP条目。这样,内容段将具有相同的可见性行为。
  • 两个内容段可以属于引用相同组但具有不同P设置的成员字典。例如,如果一个段没有P条目,而另一个段有AllOffP条目,那么这两个内容段的可见性将相反。即,第一个段在第二个段隐藏时可见,反之亦然。

以下示例演示了可选内容组的直接使用和通过成员字典的间接使用。内容(一个黑色矩形框)如果由名为Image A或Image B的组控制的任一图像显示,则会被绘制。如果两个组都隐藏,矩形框也将被隐藏。

示例2

% 在内容流中
...
/OC /OC2 BDC                % 绘制一个黑色矩形框
    0g
    4w
    100 100 412 592 re s
EMC

/OC /OC3 BDC                % 绘制一个图像XObject
    q
    412 0 0 592 100 100 cm
    /Im3 Do
    Q
EMC
/OC /OC4 BDC                % 绘制一个图像XObject
    q
    412 0 0 592 100 100 cm
    /Im4 Do
    Q
EMC
...

<<                          % 资源字典
    /Properties << /OC2 20 0 R /OC3 30 0 R /OC4 40 0 R >>
    /XObject << /lm3 50 0 R /lm4 /60 0 R >>
>>

20 0 obj
<<                          % 可选内容成员字典
    /Type /OCMD
    /OCGs [30 0 R 40 0 R]
    /P /AnyOn
>>
endobj
30 0 obj                    % 可选内容组“Image A”
<<
    /Type /OCG
    /Name (Image A)
>>
endobj
40 0 obj                    % 可选内容组“Image B”
<<
    /Type /OCG
    /Name (Image B)
>>
endobj

在这个示例中,黑色矩形框的可见性由名为Image A和Image B的两个可选内容组控制。只要任一图像显示,该矩形框就会被绘制;如果两个图像都隐藏,矩形框也将被隐藏。

Sections of content in a content stream (including a page's Contents stream, a form or pattern’s content stream, glyph descriptions a Type 3 font as specified by its CharProcs entry, or an annotation’s appearance) may be made optional by enclosing them between the marked-content operators BDC and EMC (see 14.6, "Marked Content") with a marked-content tag of OC. In addition, a DP marked-content operator may be placed in a page’s content stream to force a reference to an optional content group or groups on the page, even when the page has no current content in that layer.

The property list associated with the marked content shall specify either an optional content group or optional content membership dictionary to which the content belongs. Because a group shall be an indirect object and a membership dictionary contains references to indirect objects, the property list shall be a named resource listed in the Properties subdictionary of the current resource dictionary (see 14.6.2, "Property Lists"), as shown in EXAMPLE 1 and EXAMPLE 2 in this sub-clause.

Although the marked-content tag shall be OC, other applications of marked content are not precluded from using OC as a tag. The marked content shall be considered to be for optional content only if the tag is OC and the dictionary operand is a valid optional content group or optional content membership dictionary.

NOTE 1

To avoid conflict with other features that used marked content (such as logical structure; see 14.7, "Logical Structure"), the following strategy is recommended:

Where content is to be tagged with optional content markers as well as other markers, the optional content markers should be nested inside the other marked content.

Where optional content and the other markers would overlap but there is not strict containment, the optional content should be broken up into two or more BDC/EMC sections, nesting the optional content sections inside the others as necessary. Breaking up optional content spans does not damage the nature of the visibility of the content, whereas the same guarantee cannot be made for all other uses of marked content.

NOTE 2

Any marked content tagged for optional content that is nested inside other marked content tagged for optional content is visible only if all the levels indicate visibility. In other words, if the settings that apply to the outer level indicate that the content should be hidden, the inner level is hidden regardless of its settings.

In the following example, the state of the Show Greeting optional content group directly controls the visibility of the text string “Hello” on the page. When the group is ON, the text shall be visible; when the group is OFF, the text shall be hidden.

EXAMPLE 1

% Within a content stream
...
/OC /oc1 BDC                        % Optional content follows
    BT
        /F1 1 Tf
        12 0 0 12 100 600 Tm
        (Hello) Tj
    ET
EMC                                 % End of optional content
...

<<                                    % In the resources dictionary
    /Properties << /oc1 5 0 R >>      % This dictionary maps the name oc1 to an
...                                   % optional content group (object 5)
>>

5 0 obj                               % The OCG controlling the visibility
    <<                                % of the text.
        /Type /OCG
        /Name (Show Greeting)
    >>
    endobj

The example above shows one piece of content associated with one optional content group. There are other possibilities:

  • More than one section of content may refer to the same group or membership dictionary, in which case the visibility of both sections is always the same.
  • Equivalently, although less space-efficient, different sections may have separate membership dictionaries with the same OCGs and P entries. The sections shall have identical visibility behaviour.
  • Two sections of content may belong to membership dictionaries that refer to the same group(s) but with different P settings. For example, if one section has no P entry, and the other has a P entry of AllOff, the visibility of the two sections of content shall be opposite. That is, the first section shall be visible when the second is hidden, and vice versa.

The following example demonstrates both the direct use of optional content groups and the indirect use of groups through a membership dictionary. The content (a black rectangle frame) is drawn if either of the images controlled by the groups named Image A or Image B is shown. If both groups are hidden, the rectangle frame shall be hidden.

EXAMPLE 2

% Within a content stream
...
/OC /OC2 BDC                % Draws a black rectangle frame
    0g
    4w
    100 100 412 592 re s
EMC

/OC /OC3 BDC                % Draws an image XObject
    q
    412 0 0 592 100 100 cm
    /Im3 Do
    Q
EMC
/OC /OC4 BDC                % Draws an image XObject
    q
    412 0 0 592 100 100 cm
    /Im4 Do
    Q
EMC
...

<<                          % The resource dictionary
    /Properties << /OC2 20 0 R /OC3 30 0 R /OC4 40 0 R >>
    /XObject << /lm3 50 0 R /lm4 /60 0 R >>
>>

20 0 obj
<<                          % Optional content membership dictionary
    /Type /OCMD
    /OCGs [30 0 R 40 0 R]
    /P /AnyOn
>>
endobj
30 0 obj                    % Optional content group “Image A”
<<
    /Type /OCG
    /Name (Image A)
>>
endobj
40 0 obj                    % Optional content group “Image B”
<<
    /Type /OCG
    /Name (Image B)
>>
endobj

8.11.3.3 XObjects 和注释中的可选内容

Optional Content in XObjects and Annotations

除了内容流中的标记内容外,表单XObject和图像XObject(见 8.8,"外部对象")以及注释(见 12.5,"注释")可能包含一个 OC 条目,它应该是一个可选内容组或可选内容成员资格字典。

表单或图像XObject的可见性应由组的状态或成员资格字典引用的组的状态,与其 P(或 VE)条目结合使用,并结合调用XObject时上下文中的当前可见状态(即,在执行 Do 操作的地方,内容流中的对象是否可见)来确定。

注释具有各种控制屏幕和打印可见性的标记(见 12.5.3,"注释标记")。如果注释包含一个 OC 条目,它只有在标记具有适当的设置,并且组或成员资格字典指示它应该可见时,才会在屏幕或打印中可见。

In addition to marked content within content streams, form XObjects and image XObjects (see 8.8, "External Objects") and annotations (see 12.5, "Annotations") may contain an OC entry, which shall be an optional content group or an optional content membership dictionary.

A form or image XObject's visibility shall be determined by the state of the group or those of the groups referenced by the membership dictionary in conjunction with its P (or VE) entry, along with the current visibility state in the context in which the XObject is invoked (that is, whether objects are visible in the contents stream at the place where the Do operation occurred).

Annotations have various flags controlling on-screen and print visibility (see 12.5.3, "Annotation Flags"). If an annotation contains an OC entry, it shall be visible for screen or print only if the flags have the appropriate settings and the group or membership dictionary indicates it shall be visible.

8.11.4 配置可选内容

Configuring Optional Content

8.11.4.1 概述

General

PDF文档中包含可选内容时,可以指定文档中可选内容组的默认状态,并指出将用于更改状态的外部因素。

NOTE

以下子条款描述了用于指定这些信息的PDF结构。

8.11.4.2,“可选内容属性字典”,描述了列出文档中所有可选内容组及其可能配置的结构。

8.11.4.3,“可选内容配置字典”,描述了指定文档中组的初始状态设置和其他信息的结构。

8.11.4.4,“使用和使用应用程序字典”和8.11.4.5,“确定可选内容组的状态”,描述了组的状态如何根据外部因素受到影响。

A PDF document containing optional content may specify the default states for the optional content groups in the document and indicate which external factors shall be used to alter the states.

NOTE

The following sub-clauses describe the PDF structures that are used to specify this information.

8.11.4.2, "Optional Content Properties Dictionary" describes the structure that lists all the optional content groups in the document and their possible configurations.

8.11.4.3, "Optional Content Configuration Dictionaries" describes the structures that specify initial state settings and other information about the groups in the document.

8.11.4.4, "Usage and Usage Application Dictionaries" and 8.11.4.5, "Determining the State of Optional Content Groups" describe how the states of groups can be affected based on external factors.

8.11.4.2 可选内容属性字典

Optional Content Properties Dictionary

文档目录中的可选 OCProperties 条目(见 7.7.2,"文档目录")在出现时,应包含 可选内容属性字典,该字典包含文档中所有可选内容组的列表,以及有关可选内容的默认和替代配置的信息。如果文件包含任何可选内容,则此字典必须存在;如果缺少此字典,符合规范的阅读器将忽略文档中的任何可选内容结构。

这个字典包含以下条目:

Table 100 – 可选内容属性字典中的条目
Key Type Value
OCGs array (必需) 对文档中所有可选内容组的间接引用数组(见 8.11.2,"可选内容组"),顺序任意。每个可选内容组都应包含在此数组中。
D dictionary (必需) 默认视图可选内容配置字典(见 8.11.4.3,"可选内容配置字典")。
Configs array (可选) 替代可选内容配置字典的数组(见 8.11.4.3,"可选内容配置字典")。

The optional OCProperties entry in the document catalog (see 7.7.2, "Document Catalog") shall contain, when present, the optional content properties dictionary, which contains a list of all the optional content groups in the document, as well as information about the default and alternate configurations for optional content. This dictionary shall be present if the file contains any optional content; if it is missing, a conforming reader shall ignore any optional content structures in the document.

This dictionary contains the following entries:

Table 100 – Entries in the Optional Content Properties Dictionary
Key Type Value
OCGs array (Required) An array of indirect references to all the optional content groups in the document (see 8.11.2, "Optional Content Groups"), in any order. Every optional content group shall be included in this array.
D dictionary (Required) The default viewing optional content configuration dictionary (see 8.11.4.3, "Optional Content Configuration Dictionaries").
Configs array (Optional) An array of alternate optional content configuration dictionaries (see 8.11.4.3, "Optional Content Configuration Dictionaries").

8.11.4.3 可选内容配置词典

Optional Content Configuration Dictionaries

可选内容属性字典中的 DConfigs 条目是配置字典,代表文档的可选内容组的不同呈现方式,供符合规范的阅读器使用。D 配置字典用于指定文档首次打开时可选内容组的初始状态。Configs 列出了在特定情况下可能使用的其他配置。配置字典中的条目显示在 表 101 中。

Table 101 – Entries in an Optional Content Configuration Dictionary
Key Type Value
Name text string (可选) 配置的名称,适合在用户界面中展示。
Creator text string (可选) 创建此配置字典的应用程序或功能的名称。
BaseState name (可选) 用于初始化应用此配置时文档中所有可选内容组的状态。此条目的值应为以下名称之一:
ON   所有组的状态将被设置为 ON。
OFF   所有组的状态将被设置为 OFF。
Unchanged   所有组的状态保持不变。
在此初始化之后,将处理 ONOFF 数组的内容,覆盖包含在数组中的组的状态。
默认值:ON
如果 BaseState 在文档的默认配置字典中存在,其值应为 ON
ON array (可选) 当应用此配置时,将状态设置为 ON 的可选内容组的数组。
如果 BaseState 条目是 ON,此条目是多余的。
OFF array (可选) 当应用此配置时,将状态设置为 OFF 的可选内容组的数组。
如果 BaseState 条目是 OFF,此条目是多余的。
Intent name or array (可选) 一个单一的意图名称或包含任意组合名称的数组。它用于确定在计算内容的可见性时应考虑哪些可选内容组的状态,以及应忽略哪些。
PDF 定义了两个意图名称,ViewDesign。此外,名称 All 表示包括尚未定义的所有意图的集合。默认值:View。文档的默认配置的值应为 View
AS array (可选) 使用应用字典的数组(见 表 103),指定哪些使用字典类别(见 表 102)应由符合规范的阅读器咨询,以根据外部因素(如当前系统语言或查看放大倍数)自动设置可选内容组的状态,以及何时应用它们。
Order array (可选) 指定在符合规范的阅读器的用户界面中呈现可选内容组的顺序的数组。数组元素可能包括以下对象:
可选内容组字典,其 Name 条目应由符合规范的阅读器在用户界面中展示。
可选内容组的数组,可能由符合规范的阅读器以树形或大纲结构展示。每个嵌套数组可以作为其第一个元素有一个文本字符串,用作符合规范的阅读器用户界面中的不可选标签。
嵌套数组中的文本标签用于呈现相关可选内容组的集合,而不是用于传达多层组中内容的实际嵌套(见 8.11.4.3 中的 EXAMPLE 1)。要反映内容的实际嵌套,例如具有子层的层,应使用没有文本标签的组的嵌套数组(见 8.11.4.3 中的 EXAMPLE 2)。
空数组 [] 明确指定不展示任何组。
在默认配置字典中,默认值应为一个空数组;在其他配置字典中,默认值为默认配置字典中的 Order 值。
此数组中未列出的任何组都不会在任何使用该配置的用户界面中展示。
ListMode name (可选) 指定在 Order 数组中应向用户展示哪些可选内容组的名称。有效值应为:
AllPages    展示 Order 数组中的所有组。
VisiblePages    仅展示 Order 数组中被一个或多个可见页面引用的组。
默认值:AllPages
RBGroups array (可选) 由一个或多个数组组成的数组,每个数组代表一组可选内容组,其状态应遵循单选按钮范式。也就是说,每个数组中最多有一个可选内容组的状态为 ON。如果一个组被设置为 ON,所有其他组将被设置为 OFF。但是,将一个组从 ON 切换到 OFF 并不会强制任何其他组变为 ON
空数组 [] 明确表示不存在这样的集合。
在默认配置字典中,默认值应为一个空数组;在其他配置字典中,默认值为默认配置字典中的 RBGroups 值。
Locked array (可选;PDF 1.6) 一个可选内容组的数组,当应用此配置时,这些组将被锁定。锁定组的状态不能通过符合规范的阅读器的用户界面更改。符合规范的编写器可以使用此条目来防止依赖这些组的内容的可见性被用户更改。
默认值:一个空数组。
符合规范的阅读器可以通过用户界面以外的方式允许更改可选内容组的状态,例如 JavaScript 或配置字典 AS 条目中的物品。

NOTE

此子条款中的 EXAMPLE 1 和 EXAMPLE 2 演示了如何使用 Order 条目来控制在用户界面中组的显示。

EXAMPLE 1

给定以下PDF对象:

1 0 obj <</Type /OCG /Name (Skin)>> endobj        % 可选内容组
2 0 obj <</Type /OCG /Name (Bones)>> endobj
3 0 obj <</Type /OCG /Name (Bark)>> endobj
4 0 obj <</Type /OCG /Name (Wood)>> endobj

5 0 obj                                            % 配置字典
    << /Order [[(Frog Anatomy) 1 0 R 2 0 R] [(Tree Anatomy 3 0 R 4 0 R] ] >>

一个符合规范的阅读器应该如下显示可选内容组:

Frog Anatomy
    Skin
    Bones
Plant Anatomy
    Bark
    Wood

EXAMPLE 2

给定以下PDF对象:

                            % 页面内容
/OC /L1 BDC                 % 图层 1
    /OC /L1a BDC            % 图层 1 的子图层 A
        0 0 100 100 re f
    EMC
    /OC /L1b BDC            % 图层 1 的子图层 B
        0 100 100 100 re f
    EMC
EMC
...
<< /L1 1 0 R               % 资源名称
/L1a 2 0 R
/L1b 3 0 R
>>
...                        % 可选内容组
1 0 obj <</Type /OCG /Name (Layer 1)>> endobj
2 0 obj <</Type /OCG /Name (Sublayer A)>> endobj
3 0 obj <</Type /OCG /Name (Sublayer B)>> endobj
...
4 0 obj                    % 配置字典
    << /Order [1 0 R [2 0 R 3 0 R]] >>

一个符合规范的阅读器应该如下显示 OCGs:

Layer 1
    Sublayer A
    Sublayer B

请注意,BDC 代表 "Begin Marked Content",EMC 代表 "End Marked Content",它们是PDF中用于标记内容的命令。这里的 "/OC" 指的是 "Optional Content",即可选内容。

AS 条目是一个 自动状态 数组,由一个或多个 使用应用程序字典 组成,这些字典指定了符合规范的阅读器如何根据外部因素自动设置可选内容组的状态,这将在以下子条款中讨论。

The D and Configs entries in Table 100 are configuration dictionaries, which represent different presentations of a document’s optional content groups for use by conforming readers. The D configuration dictionary shall be used to specify the initial state of the optional content groups when a document is first opened. Configs lists other configurations that may be used under particular circumstances. The entries in a configuration dictionary are shown in Table 101.

Table 101 – Entries in an Optional Content Configuration Dictionary
Key Type Value
Name text string (Optional) A name for the configuration, suitable for presentation in a user interface.
Creator text string (Optional) Name of the application or feature that created this configuration dictionary.
BaseState name (Optional) Used to initialize the states of all the optional content groups in a document when this configuration is applied. The value of this entry shall be one of the following names:
ON   The states of all groups shall be turned ON.
OFF   The states of all groups shall be turned OFF.
Unchanged   The states of all groups shall be left unchanged.
After this initialization, the contents of the ON and OFF arrays shall be processed, overriding the state of the groups included in the arrays.
Default value: ON.
If BaseState is present in the document’s default configuration dictionary, its value shall be ON.
ON array (Optional) An array of optional content groups whose state shall be set to ON when this configuration is applied.
If the BaseState entry is ON, this entry is redundant.
OFF array (Optional) An array of optional content groups whose state shall be set to OFF when this configuration is applied.
If the BaseState entry is OFF, this entry is redundant.
Intent name or array (Optional) A single intent name or an array containing any combination of names. it shall be used to determine which optional content groups’ states to consider and which to ignore in calculating the visibility of content (see 8.11.2.3, "Intent").
PDF defines two intent names, View and Design. In addition, the name All shall indicate the set of all intents, including those not yet defined. Default value: View. The value shall be View for the document’s default configuration.
AS array (Optional) An array of usage application dictionaries (see Table 103) specifying which usage dictionary categories (see Table 102) shall be consulted by conforming readers to automatically set the states of optional content groups based on external factors, such as the current system language or viewing magnification, and when they shall be applied.
Order array (Optional) An array specifying the order for presentation of optional content groups in a conforming reader’s user interface. The array elements may include the following objects:
Optional content group dictionaries, whose Name entry shall be displayed in the user interface by the conforming reader.
Arrays of optional content groups which may be displayed by a conforming reader in a tree or outline structure. Each nested array may optionally have as its first element a text string to be used as a non-selectable label in a conforming reader’s user interface.
Text labels in nested arrays shall be used to present collections of related optional content groups, and not to communicate actual nesting of content inside multiple layers of groups (see EXAMPLE 1 in 8.11.4.3, "Optional Content Configuration Dictionaries"). To reflect actual nesting of groups in the content, such as for layers with sublayers, nested arrays of groups without a text label shall be used (see EXAMPLE 2 in 8.11.4.3, "Optional Content Configuration Dictionaries").
An empty array [] explicitly specifies that no groups shall be presented.
In the default configuration dictionary, the default value shall be an empty array; in other configuration dictionaries, the default shall be the Order value from the default configuration dictionary.
Any groups not listed in this array shall not be presented in any user interface that uses the configuration.
ListMode name (Optional) A name specifying which optional content groups in the Order array shall be displayed to the user. Valid values shall be:
AllPages    Display all groups in the Order array.
VisiblePages    Display only those groups in the Order array that are referenced by one or more visible pages.
Default value: AllPages.
RBGroups array (Optional) An array consisting of one or more arrays, each of which represents a collection of optional content groups whose states shall be intended to follow a radio button paradigm. That is, the state of at most one optional content group in each array shall be ON at a time. If one group is turned ON, all others shall be turned OFF. However, turning a group from ON to OFF does not force any other group to be turned ON.
An empty array [] explicitly indicates that no such collections exist.
In the default configuration dictionary, the default value shall be an empty array; in other configuration dictionaries, the default is the RBGroups value from the default configuration dictionary.
Locked array (Optional; PDF 1.6) An array of optional content groups that shall be locked when this configuration is applied. The state of a locked group cannot be changed through the user interface of a conforming reader. Conforming writers can use this entry to prevent the visibility of content that depends on these groups from being changed by users.
Default value: an empty array.
A conforming reader may allow the states of optional content groups from being changed by means other than the user interface, such as JavaScript or items in the AS entry of a configuration dictionary.

NOTE

EXAMPLE 1 and EXAMPLE 2 in this sub-clause illustrate the use of the Order entry to control the display of groups in a user interface.

EXAMPLE 1

Given the following PDF objects:

1 0 obj <</Type /OCG /Name (Skin)>> endobj        % Optional content groups
2 0 obj <</Type /OCG /Name (Bones)>> endobj
3 0 obj <</Type /OCG /Name (Bark)>> endobj
4 0 obj <</Type /OCG /Name (Wood)>> endobj

5 0 obj                                            % Configuration dictionary
    << /Order [[(Frog Anatomy) 1 0 R 2 0 R] [(Tree Anatomy 3 0 R 4 0 R] ] >>

A conforming reader should display the optional content groups as follows:

Frog Anatomy
    Skin
    Bones
Tree Anatomy
    Bark
    Wood

EXAMPLE 2

Given the following PDF objects:

                           % Page contents
/OC /L1 BDC                % Layer 1
    /OC /L1a BDC               % Sublayer A of layer 1
        0 0 100 100 re f
    EMC
    /OC /L1b BDC               % Sublayer B of layer 1
        0 100 100 100 re f
    EMC
EMC
...
<< /L1 1 0 R               % Resource names
/L1a 2 0 R
/L1b 3 0 R
>>
...                        %Optional content groups
1 0 obj <</Type /OCG /Name (Layer 1)>> endobj
2 0 obj <</Type /OCG /Name (Sublayer A)>> endobj
3 0 obj <</Type /OCG /Name (Sublayer B)>> endobj
...
4 0 obj                    % Configuration dictionary
    << /Order [1 0 R [2 0 R 3 0 R]] >>

A conforming reader should display the OCGs as follows:

Layer 1
    Sublayer A
    Sublayer B

The AS entry is an auto state array consisting of one or more usage application dictionaries that specify how conforming readers shall automatically set the state of optional content groups based on external factors, as discussed in the following sub-clause.

8.11.4.4 用法和用法应用词典

Usage and Usage Application Dictionaries

可选内容组通常构建用于以某种方式控制图形对象的可见性。对象可以以多种方式相关;例如,一个组可能包含特定语言的内容或适合在特定放大倍数下查看的内容。

可选内容组的使用字典(可选内容组字典中 Usage 条目的值;见 表 98)应包含描述由组控制内容性质的信息。该字典可以包含 表 102 中显示的任何条目组合。

Table 102 – 可选内容使用字典
Key Type Value
CreatorInfo dictionary (可选) 创建应用程序用于存储与此可选内容组相关的应用程序特定数据的字典。必须包含两个必需条目:
Creator    指定创建该组的应用程序的文本字符串。
Subtype    定义组控制的内容类型的名称。建议值包括但不限于 Artwork(用于图形设计或出版应用程序)和 Technical(用于技术设计如建筑图纸或原理图)。
可以包含其他条目以呈现与创建应用程序或相关应用程序相关的信息。
具有 Design 意图的组通常包含 CreatorInfo 条目。
Language dictionary (可选) 指定由此可选内容组控制的内容语言的字典。可以包含以下两个条目:
Lang    (必需) 指定语言及可能的地区(参见 14.9.2, "自然语言规范")的文本字符串。例如,es-MX 代表墨西哥西班牙语。
Preferred    (可选) 一个名称,其值应为 ONOFF。默认值:OFF。当系统语言与所有使用字典中的语言字符串之间存在部分匹配但没有完全匹配时,应由符合要求的阅读器使用此值。有关更多信息,请参见 8.11.4.4, "使用和使用应用字典"。
Export dictionary (可选) 包含一个条目的字典,ExportState,其值应为 ONOFF。此值应指示在符合要求的阅读器将文档(或其部分)保存为不支持可选内容的格式(例如,栅格图像格式)时,该组中内容的推荐状态。
Zoom dictionary (可选) 指定在最佳查看时的缩放范围的字典。应包含以下一个或两个条目:
min    指定组应为 ON 的最小推荐缩放因子。默认值:0。
max    指定组应为 ON 的最大缩放因子。默认值:无限大。
Print dictionary (可选) 指定该组中的内容应在打印时使用的字典。可以包含以下可选条目:
Subtype 指定组控制的内容类型的名称对象;例如,TrappingPrintersMarksWatermark
PrintState 一个名称,其值应为 ONOFF,指示该组在从符合要求的阅读器打印文档时应设置为该状态。
View dictionary (可选) 一个字典,应包含一个条目 ViewState,该条目的值应为 ONOFF,指示在符合要求的阅读器中打开文档时,该组应设置为该状态。
User dictionary (可选) 指定一个或多个主要面向该可选内容组的用户的字典。每个字典应包含两个必需条目:
Type    一个名称对象,值应为 Ind(个人)、Ttl(职称)或 Org(组织)。
Name    一个文本字符串或文本字符串数组,表示个人、职位或组织的名称。
PageElement dictionary (可选) 声明该组包含分页伪影的字典。应包含一个条目 Subtype,其值应为 HF(页眉/页脚)、FG(前景图像或图形)、BG(背景图像或图形)或 L(徽标)。

在可选内容使用字典中的数据除了供文档用户查看外,还可以被符合标准的阅读器用来根据外部因素(如当前系统语言设置或缩放级别)自动调整可选内容组的状态。文档作者可以使用 使用应用字典 来指定哪些使用字典中的条目应被查阅,以便根据这些因素自动设置可选内容组的状态。使用应用字典应列在可选内容配置字典的 AS 条目中(参见 表 101)。如果没有 AS 条目,则状态不会根据使用信息自动调整。

使用应用字典指定了符合标准的阅读器应如何根据使用条目自动操作可选内容组的状态、哪些组将受到影响,以及在什么情况下。 表 103 显示了使用应用字典中的条目。

使用应用字典应仅由交互式符合标准的阅读器使用,不应由将 PDF 作为最终输出形式的应用程序使用(有关更多信息,请参见 8.11.4.5,"确定可选内容组的状态")。

表 103 – 使用应用字典中的条目
Key Type Value
Event name (必需) 定义使用此使用应用字典的情况的名称。应为 ViewPrintExport 之一。
OCGs array (可选) 列出应根据其使用字典中的信息自动管理状态的可选内容组的数组(参见 8.11.4.4,“使用和使用应用字典”)。默认值:空数组,表示没有组将受到影响。
Category array (必需) 名称数组,每个名称对应于使用字典条目(参见 表 102)。在管理 OCGs 数组中的可选内容组的状态时,应考虑组的使用字典中的每个相应类别。

Event 条目指定使用设置应在查看、打印或导出文档时应用。OCGs 条目指定应应用使用设置的可选内容组集合。对于 OCGs 中的每个组,应检查其使用字典中的条目(参见 表 102),这些条目由 Category 指定,以得出组的推荐状态。如果所有条目都推荐状态为 ON,则组的状态应设置为 ON;否则,状态应设置为 OFF

使用字典中的条目使用方法如下:

  • View: 状态应为 ViewState 条目的值。此条目允许文档包含仅在交互式查看文档时相关的内容,例如如何与文档互动的说明。
  • Print: 状态应为 PrintState 条目的值。如果 PrintState 不存在,则应保持可选内容组的状态不变。
  • Export: 状态应为 ExportState 条目的值。
  • Zoom: 如果文档的当前缩放级别大于或等于 min 且小于 max,则使用 ON 状态;否则,使用 OFF 状态。
  • User: Name 条目应指定一个或多个名称,以与用户的身份匹配。Type 条目确定 Name 条目的解释方式(个人、职称或组织)。如果存在完全匹配,则使用 ON 状态;否则使用 OFF 状态。
  • Language: 此类别应允许基于应用程序的语言和地区选择内容。如果在使用应用字典的 OCGs 列表中的可选内容组的 Lang 条目中找到完全匹配,则所有具有完全匹配的组应接收 ON 推荐。如果未找到完全匹配,但找到部分匹配(即语言匹配但地区不匹配),则所有部分匹配的组中 Preferred 条目值为 ON 的组应接收 ON 推荐。所有其他组应接收 OFF 推荐。

对于具有相同 Event 值的多个条目没有限制,以允许具有不兼容的使用应用字典的文档合并为更大的文档,并保持其行为不变。如果一个可选内容组出现在多个 OCGs 数组中,则其状态应为 ON 仅当所有使用应用字典中所有类别的状态都为 ON 时。

EXAMPLE

以下示例展示了如何使用带有使用应用字典的自动状态数组。默认配置字典中的 AS 条目是一个包含三个使用应用字典的数组,分别用于 ViewPrintExport 事件类型。

/OCProperties                                      % 文档目录中的 OCProperties 字典
    << /OCGs [1 0 R 2 0 R 3 0 R 4 0 R]
        /D << /BaseState /OFF                      % 默认配置
                /ON [1 0 R]
                /AS [                                % 使用应用字典的自动状态数组
                    << /Event /View /Category [/Zoom] /OCGs [1 0 R 2 0 R 3 0 R 4 0 R] >>
                    << /Event /Print /Category [/Print] /OCGs [4 0 R] >>
                    << /Event /Export /Category [/Export] /OCGs [3 0 R 4 0 R] >>
                    ]
            >>
    >>
...

1 0 obj
    << /Type /OCG
        /Name (20000 foot view)
        /Usage << /Zoom << /max 1.0 >> >>
    >>
endobj
2 0 obj
    << /Type /OCG
    /Name (10000 foot view)
    /Usage << /Zoom << /min 1.0 /max 2.0 >> >>
>>
endobj
3 0 obj
    << /Type /OCG
        /Name (1000 foot view)
        /Usage << /Zoom << /min 2.0 /max 20.0 >>
                    /Export << /ExportState /OFF >> >>
        >>
endobj
4 0 obj
    << /Type /OCG
        /Name (Copyright notice)
        /Usage << /Print << /PrintState /ON >>
                    /Export << /ExportState /ON>> >>
    >>
endobj

在这个示例中,事件类型为 View 的使用应用字典指定所有可选内容组的状态应基于缩放级别进行管理。当查看文档时,三个组(对象 1、2 和 3)包含 Zoom 使用信息。对象 4 没有任何使用信息,因此它不会受到缩放级别变化的影响。对象 3 在导出时会收到 OFF 推荐。在打印或导出时,对象 4 会收到 ON 推荐。

Optional content groups are typically constructed to control the visibility of graphic objects that are related in some way. Objects can be related in several ways; for example, a group may contain content in a particular language or content suitable for viewing at a particular magnification.

An optional content group’s usage dictionary (the value of the Usage entry in an optional content group dictionary; see Table 98) shall contain information describing the nature of the content controlled by the group. This dictionary can contain any combination of the entries shown in Table 102.

Table 102 – Entries in an Optional Content Usage Dictionary
Key Type Value
CreatorInfo dictionary (Optional) A dictionary used by the creating application to store application-specific data associated with this optional content group. It shall contain two required entries:
Creator    A text string specifying the application that created the group.
Subtype    A name defining the type of content controlled by the group. Suggested values include but shall not be limited to Artwork, for graphic-design or publishing applications, and Technical, for technical designs such as building plans or schematics.
Additional entries may be included to present information relevant to the creating application or related applications.
Groups whose Intent entry contains Design typically include a CreatorInfo entry.
Language dictionary (Optional) A dictionary specifying the language of the content controlled by this optional content group. It may contain the following two entries:
Lang   (required) A text string that specifies a language and possibly a locale (see 14.9.2, "Natural Language Specification"). For example, es-MX represents Mexican Spanish. Preferred   (optional) A name whose values shall be either ON or OFF. Default value: OFF. it shall be used by conforming readers when there is a partial match but no exact match between the system language and the language strings in all usage dictionaries. See 8.11.4.4, "Usage and Usage Application Dictionaries" for more information.
Export dictionary (Optional) A dictionary containing one entry, ExportState, a name whose value shall be either ON or OFF. This value shall indicate the recommended state for content in this group when the document (or part of it) is saved by a conforming reader to a format that does not support optional content (for example, a raster image format).
Zoom dictionary (Optional) A dictionary specifying a range of magnifications at which the content in this optional content group is best viewed. It shall contain one or both of the following entries:
min   The minimum recommended magnification factor at which the group shall be ON. Default value: 0.
max   The magnification factor below which the group shall be ON. Default value: infinity.
Print dictionary (Optional) A dictionary specifying that the content in this group is shall be used when printing. It may contain the following optional entries:
Subtype A name object specifying the kind of content controlled by the group; for example, Trapping, PrintersMarks and Watermark.
PrintState A name that shall be either ON or OFF, indicating that the group shall be set to that state when the document is printed from a conforming reader.
View dictionary (Optional) A dictionary that shall have a single entry, ViewState, a name that shall have a value of either ON or OFF, indicating that the group shall be set to that state when the document is opened in a conforming reader.
User dictionary (Optional) A dictionary specifying one or more users for whom this optional、 content group is primarily intended. Each dictionary shall have two、 required entries: Type    A name object that shall be either Ind (individual), Ttl (title), or Org (organization). Name    A text string or array of text strings representing the name(s) of the individual, position or organization.
PageElement dictionary (Optional) A dictionary declaring that the group contains a pagination artifact. It shall contain one entry, Subtype, whose value shall be a name that is either HF (header/footer), FG (foreground image or graphic), BG (background image or graphic), or L (logo).

While the data in the usage dictionary serves as information for a document user to examine, it may also be used by conforming readers to automatically manipulate the state of optional content groups based on external factors such as current system language settings or zoom level. Document authors may use usage application dictionaries to specify which entries in the usage dictionary shall be consulted to automatically set the state of optional content groups based on such factors. Usage application dictionaries shall be listed in the AS entry in an optional content configuration dictionary (see Table 101). If no AS entry is present, states shall not be automatically adjusted based on usage information.

A usage application dictionary specifies the rules for which usage entries shall be used by conforming readers to automatically manipulate the state of optional content groups, which groups shall be affected, and under which circumstances. Table 103 shows the entries in a usage application dictionary.

Usage application dictionaries shall only be used by interactive conforming readers, and shall not be used by applications that use PDF as final form output (see 8.11.4.5, "Determining the State of Optional Content Groups" for more information).

Table 103 – Entries in a Usage Application Dictionary
Key Type Value
Event name (Required) A name defining the situation in which this usage application dictionary should be used. Shall be one of View, Print, or Export.
OCGs array (Optional) An array listing the optional content groups that shall have their states automatically managed based on information in their usage dictionary (see 8.11.4.4, "Usage and Usage Application Dictionaries"). Default value: an empty array, indicating that no groups shall be affected.
Category array (Required) An array of names, each of which corresponds to a usage dictionary entry (see Table 102). When managing the states of the optional content groups in the OCGs array, each of the corresponding categories in the group’s usage dictionary shall be considered.

The Event entry specifies whether the usage settings shall be applied during viewing, printing, or exporting the document. The OCGs entry specifies the set of optional content groups to which usage settings shall be applied. For each of the groups in OCGs, the entries in its usage dictionary (see Table 102) specified by Category shall be examined to yield a recommended state for the group. If all the entries yield a recommended state of ON, the group’s state shall be set to ON; otherwise, its state shall be set to OFF.

The entries in the usage dictionary shall be used as follows:

  • View: The state shall be the value of the ViewState entry. This entry allows a document to contain content that is relevant only when the document is viewed interactively, such as instructions for how to interact with the document.
  • Print: The state shall be the value of the PrintState entry. If PrintState is not present, the state of the optional content group shall be left unchanged.
  • Export: The state shall be the value of the ExportState entry.
  • Zoom: If the current magnification level of the document is greater than or equal to min and less than max the ON state shall be used; otherwise, OFF shall be used.
  • User: The Name entry shall specify a name or names to match with the user’s identification. The Type entry determines how the Name entry shall be interpreted (name, title, or organization). If there is an exact match, the ON state shall be used; otherwise OFF shall be used.
  • Language: This category shall allow the selection of content based on the language and locale of the application. If an exact match to the language and locale is found among the Lang entries of the optional content groups in the usage application dictionary’s OCGs list, all groups that have exact matches shall receive an ON recommendation. If no exact match is found, but a partial match is found (that is, the language matches but not the locale), all partially matching groups that have Preferred entries with a value of ON shall receive an ON recommendation. All other groups shall receive an OFF recommendation.

There shall be no restriction on multiple entries with the same value of Event, in order to allow documents with incompatible usage application dictionaries to be combined into larger documents and have their behaviour preserved. If a given optional content group appears in more than one OCGs array, its state shall be ON only if all categories in all the usage application dictionaries it appears in shall have a state of ON.

EXAMPLE

This example shows the use of an auto state array with usage application dictionaries. The AS entry in the default configuration dictionary is an array of three usage application dictionaries, one for each of the Event values View, Print, and Export.

/OCProperties                                      % OCProperties dictionary in document catalog
    << /OCGs [1 0 R 2 0 R 3 0 R 4 0 R]
        /D << /BaseState /OFF                      % The default configuration
              /ON [1 0 R]
              /AS [                                % Auto state array of usage application dictionaries
                  << /Event /View /Category [/Zoom] /OCGs [1 0 R 2 0 R 3 0 R 4 0 R] >>
                  << /Event /Print /Category [/Print] /OCGs [4 0 R] >>
                  << /Event /Export /Category [/Export] /OCGs [3 0 R 4 0 R] >>
                  ]
           >>
    >>
...

1 0 obj
    << /Type /OCG
       /Name (20000 foot view)
       /Usage << /Zoom << /max 1.0 >> >>
    >>
endobj
2 0 obj
    << /Type /OCG
    /Name (10000 foot view)
    /Usage << /Zoom << /min 1.0 /max 2.0 >> >>
>>
endobj
3 0 obj
    << /Type /OCG
       /Name (1000 foot view)
       /Usage << /Zoom << /min 2.0 /max 20.0 >>
                 /Export << /ExportState /OFF >> >>
        >>
endobj
4 0 obj
    << /Type /OCG
       /Name (Copyright notice)
       /Usage << /Print << /PrintState /ON >>
                 /Export << /ExportState /ON>> >>
    >>
endobj

In the example, the usage application dictionary with event type View specifies that all optional content groups shall have their states managed based on zoom level when viewing. Three groups (objects 1, 2, and 3) contain Zoom usage information. Object 4 has none; therefore, it shall not be affected by zoom level changes. Object 3 shall receive an OFF recommendation when exporting. When printing or exporting, object 4 shall receive an ON recommendation.

8.11.4.5 确定可选内容组的状态

Determining the State of Optional Content Groups

本子条款总结了符合要求的阅读器如何利用配置字典和使用应用字典来设置可选内容组的状态。为了讨论的方便,以下几类符合要求的阅读器可以区分为:

  • 观众应用程序:允许用户以各种方式与文档进行交互。
  • 设计应用程序:提供分层功能以将图形组聚集在一起,并选择性地隐藏或查看它们。

NOTE 1

以下规则不适用于设计应用程序;这些应用程序可以选择以完全不同的方式管理它们的状态。

  • 聚合应用程序:将 PDF 文件作为图形导入。
  • 打印应用程序:打印 PDF 文件。

当文档首次打开时,其可选内容组的状态应基于 OCProperties 字典中的 D(默认)配置字典进行分配:

a) 应将 BaseState 的值应用于所有组。

b) 列在 ONOFF 数组中的组(取决于哪个数组与 BaseState 相反)应调整其状态。

这种状态将是打印和聚合应用程序使用的状态。这些应用程序不应根据以下描述的使用应用字典应用更改。然而,为了更高级的功能,它们可以提供用户控制以手动调整个别可选内容组的状态。

NOTE 2

观众应用程序还可以提供选项让用户以这种状态查看文档(即禁用下面讨论的自动调整)。该选项允许准确预览文档在被放置到聚合应用程序或发送到独立打印系统时的内容。

以下讨论仅适用于观众应用程序。这些应用程序应检查 AS 数组中具有 View 事件类型的使用应用字典。对于找到的每个字典,应按 8.11.4.4 节 "使用与使用应用字典" 中描述的方式调整其 OCGs 数组中的组。

随后,文档已准备好供用户进行交互式查看。每当有依赖于 View 事件类型的使用应用字典的因素发生变化(如缩放级别),应重新应用相应的字典。

用户可以手动调整可选内容组的状态或通过触发 SetOCGState 操作(参见 12.6.4.12 节 "Set-OCG-State 操作")来进行调整,例如点击链接或书签。手动更改将覆盖自动设置的状态。这些组的状态保持被覆盖,并且在文档打开期间(或直到用户将文档恢复到其原始状态之前),不会根据 View 事件类型的使用应用字典进行重新调整。

当文档由观众应用程序打印时,将应用 Print 事件类型的使用应用字典覆盖当前的可选内容组状态。这些更改仅在打印操作期间有效;之后所有组将恢复到先前的状态。

类似地,当文档导出到不支持可选内容的格式时,将应用 Export 事件类型的使用应用字典覆盖当前的可选内容组状态。更改仅在导出操作期间有效;之后所有组将恢复到先前的状态。

NOTE 3

尽管 PrintExport 事件类型有名称相同的使用类别,但相应的使用应用字典可以指定应用其他类别。

This sub-clause summarizes the rules by which conforming readers make use of the configuration and usage application dictionaries to set the state of optional content groups. For purposes of this discussion, it is useful to distinguish the following types of conforming readers:

  • Viewer applications which allow users to interact with the document in various ways.
  • Design applications, which offer layering features for collecting groups of graphics together and selectively hiding or viewing them.

NOTE 1

The following rules are not meant to apply to design applications; they may manage their states in an entirely different manner if they choose.

  • Aggregating applications, which import PDF files as graphics.
  • Printing applications, which print PDF files.

When a document is first opened, its optional content groups shall be assigned a state based on the D (default) configuration dictionary in the OCProperties dictionary:

a) The value of BaseState shall be applied to all the groups.

b) The groups listed in either the ON or OFF array (depending on which one is opposite to BaseState) shall have their states adjusted.

This state shall be the state used by printing and aggregating application. Such applications shall not apply the changes based on usage application dictionaries described below. However, for more advanced functionality, they may provide user control for manipulating the individual states of optional content groups.

NOTE 2

Viewer applications may also provide users with an option to view documents in this state (that is, to disable the automatic adjustments discussed below). This option permits an accurate preview of the content as it will appear when placed into an aggregating application or sent to a stand-alone printing system.

The remaining discussion in this sub-clause applies only to viewer applications. Such applications shall examine the AS array for usage application dictionaries that have an Event of type View. For each one found, the groups listed in its OCGs array shall be adjusted as described in 8.11.4.4, "Usage and Usage Application Dictionaries".

Subsequently, the document is ready for interactive viewing by a user. Whenever there is a change to a factor that the usage application dictionaries with event type View depend on (such as zoom level), the corresponding dictionaries shall be reapplied.

The user may manipulate optional content group states manually or by triggering SetOCGState actions (see 12.6.4.12, "Set-OCG-State Actions") by, for example, clicking links or bookmarks. Manual changes shall override the states that were set automatically. The states of these groups remain overridden and shall not be readjusted based on usage application dictionaries with event type View as long as the document is open (or until the user reverts the document to its original state).

When a document is printed by a viewer application, usage application dictionaries with an event type Print shall be applied over the current states of optional content groups. These changes shall persist only for the duration of the print operation; then all groups shall revert to their prior states.

Similarly, when a document is exported to a format that does not support optional content, usage application dictionaries with an event type Export shall be applied over the current states of optional content groups. Changes shall persist only for the duration of the export operation; then all groups shall revert to their prior states.

NOTE 3

Although the event types Print and Export have identically named counterparts that are usage categories, the corresponding usage application dictionaries are permitted to specify that other categories may be applied.