跳转至

8.8 外部对象

External Objects

8.8.1 概述

General

外部对象(通常称为 XObject)是一种图形对象,其内容由一个自包含的流定义,与其使用的内容流分开。有三种类型的外部对象:

  • 图像 XObject(见 8.9.5,“图像字典”)表示采样的视觉图像,例如照片。
  • 表单 XObject(见 8.10,“表单 XObject”)是任意图形对象序列的自包含描述。
  • PostScript XObject(见 8.8.2,“PostScript XObject”)包含用 PostScript 页面描述语言表达的代码片段。不应使用 PostScript XObject。

另外还有两类外部对象,组 XObject引用 XObject(均为 PDF 1.4),实际上是具有附加属性的特定类型的表单 XObject。更多信息请参见 8.10.3,“组 XObject”和 8.10.4,“引用 XObject”。

任何 XObject 都可以通过 Do 操作符作为另一个内容流的一部分进行绘制(见表 87)。该操作符适用于任何类型的 XObject——图像、表单或 PostScript。语法在所有情况下都是相同的,尽管操作符的行为细节根据类型有所不同。

表 87 – XObject 操作符
操作数 操作符 描述
name Do 绘制指定的 XObject。操作数名称应作为当前资源字典的 XObject 子字典中的键出现(见 7.8.3,“资源字典”)。相关的值应为一个流,其 Type 条目(如果存在)为 XObjectDo 的效果取决于 XObject 的 Subtype 条目值,它可以是 Image(见 8.9.5,“图像字典”)、Form(见 8.10,“表单 XObject”)或 PS(见 8.8.2,“PostScript XObject”)。

An external object (commonly called an XObject) is a graphics object whose contents are defined by a self-contained stream, separate from the content stream in which it is used. There are three types of external objects:

  • An image XObject (8.9.5, "Image Dictionaries") represents a sampled visual image such as a photograph.
  • A form XObject (8.10, "Form XObjects") is a self-contained description of an arbitrary sequence of graphics objects.
  • A PostScript XObject (8.8.2, "PostScript XObjects") contains a fragment of code expressed in the PostScript page description language. PostScript XObjects should not be used.

Two further categories of external objects, group XObjects and reference XObjects (both PDF 1.4), are actually specialized types of form XObjects with additional properties. See 8.10.3, "Group XObjects" and 8.10.4, "Reference XObjects" for additional information.

Any XObject can be painted as part of another content stream by means of the Do operator (see Table 87). This operator applies to any type of XObject—image, form, or PostScript. The syntax is the same in all cases, although details of the operator’s behaviour differ depending on the type.

Table 87 – XObject Operator
Operands Operator Description
name Do Paint the specified XObject. The operand name shall appear as a key in the XObject subdictionary of the current resource dictionary (see 7.8.3, "Resource Dictionaries"). The associated value shall be a stream whose Type entry, if present, is XObject. The effect of Do depends on the value of the XObject’s Subtype entry, which may be Image (see 8.9.5, "Image Dictionaries"), Form (see 8.10, "Form XObjects"), or PS (see 8.8.2, "PostScript XObjects").

8.8.2 PostScript X对象

PostScript XObjects

从 PDF 1.1 开始,内容流中可以包含 PostScript 语言片段。这些片段只能在打印到 PostScript 输出设备时使用;在屏幕上查看文档或打印到非 PostScript 设备时,它们不会产生任何效果。此外,合规的阅读器可能无法解释这些 PostScript 片段。因此,这种功能应该非常谨慎地使用,并且仅在没有其他方式可以实现相同结果时使用。不适当使用 PostScript XObject 会导致 PDF 文件打印错误。

一个 PostScript XObject 是一个其 Subtype 条目值为 PS 的 XObject 流。PostScript XObject 字典除了通常所有流共有的条目(见 表 5)外,还可能包含 表 88 中显示的条目。

表 88 – 特定于 PostScript XObject 字典的附加条目
类型
Type 名称 (可选) 此字典描述的 PDF 对象类型;如果存在,对于 PostScript XObject 应为 XObject
Subtype 名称 (必需) 此字典描述的 XObject 类型;对于 PostScript XObject,应为 PS
或者,此条目的值可以是 Form,并带有一个附加的 Subtype2 条目,其值应为 PS
Level1 (可选) 一个流,其内容应在目标 PostScript 解释器已知仅支持 LanguageLevel 1 时代替 PostScript XObject 的流。

如果合规阅读器将 PDF 内容流翻译成 PostScript 语言,任何引用 PostScript XObject 的 Do 操作可以替换为 XObject 流本身的内容。流应在未经解释的情况下被复制。PostScript 片段可以使用当前资源字典 Font 子字典中列出的 Type 1 和 TrueType 字体(见 7.8.3,“资源字典”),并使用 PostScript findfont 操作符通过其 BaseFont 名称访问它们。该片段不应使用 Font 子字典中列出的其他类型的字体。它不应引用与 PDF 程序集对应的 PostScript 定义(见 14.2,“程序集”),这些定义可能会改变。

Beginning with PDF 1.1, a content stream may include PostScript language fragments. These fragments may be used only when printing to a PostScript output device; they shall have no effect either when viewing the document on-screen or when printing it to a non-PostScript device. In addition, conforming readers may not be able to interpret the PostScript fragments. Hence, this capability should be used with extreme caution and only if there is no other way to achieve the same result. Inappropriate use of PostScript XObjects can cause PDF files to print incorrectly.

A PostScript XObject is an XObject stream whose Subtype entry has the value PS. A PostScript XObject dictionary may contain the entries shown in Table 88 in addition to the usual entries common to all streams (see Table 5).

Table 88 – Additional Entries Specific to a PostScript XObject Dictionary
Key Type Value
Type name (Optional) The type of PDF object that this dictionary describes; if present, shall be XObject for a PostScript XObject.
Subtype name (Required) The type of XObject that this dictionary describes; shall be PS for a PostScript XObject.
Alternatively, the value of this entry may be Form, with an additional Subtype2 entry whose value shall be PS.
Level1 stream (Optional) A stream whose contents shall be used in place of the PostScript XObject’s stream when the target PostScript interpreter is known to support only LanguageLevel 1.

If a PDF content stream is translated by a conforming reader into the PostScript language, any Do operation that references a PostScript XObject may be replaced by the contents of the XObject stream itself. The stream shall be copied without interpretation. The PostScript fragment may use Type 1 and TrueType fonts listed in the Font subdictionary of the current resource dictionary (see 7.8.3, "Resource Dictionaries"), accessing them by their BaseFont names using the PostScript findfont operator. The fragment shall not use other types of fonts listed in the Font subdictionary. It should not reference the PostScript definitions corresponding to PDF procedure sets (see 14.2, "Procedure Sets"), which are subject to change.