13.5 替代演示¶
13.5 Alternate Presentations
从 PDF 1.4 开始,PDF 文档应包含备用呈现(Alternate Presentations),它们指定了文档可能被查看的不同方式。文档的名称字典(name dictionary)(参见 表 31)中的可选 AlternatePresentations 条目(PDF 1.4)包含一个名称树(name tree),该名称树将名称字符串映射到文档可用的备用呈现方式。
注意 1
由于符合标准的阅读器不要求支持备用呈现,因此包含备用呈现的文档的作者应确保文件能够以某种有用且有意义的方式显示和打印。例如,如果文档包含一组照片的幻灯片演示,则这些照片应该能够以静态形式查看,以便无法播放幻灯片的阅读器仍然可以显示这些照片。
从 PDF 1.5 开始,唯一的备用呈现类型是 幻灯片放映(slideshow)。幻灯片放映可以通过 JavaScript 动作(参见 12.6.4.16,“JavaScript 动作”)触发,并由用户在交互式表单元素上执行的操作启动(参见 12.7,“交互式表单”)。
下表列出了幻灯片字典中的条目。
键(Key) | 类型(Type) | 值(Value) |
---|---|---|
Type | name | (必需;PDF 1.4) 此字典描述的 PDF 对象类型;对于幻灯片字典,该值应为 SlideShow。 |
Subtype | name | (必需;PDF 1.4) 此字典描述的 PDF 对象的子类型;对于幻灯片字典,该值应为 Embedded。 |
Resources | 名称树(name tree) | (必需;PDF 1.4) 一个名称树,将名称字符串映射到备用呈现引用的对象。 注意 尽管 PDF 视名称树中的字符串为不具有特定编码的字符串,但幻灯片放映应将它们解释为 UTF-8 编码的 Unicode。 |
StartResource | 字节字符串(byte string) | (必需;PDF 1.4) 一个字节字符串,应与 Resources 条目中的某个字符串匹配。它应定义幻灯片放映的根对象。 |
注意 2
Resources 名称树对幻灯片放映而言表示一个虚拟文件系统。它将字符串(“文件名”)与 PDF 对象关联起来,这些对象代表幻灯片放映所使用的资源。例如,一个根流(root stream)可能会引用一个文件名,该文件名将在 Resources 名称树中查找,并加载相应的对象作为文件。(此虚拟文件系统是扁平的,即无法引用子文件夹。)
注意 3
通常,图像存储在文档中,作为图像 XObject(参见 8.9.5,“图像字典”),这样它们就可以在标准 PDF 表示和幻灯片放映之间共享。其他媒体对象存储为嵌入式文件流(embedded file streams)(参见 7.11.4,“嵌入式文件流”)。
为了使符合标准的阅读器能够根据其支持的功能验证内容,所有引用的对象都应在其字典中包含 Type 条目,即使在通常情况下 Type 条目是可选的。
示例
下面的示例演示了如何使用备用呈现幻灯片放映。
1 0 obj
<</Type /Catalog
/Pages 2 0 R
/Names 3 0 R % 间接引用名称字典
>>
...
3 0 obj % 名称字典
<</AlternatePresentations 4 0 R >>
endobj
4 0 obj % 备用呈现名称树
<</Names [(MySlideShow) 5 0 R]>>
endobj
5 0 obj % 幻灯片放映定义
<</Type /SlideShow
/Subtype /Embedded
/Resources <</Names [ (mysvg.svg) 31 0R
(abc0001.jpg) 35 0 R (abc0002.jpg) 36 0 R
(mysvg.js) 61 0 R (mymusic.mp3) 65 0 R ]>>
/StartResource (mysvg.svg)
>>
...
31 0 obj
<</Type /Filespec % 根对象
/F (mysvg.svg) % 指向嵌入式文件流
/EF <</F 32 0 R>>
>>
endobj
32 0 obj % 嵌入式文件流
<</Type /EmbeddedFile
/Subtype /image#2Fsvg+xml
/Length 72
>>
stream
<?xml version="1.0" standalone="no"?>
<svg><!-- 这里是一些 SVG 代码 --></svg>
endstream
endobj
% ... 其他对象未显示
Beginning with PDF 1.4, a PDF document shall contain alternate presentations, which specify alternate ways in which the document may be viewed. The optional AlternatePresentations entry (PDF 1.4) in a document’s name dictionary (see Table 31) contains a name tree that maps name strings to the alternate presentations available for the document.
NOTE 1
Since conforming readers are not required to support alternate presentations, authors of documents containing alternate presentations should define the files such that something useful and meaningful can be displayed and printed. For example, if the document contains an alternate presentation slideshow of a sequence of photographs, the photographs should be viewable in a static form by viewers that are not capable of playing the slideshow.
As of PDF 1.5, the only type of alternate presentation is a slideshow. Slideshows may be invoked by means of JavaScript actions (see 12.6.4.16, “JavaScript Actions”) initiated by user action on an interactive form element (see 12.7, “Interactive Forms”).
The following table shows the entries in a slideshow dictionary.
Key | Type | Value |
---|---|---|
Type | name | (Required; PDF 1.4) The type of PDF object that this dictionary describes; shall be SlideShow for a slideshow dictionary. |
Subtype | name | (Required; PDF 1.4) The subtype of the PDF object that this dictionary describes; shall be Embedded for a slideshow dictionary. |
Resources | name tree | (Required; PDF 1.4) A name tree that maps name strings to objects referenced by the alternate presentation. NOTE Even though PDF treats the strings in the name tree as strings without a specified encoding, the slideshow shall interpret them as UTF-8 encoded Unicode. |
StartResource | byte string | (Required; PDF 1.4) A byte string that shall match one of the strings in the Resources entry. It shall define the root object for the slideshow presentation. |
NOTE 2
The Resources name tree represents a virtual file system to the slideshow. It associates strings (“file names”) with PDF objects that represent resources used by the slideshow. For example, a root stream may reference a file name, which would be looked up in the Resources name tree, and the corresponding object would be loaded as the file. (This virtual file system is flat; that is, there is no way to reference subfolders.)
NOTE 3
Typically, images are stored in the document as image XObjects (see 8.9.5, “Image Dictionaries”), thereby allowing them to be shared between the standard PDF representation and the slideshow. Other media objects are stored or embedded file streams (see 7.11.4, “Embedded File Streams”).
To allow conforming readers to verify content against their own supported features all referenced objects shall include a Type entry in their dictionary, even when the Type entry is normally optional for a given object.
EXAMPLE
The following example illustrates the use of alternate presentation slideshows.
1 0 obj
<</Type /Catalog
/Pages 2 0 R
/Names 3 0 R % Indirect reference to name dictionary
>>
...
3 0 obj % The name dictionary
<</AlternatePresentations 4 0 R >>
endobj
4 0 obj % The alternate presentations name tree
<</Names [(MySlideShow) 5 0 R]>>
endobj
5 0 obj % The slideshow definition
<</Type /SlideShow
/Subtype /Embedded
/Resources <</Names [ (mysvg.svg) 31 0R
(abc0001.jpg) 35 0 R (abc0002.jpg) 36 0 R
(mysvg.js) 61 0 R (mymusic.mp3) 65 0 R ]>>
/StartResource (mysvg.svg)
>>
...
31 0 obj
<</Type /Filespec % The root object, which
/F (mysvg.svg) % points to an embedded file stream
/EF <</F 32 0 R>>
>>
endobj
32 0 obj % The embedded file stream
<</Type /EmbeddedFile
/Subtype /image#2Fsvg+xml
/Length 72
>>
stream
<?xml version="1.0" standalone="no"?>
<svg><!-- Some SVG goes here--></svg>
endstream
endobj
% ... other objects not shown