跳转至

附录 C(规范性)实现限制

Annex C (normative) Implementation Limits

C.1 概述

C.1 General

通常,PDF 不会限制文件格式中描述的内容的大小或数量,例如数字、数组、图像等。然而,运行在特定处理器和特定操作环境中的符合规范的阅读器确实存在此类限制。如果符合规范的阅读器遇到超出这些限制的 PDF 结构,或执行的计算的中间结果超出限制,则会发生错误。

注意

PostScript 解释器也有实现限制,列在《PostScript 语言参考第三版》的附录 B 中。有可能构造一个不违反 PDF 实现限制但无法在 PostScript 打印机上打印的 PDF 文件。请记住,这些限制根据 PostScript LanguageLevel、解释器版本和解释器可用内存量的不同而有所不同。

本附录描述了符合规范的 PDF 应用程序(阅读器和写入器)的典型限制。这些限制主要分为两类:

  • 架构限制。符合规范的阅读器运行的硬件会施加某些约束。例如,整数通常以 32 位表示,限制了允许的整数范围。此外,软件的设计也会施加其他约束,例如数组或字符串中元素数量的限制。
  • 内存限制。符合规范的阅读器可用的内存量限制了可以同时保存的消耗内存的对象的数量。

In general, PDF does not restrict the size or quantity of things described in the file format, such as numbers, arrays, images, and so on. However, a conforming reader running on a particular processor and in a particular operating environment does have such limits. If a conforming reader encounters a PDF construct that exceeds one of these limits or performs a computation whose intermediate results exceed a limit, an error occurs.

NOTE

PostScript interpreters also have implementation limits, listed in Appendix B of the PostScript Language Reference, Third Edition. It is possible to construct a PDF file that does not violate PDF implementation limits but fails to print on a PostScript printer. Keep in mind that these limits vary according to the PostScript LanguageLevel, interpreter version, and the amount of memory available to the interpreter.

This annex describes typical limits for a conforming PDF application (readers and writers). These limits fall into two main classes:

  • Architectural limits. The hardware on which a conforming reader executes imposes certain constraints. For example, an integer is usually represented in 32 bits, limiting the range of allowed integers. In addition, the design of the software imposes other constraints, such as a limit to the number of elements in an array or string.
  • Memory limits. The amount of memory available to a conforming reader limits the number of memory- consuming objects that can be held simultaneously.

C.2 架构限制

C.2 Architectural limits

PDF本身有一个架构限制:由于交叉引用表(见7.5.4,“交叉引用表”)分配十个数字来表示字节偏移量,因此文件大小应限制为\(10^{10}\)字节(约10吉字节)。在使用交叉引用流(见7.5.8,“交叉引用流”)而不是交叉引用表的PDF文件中,此限制不适用。

表C.1描述了在32位机器上运行的兼容阅读器应适应的最小架构限制。由于兼容阅读器可能会受到这些限制的影响,生成PDF文件的兼容写入器应保持在这些限制之内。

注意

在达到架构限制(如间接对象数量的限制)之前,内存限制往往会被超出。

表C.1 – 架构限制
数量 限制 描述
整数 2,147,483,647 最大整数值;等于\(2^{31} − 1\)
-2,147,483,648 最小整数值;等于\(−2^{31}\)
实数 \(± 3.403 × 10^{38}\) 最大和最小实数值(近似值)。
\(± 1.175 × 10^{-38}\) 最接近0的非零实数值(近似值)。比这些值更接近0的值将自动转换为0。
5 小数部分的有效十进制数字精度(近似值)。
字符串(在内容流中) 32,767 字符串的最大长度,以字节为单位。
此限制仅适用于内容流中的字符串。PDF文件中的其他字符串没有有效限制。
名称 127 名称的最大长度,以字节为单位。
间接对象 8,388,607 PDF文件中间接对象的最大数量。
q/Q 嵌套 28 注意   qQ 操作符的图形状态嵌套的最大深度。这本身并不是一个限制,而是因为在生成PostScript输出时,qQ 是通过PostScript gsavegrestore 操作符实现的。
DeviceN 组件 32 DeviceN 颜色空间中的颜色剂或色调组分的最大数量。
CID 65,535 字符标识符(CID)的最大值。

此外,兼容写入器应遵守以下约束条件,兼容阅读器应能处理符合这些约束条件的PDF文件。

  • 缩略图图像的大小不应超过106×106个样本,并且对于8.5×11英寸和A4尺寸的页面,应按八分之一比例创建。
  • 默认用户空间中的最小页面大小应为3×3个单位;最大应为14,400×14,400个单位。在PDF 1.6之前的版本中,默认用户空间单位的大小固定为1/72英寸,产生的最小尺寸约为0.04×0.04英寸,最大尺寸为200×200英寸。从PDF 1.6开始,单位大小可以逐页设置;默认值仍为1/72英寸。
  • 视图的放大倍数应限制在大约8%到6400%之间。
  • 当兼容阅读器读取具有损坏或缺失交叉引用表的PDF文件时,它可能会尝试通过扫描文件中的所有对象来重建该表。然而,如果交叉引用表丢失或严重损坏,删除条目的生成号将会丢失。为了便于这种重建,对象标识符、endobj 关键字和endstream关键字应出现在一行的开头。此外,流中的数据不应包含以endstream 开头的行,除了用于界定流结束的必需的endstream

PDF itself has one architectural limit: Because a cross-reference table (see 7.5.4, "Cross-Reference Table") allocates ten digits to represent byte offsets, the size of a file shall be limited to \(10^{10}\) bytes (approximately 10 gigabytes). This limit does not apply in a PDF file that uses a cross-reference stream (see 7.5.8, "Cross- Reference Streams") instead of a cross reference table.

Table C.1 describes the minimum architectural limits that should be accommodated by conforming readers running on 32-bit machines. Because conforming readers may be subject to these limits, conforming writers producing PDF files should remain within them.

NOTE

Memory limits are often exceeded before architectural limits (such as the limit on the number of indirect objects) are reached.

Table C.1 – Architectural limits
Quantity Limit Description
integer 2,147,483,647 Largest integer value; equal to \(2^{31} − 1\).
-2,147,483,648 Smallest integer value; equal to \(−2^{31}\).
real \(± 3.403 × 10^{38}\) Largest and smallest real values (approximate).
\(± 1.175 × 10^{-38}\) Nonzero real values closest to 0 (approximate). Values closer than these are automatically converted to 0.
5 Number of significant decimal digits of precision in fractional part (approximate).
string (in content stream) 32,767 Maximum length of a string, in bytes.
This restriction applies only to strings in content streams. There is no effective restriction on other strings in PDF files.
name 127 Maximum length of a name, in bytes.
indirect object 8,388,607 Maximum number of indirect objects in a PDF file.
q/Q nesting 28 NOTE   Maximum depth of graphics state nesting by q and Q operators. This is not a limit as such, but arises from the fact that q and Q are implemented by the PostScript gsave and grestore operators when generating PostScript output.
DeviceN components 32 Maximum number of colorants or tint components in a DeviceN colour space.
CID 65,535 Maximum value of a CID (character identifier).

Additionally, conforming writers should adhere to the following constraints, and conforming readers should accommodate PDF files that obey the constraints.

  • Thumbnail images should be no larger than 106 by 106 samples, and should be created at one-eighth scale for 8.5-by-11-inch and A4-size pages.
  • The minimum page size should be 3 by 3 units in default user space; the maximum should be 14,400 by 14,400 units. In versions of PDF earlier than 1.6, the size of the default user space unit was fixed at 1 ⁄ 72 inch, yielding a minimum of approximately 0.04 by 0.04 inch and a maximum of 200 by 200 inches. Beginning with PDF 1.6, the size of the unit may be set on a page-by-page basis; the default remains at 1/ 72 inch.
  • The magnification factor of a view should be constrained to be between approximately 8 percent and 6400 percent.
  • When a conforming reader reads a PDF file with a damaged or missing cross-reference table, it may attempt to rebuild the table by scanning all the objects in the file. However, the generation numbers of deleted entries are lost if the cross-reference table is missing or severely damaged. To facilitate such reconstruction, object identifiers, the endobj keyword, and the endstream keyword should appear at the start of a line. Also, the data within a stream should not contain a line beginning with the word endstream, aside from the required endstream that delimits the end of the stream.

C.3 内存限制

C.3 Memory limits

内存限制不像架构限制那样能够精确描述,因为可用内存的数量及其分配方式因不同的兼容产品而异。

注意

必要时,内存会自动从一个用途重新分配到另一个用途:当某个特定用途需要更多内存时,如果分配给另一个用途的内存当前未被使用或其使用是非必要的(例如缓存),则可以从中获取内存。此外,当内存有限时,数据通常会保存到临时文件中。由于这种行为,无法针对文档中的页面数量、页面上的文本注释或超文本链接数量、页面上的图形对象数量,或者文档中的字体数量等项声明限制 。

Memory limits cannot be characterized as precisely as architectural limits because the amount of available memory and the ways in which it is allocated vary from one conforming product to another.

NOTE

Memory is automatically reallocated from one use to another when necessary: when more memory is needed for a particular purpose, it can be taken from memory allocated to another purpose if that memory is currently unused or its use is nonessential (a cache, for example). Also, data is often saved to a temporary file when memory is limited. Because of this behaviour, it is not possible to state limits for such items as the number of pages in a document, number of text annotations or hypertext links on a page, number of graphics objects on a page, or number of fonts on a page or in a document.