跳转至

12.10 文件要求

12.10 Document Requirements

12.10.1 概述

12.10.1 General

从 PDF 1.7 开始,文档可以指定符合规范的阅读器必须具备的要求,以确保文档能够正确运行。文档目录(参见 7.7.2,“文档目录”)中的 Requirements 条目应指定一个需求字典数组,其条目如 表 264 所示。

表 264 – 所有需求字典共有的条目
键(Key) 类型(Type) 值(Value)
Type name (可选)此字典描述的 PDF 对象类型。如果存在,则对于需求字典,该值应为 Requirement
S name (必需)该字典描述的需求类型。其值应为 EnableJavaScripts
RH array (可选)一个需求处理器字典数组(参见 表 265)。如果符合规范的阅读器能够检查 S 条目指定的需求,则此数组列出的需求处理器应被禁用(不执行)。

RH 条目确保了该特性的向后兼容性。一些 PDF 文档包含用于验证某些需求符合性的 JavaScript 代码片段,这些 JavaScript 代码片段称为需求处理器(requirement handlers)。为了保持向后兼容性,必须确保要么由符合规范的阅读器检查需求,要么由 JavaScript 代码检查需求,但不能同时进行。

当 PDF 文档首次打开时,文档中的所有 JavaScript 代码片段(包括需求处理器)都应被执行。如果符合规范的阅读器能够解析需求字典,则应禁用 RH 条目中列出的需求处理器的执行。如果需求处理器是 JavaScript 代码,则符合规范的阅读器应使用 Names 字典(7.7.4,“名称字典”)查找该代码片段。

在 PDF 1.7 中,唯一定义的需求类型是 EnableJavaScripts。该需求表示文档需要在符合规范的阅读器中启用 JavaScript 执行。如果文档包含 EnableJavaScripts 需求,交互式符合规范的阅读器可以允许用户选择保持 JavaScript 执行禁用,或者暂时启用 JavaScript 以充分利用文档的功能。

如果 EnableJavaScripts 需求存在于需求字典中,则包含一个 RH 条目(指定 JavaScript 代码片段)将毫无意义。编写一个 JavaScript 代码片段来检查 JavaScript 是否启用,无法实现所需的目标。因此,在 PDF 1.7 中不得使用 RH 条目。

Beginning with PDF 1.7, a document may specify requirements that shall be present in a conforming reader in order for the document to function properly. The Requirements entry in the document catalogue (see 7.7.2, “Document Catalog”) shall specify an array of requirement dictionaries, whose entries are shown in Table 264.

Table 264 – Entries common to all requirement dictionaries
Key Type Value
Type name (Optional) The type of PDF object that this dictionary describes. If present, shall be Requirement for a requirement dictionary.
S name (Required) The type of requirement that this dictionary describes. The value shall be EnableJavaScripts.
RH array (Optional) An array of requirement handler dictionaries (see Table 265). This array lists the requirement handlers that shall be disabled (not executed) if the conforming reader can check the requirement specified in the S entry.

The RH entry ensures backward-capability for this feature. Some PDF documents include JavaScript segments that verify compliance with certain requirements. Such JavaScript segments are called requirement handlers. Backward-compatibility shall be achieved by ensuring that either the conforming reader checks the requirement or the JavaScript segment checks the requirement, but not both.

When a PDF document is first opened, all JavaScript segments in the document shall be executed, including the requirement handlers. If the conforming reader understands the requirement dictionary, it shall disable execution of the requirement handlers named by the RH entry. If the requirement handler is in JavaScript, the conforming reader shall look up the segment using the Names dictionary (7.7.4, “Name Dictionary”).

In PDF 1.7, the only defined requirement type shall be EnableJavaScripts. This requirement indicates that the document requires JavaScript execution to be enabled in the conforming reader. If the EnableJavaScripts requirement is present, an interactive conforming reader may allow the user to choose between keeping JavaScript execution disabled or temporarily enabling it to benefit from the full function of the document.

If the EnableJavaScripts requirement is present in a requirement dictionary, the inclusion of the RH entry that specifies a JavaScript segment would be pointless. Writing a JavaScript segment to verify that JavaScript is enabled would not achieve the desired goal. The RH entry shall not be used in PDF 1.7.

12.10.2 需求处理者

12.10.2 Requirement Handlers

需求处理器(requirement handler)是用于验证某些需求是否满足的程序。表 265 描述了需求处理器字典中的条目。

表 265 – 需求处理器字典中的条目
键(Key) 类型(Type) 值(Value)
Type name (可选)此字典描述的 PDF 对象类型。如果存在,则对于需求处理器字典,该值应为 ReqHandler
S name (必需)该字典描述的需求处理器类型。有效的需求处理器类型应为 JS(用于 JavaScript 需求处理器)和 NoOp
NoOp 允许旧版符合规范的阅读器忽略无法识别的需求。此值不会向需求处理器字典添加任何特定条目。
Script text string (可选;仅当 S 条目的值为 JS 时有效)存储在文档名称字典(参见 7.7.4,“名称字典”)中的文档级 JavaScript 操作的名称。如果符合规范的阅读器能够解析其父需求字典并验证该字典指定的需求,则应禁用本字典中标识的需求处理器的执行。

A requirement handler is a program that verifies certain requirements are satisfied. Table 265 describes the entries in a requirement handler dictionary.

Table 265 – Entries in a requirement handler dictionary
Key Type Value
Type name (Optional) The type of PDF object that this dictionary describes. If present, shall be ReqHandler for a requirement handler dictionary.
S name (Required) The type of requirement handler that this dictionary describes. Valid requirement handler types shall be JS (for a JavaScript requirement handlers) and NoOp. A value of NoOp allows older conforming readers to ignore unrecognized requirements. This value does not add any specific entry to the requirement handler dictionary.
Script text string (Optional; valid only if the S entry has a value of JS) The name of a document-level JavaScript action stored in the document name dictionary (see 7.7.4, “Name Dictionary”). If the conforming reader understands the parent requirement dictionary and can verify the requirement specified in that dictionary, it shall disable execution of the requirement handler identified in this dictionary.