# The media9 Package, v1.25

Alexander Grahn

[https://gitlab.com/agrahn/media9](https://gitlab.com/agrahn/media9)

4th August 2022

###### Abstract

A HEX package for embedding interactive Adobe Flash (SWF) and 3D files (Adobe U3D & PRC) as well as video and sound files or streams (FLV, MP4/H.246, MP3) into PDF documents with Adobe Reader-9/X compatibility.

_Keywords_: embed flash movie LaTeX pdf 3d include sound swf mp3 video mp4 h.264 aac slideshow image gallery flv audio multimedia streamed media rtmp YouTube animation JavaScript pdfLaTeX dvips ps2pdf divpdfmx XeLaTeX u3d prc Adobe Reader Foxit RichMedia annotation LuaLaTeX

###### Contents

* 1 Introduction
* 2 Requirements
* 3 Installation
* 4 Using the package
* 5 The user interface
	* 5.1 Media inclusion
	* 5.2 Command options
	* 5.3 Control buttons
* 6 Embedding Flash, video and sound, image slide-shows (with examples)
* 7 Embedding 3D objects (with examples)
	* 7.1 Introduction
	* 7.2 3D quick-start guide
* 8 Caveats
* 9 AcknowledgementsIntroduction

This package provides an interface to embed, in the first place, interactive Flash (SWF) and 3D objects (Adobe U3D & PRC) into PDF documents. Video and audio files or streams in the popular MP4, FLV and MP3 formats can be embedded as well. However, a media player Flash component is required for playback, as will be explained shortly. Playback of multimedia files uses Adobe Flash Player, which was bundled with Adobe Reader 9 and 10 versions. Unfortunately, beginning with Adobe Reader 11, it must be installed as a separate plug-in.

Among the supported media types, video and sound files require an additional Flash (SWF) application for playback, which must be either embedded into the PDF or loaded at runtime from the internet. There are numerous such players, both open-source and commercial, available on the internet. One of them is the highly configurable open-source 'StrobeMediaPlayback.swf' [1], maintained by Adobe and hosted on SourceForge.net. Package'media9' comes with an enhanced version of 'StrobeMediaPlayback.swf'. In addition, two simple players for video and audio, 'VPlayer.swf' and 'APlayer.swf' are included, which can be used instead. They provide sufficient functionality for playing embedded files and streamed media.

There is yet another player bundled with'media9'. It is a simple image gallery viewer called 'SlideShow.swf' which can display collections of embedded and remote images in the PNG, JPEG and GIF file formats. Remote images are downloaded at viewing time and can be configured to be refreshed at definite time intervals.

Flash Player supports the efficient H.264 codec for video compression. MP4/H.264 video files can be encoded from existing video files and from numbered bitmap sequences using the ffmpeg ([http://ffmpeg.org](http://ffmpeg.org)) or avconv ([http://libav.org](http://libav.org)) command line tools (Libav is a fork from the FFmpeg code). In order to allow for precise seeking within video files it is necessary to encode them with a sufficient number of key frames. The command line for recoding an existing video file video.avi into video.mp4 reads (one line; ffmpeg can be substituted with avconv)

 ffmpeg -i video.avi -vf scale="trunc(iw/2)*2:trunc(ih/2)*2"  -c:v libx264 -profile:v high -pix_fmt yuv420p  -g 30 -r 30 video.mp4

From a sequence frame-0.png, frame-1.png,... of bitmap files, an MP4 video is produced by

 ffmpeg -i frame-%d.png -vf scale="trunc(iw/2)*2:trunc(ih/2)*2"  -c:v libx264 -profile:v high -pix_fmt yuv420p  -g 30 -r 30 video.mp4

Both examples insert a key frame (option '-g') at every second since the frame rate is set to 30 fps. The video encoder requires even pixel numbers in both dimensions which is ensured by adding '-vf scale="..." to the option list.

_Note:_'media9' package replaces the now obsolete'movie15' package.'media9' is based on the RichMedia Annotation (Annotations are the interactive elements in a document, in PDF specification parlance.), an Adobe addition to the PDF specification [2], while'movie15' uses the old multimedia framework ('Screen Annotation') of pre-9 Readers which depends on third-party plug-ins and which does not support recent media file formats.

Package'media9' supports the usual PDF making workflows, i. e. pdffix, Lua&FX, LaTeX\(\rightarrow\) dvips\(\rightarrow\) ps2pdf/Distiller and (Xa)TeX\(\rightarrow\) (x)dvipdfmx.

The final PDF can be viewed in current Adobe Readers on MS Windows and other platforms. On Unix platforms including Linux, however, support of Flash, video and sound was discontinued at Reader version 9.4.2, probably for security reasons. PDF documents which target Adobe Reader 9.4.1 for Linux should use 'VPlayer9.swf' and 'APlayer9.swf' (also included in the'media9' package). These media player components are compatible with the older Flash Player 9 plugin that is bundled with the Reader for Linux. Recent versions of Foxit PDF Reader, which is available on the Windows platform, are known to render embedded Flash, video and audio content. Foxit also uses Adobe Flash Player plugin. On tablets and phones running Android or iOS, ezPDF Reader was reported to play video and sound files embedded with'media9'.

## 2 Requirements

Iskernel (I&FX package), version \(\geq\) 2022 - 07 - 15

pdfTeX, version \(\geq\) 1.40

Ghostscript, version \(\geq\) 9.15, or Adobe Distiller for PS to PDF conversion

dvipdfmx, version \(\geq\) 20190503 for DVI to PDF conversion

Adobe Reader, version \(\geq\) 9, but not greater than 9.4.1 on Linux; Foxit Reader (Flash, video, audio)

Adobe Flash Player plugin for Firefox

## 3 Installation

MiKTeX and TeXLive users should run the package manager for installation and updates.

Otherwise, a manual installation into the _local_ TeX-Directory-Structure (TDS) root directory is done along the following steps:

1. Download the TDS compliant package file'media9.tds.zip' from CTAN.
2. Find the local TDS root directory by running

kpsewhich -var-value TEXMFLOCAL

on the command line. The local TDS root directory is intended for packages that are not maintained by the TeXLive package manager.
3. Unzip'media9.tds.zip' into the local TDS root directory previously found. Depending on the location of this directory, you may need to be logged in as Root/Administrator.
4. After installation, update the filename database by running 'texhash' on the command line. Again, Root/Administrator privileges may be required.

For updating the package, repeat the steps given above.

## 4 Using the package

Invoke the package by putting the line

\usepackage[<package options>]{media9}

to the preamble of your document, i. e. somewhere between \documentclass and \begin{document}.

'media9' honours the package options:

dvipdfmx

xetex

bigfiles

draft

final

playbutton=...

noplaybutton

activate=...

deactivate=...

windowed=...

transparent

passcontext

attachfiles

3Dplaytype=...

3Dplaycount=...

3Dplayspeed=...

3Dtoolbar

3Dnavpane

3Dpartsattrs=...

3Dmenu

3Dbg=...

3Dlights=...

3Drender=...

Except for 'dvipdfmx', 'xetex' and 'bigfiles', the options above are also available (among others) as command options and will be explained shortly. However, if used as package options they have global scope, taking effect on all embedded media in the document. In turn, command options locally override global settings. Options without an argument are boolean options and can be negated by appending '=false'.

XajuX will be auto-detected. Therefore package option 'xetex' is optional. However, in the case of dvipdfmx, package option 'dvipdfmx' is mandatory because it cannot be auto-detected.

If PDF is generated via DVI and Postscript by the command sequence latex \dvis \dvis \dvis \dvis option '-Ppdf' should _not_ be set when converting the intermediate DVI into Postscript. If you cannot do without, put '-D 1200' _after_ '-Ppdf' on the command line. Users of LaTeX-aware text editors with menu-driven toolchain invocation, such as TeXnicCenter, should check the configuration of the dvips call.

Option 'bigfiles' is only relevant for the latex \dvis \dvis \dvis2pdf workflow. It may be needed if large media files cause latex to abort with error 'TeX capacity exceeded'. See Sect. 8.

The user interface

Package'media9' provides commands for media inclusion (\includemedia) and insertion of media control buttons (\mediabutton). The latter is introduced in Sect. 5.3.

### Media inclusion

\includemedia[<options>]{<poster text>}{  <main Flash (SWF) file or URL | 3D (PRC, U3D) file>} The last argument, <main Flash (SWF) file or URL | 3D (PRC, U3D) file>, is the main interactive application to be inserted into the PDF. In the case of Flash, this can be a local SWF file, or a URL, such as a YouTube video player. A local file will become part of the final PDF file, while Flash content from a URL requires an internet connection when the user activates it in Adobe Reader. A URL must be fully qualified, i. e., starting with either 'http[s]://' or 'ftp://'. As for 3D content, Adobe Reader only supports U3D or PRC files embedded in the PDF; they cannot be loaded or streamed during runtime. The most frequent use of \includemedia will likely be embedding video or sound files for playback in Adobe Reader. For this we need some media player, which is an SWF file we embed as our main application. It will be configured to load, upon activation, a particular video or sound file that was embedded as a resource into the PDF or is to be streamed from the internet. This will be shown later. Note that a local file (main application or resource) will only once be physically embedded in order to keep the final PDF file size small. If the same file (identified by MD5 checksum) appears in other \includemedia commands, only a reference will be inserted that points to the same storage location in the PDF.

Argument <poster text> defines the size of the rectangular region of the document page in which the media will be displayed. Moreover, <poster text> will be shown in case the media has not been activated. <poster text> can be anything that LaTeX can typeset, such as an \includegraphics command serving as a poster image, a PGF/TikZ/PSTricks inline graphics or just ordinary text. Alternatively, <poster text> can be left blank in which case the size of the media rectangle should be set with options 'width' and 'height'. If a non-zero size <poster text> was provided, it can be resized using any combination of options 'width', 'height' or 'totalheight', 'keepaspectratio' and'scale'.

A list of directories where TeX searches for media and resource files can be set-up by means of

\addmediapath{<directory>} This command appends one directory at a time to the search list. To specify more directories, just use it repeatedly. The path separator is always '/', independent from the operating system.

The following section explains all command options provided. They are passed to the media inclusion command as a comma separated list enclosed in a pair of square brackets.

### Command options

A subset of the command options (see Sect. 4) can also be used as package options, which lets them apply to all embedded media. Some of the options listed here are meaningful only for a specific media type (either Flash or 3D), which will be noted explicitly if not obvious. Dedicated sections covering Flash, video and sound as well as 3D inclusion will follow later on in this document.

label=<label text> The media annotation is given a label, <label text>, which should be unique. Labelled media annotations can be targeted by the media actions of a control button (see description of the <mediabutton command in Sect. 5.3). Moreover, a reference to the RichMedia Annotation object (of type 'AnnotRichMedia') is assigned to the JavaScript variable annotRM['<label text>'] in order to facilitate its access in JavaScript. Note that the JavaScript reference is known only after the first opening of the page containing the media.

width=<h-size>, height=<v-size> | totalheight=<v-size>, keepaspectratio

Resize the media playback area. <poster text>, if provided, is squeezed or stretched accordingly. If only one of 'width' or '[total]height' is given, the other dimension is scaled to maintain the aspect ratio of <poster text>. If both 'width' and '[total]height' are given together with 'keepaspectratio', <poster text> is resized to fit within <h-size> and <v-size> while maintaining its original aspect ratio. Any valid <lEX dimension is acceptable for <h-size> and <v-size>. In addition, the length commands <width, <height, <depth and <totalheight can be used to refer to the original dimensions of <poster text>.

scale=<factor> Scales the playback area by <factor>.

addresource=<local file>, addresource=<another local file>,... Every invocation of this option embeds another local file that is required to run the main Flash application or 3D file (last argument of <includemedia). Typically, this option is used to embed video files, media player skins, XML files (such as databases), additional objects to appear in a 3D scene etc. If an already embedded file is needed in another <includemedia command, this option must be given there again. However, the file in question will only once be physically embedded in order to keep the PDF file small.

flashvars={<some_var=some_val&another_var=another_val&...>} (Flash only) Usually, Flash applications can be configured via ActionScript (AS) variables the programmer of the application has made visible from outside. A typical use would be to set the video source of a media player to point to an embedded MP4 file or to a live stream, or to set the speaker volume for playback of an MP3 file. The argument of the flashvars option is a list of <AS variable>=<value> pairs separated by '&' and enclosed in a pair of braces ([...]).

Note: If a variable is to be set to point to an embedded resource, the value of the variable must be given in exactly the same way as with the 'addresource' option. Otherwise the name of the embedded file cannot be resolved. For example,

 addresource=path/to/video.mp4 implies

 flashvars={vid=path/to/video.mp4&...} if, for a particular media player, the video source is set through ActionScript variable 'vid'.

(Note for 3D) Resource files used in 3D scenes cannot be loaded by means of ActionScript variables. This must be done by 3D JavaScript during activation of the 3D scene in the Reader. 3D JavaScript can be attached using option 'add3Djscript', see below.

attachfiles If set, embedded files can be downloaded from the PDF via the Attachments navigation pane in the Reader.

 activate=onclick | pageopen | pagevisible Decides on how to activate the media annotation. 'activate=onclick' is default behaviour and does not need be given explicitly; embedded media is activated when the user clicks on it or by a JavaScript. It is recommended to provide a poster image with the <poster text> argument in that case. 'pageopen' and 'pagevisible' automatically activate the media when the page becomes visible; 'pagevisible' is better for two-up and continuous page display.

 deactivate=onclick | pageclose | pageinvisible Decides on how to de-activate the media annotation. 'deactivate=pageclose' is default behaviour and does not need be given explicitly; media is automatically deactivated when the user leaves the page containing the media. 'pageinvisible' is similar, but may be better for two-up and continuous page display. Setting 'deactivate =onclick' requires user interaction for de-activating the media, either by right-click and chosing '_Disable Content_' or by a JavaScript.

 draft final With 'draft' the media is not embedded. Instead, a box is inserted that has the dimensions of <poster text>, subject to the resizing options 'width', 'height', 'totalheight' and'scale'. Option 'final' does the opposite as it forces the media to be embedded. Both options can be used to reduce compilation time during authoring of a document. To get the most out of them it is recommended to set 'draft' globally as a package or class option and to set 'final' locally as a command option of the media annotation that is currently worked on. After the document has been finished, the global 'draft' option can be removed.

 playbutton[= fancy | plain | none] noplaybutton By default, a transparent play button is laid over the inactive media annotation to draw the reader's attention to the embedded multimedia content. It is provided in two versions, 'fancy' and 'plain', but only 'plain' is available in the XAPEX workflow. The default setting is to try the 'fancy' version. 'noplaybutton' or 'playbutton=none' disable the play button overlay.

```
windowed[=false|[<width>x<height>][@<position>]]
```

The media is played in a floating window, instead of being played in an embedded fashion. The floating window size is specified via the optional argument <width>x<height>, where <width> and <height> are given in pixels (integer numbers without unit). If the size is not given, a default size is guessed from the annotation size. Optionally, the position of the floating window on the screen can be specified through @<position>, where <position> may assume one of 'tl', 'cl', 'b1', 'bc', 'br', 'cr', 'tr', 'tc' or 'cc'. The position specifiers have the following meaning:

```
tlctctcrclcccrblblbcbr
```

Default window position is 'cc', that is, centred on the screen. 'false' can be set to override a global setting via package options.

```
transparent
```

Indicates whether underlying page content is visible through transparent areas of the embedded media. Default is 'transparent=false'; media artwork is drawn over an opaque background prior to composition over the page content.

```
passcontext
```

(Flash only) If set, user right-clicks are passed through to the context menu of the embedded Flash application, replacing the default Adobe Reader context menu. Useful for cases where the Flash programmer provided additional functionality through the context menu of his application.

```
3Dtoolbar
```

Indicates whether a 3D toolbar should be shown in the Reader on top of the embedded 3D model.

```
3Dnavpane
```

If set, the 3D navigation pane displaying the 3D Model Tree becomes visible in the Reader when the content is initially activated.

```
3Dcoo=<x><y><z> <x><y><z> specify the positional vector \(\overrightarrow{COO}\) of the centre of orbit of the virtual camera. Real numbers in fixed and floating point notation are accepted.
```
3Dc2c=<x><y><z> <x><y><z> specify a direction vector \(\overrightarrow{C2C}\) of arbitrary length, originating in the centre of orbit and pointing to the virtual camera. Real numbers in fixed and floating point notation are accepted.

```
3Droll=<roll>
```

Prescribes an initial camera roll around the optical axis (in clockwise direction, if <roll> is greater that zero); measured in degrees and given as fixed or floating point real number.

3Dc2w=<12 element camera-to-world matrix> This option directly sets the camera-to-world transformation matrix according to the PDF specification. This is an expert option to be used _instead_ of the '3Dc2c', '3Dcoo' and '3Droll' options. Only fixed point real numbers are accepted.

3Dpsob=Min | Max | W | H Expert option which directly sets either the /PS entry in the case of perspective projection or the /OB entry in the case of orthographic projection to one of the four possible values. Default value is Min.

3Droo=<r> <r> is a positive fixed or floating point number specifying the radius of orbit _ROO_ of the virtual camera. Good values can be found by means of the '3Dmenu' option.

3Daac=<angle> This option sets the aperture angle of the camera, measured in degrees, for the perspective view mode. Fixed and floating point real numbers between 0 and 180 are admissible. A sensible value of 30 is pre-set by default. Larger values can be used to achieve wide-angle or fish-eye effects. See example 10 in section 7.1. This option excludes the use of the '3Dortho' option.

3Dortho[=<orthographic scaling factor>] Switches from the default perspective to orthographic view mode. In orthographic view, the 3D object is parallelly projected onto the virtual camera chip. The projected image is scaled by <orthographic scaling factor> before reaching the camera chip; default value is 1. The optimal value for the scaling factor is given by \(1/D\), where \(D\) is the diameter of the smallest enclosing sphere of the 3D object in World coordinate units. Fixed and floating point real numbers are accepted. The camera should be positioned outside the 3D object. For this, the radius of orbit (option '3Droo') should be greater than \(D/2\). Good values for orthographic scaling and orbital radius can easily be found by means of the '3Dmenu' option. Option '3Dortho' excludes the use of the '3Daac' option.

3Dmenu Mainly used during document authoring. Adds three entries, '_Generate Default View_', '_Get Current View_' and '_Cross Section_' to the context (right-click) menu of an activated 3D annotation. Moreover, it allows single parts or part groups of the scene to be scaled, translated and rotated against the remaining scene objects using the keyboard. Their new position can be saved in the current view ('_Get Current View_'). At first, parts to be modified must be highlighted by clicking either into the scene or into the 3D Model Tree (the part's bounding box becomes visible). Then, arrow keys \(\left\{\begin{array}{l}\includegraphics[]{figures/3Dmodel.pdf}\end{array}\right\}\) let the part spin around the vertical axis, and \(\left\{\begin{array}{l}\includegraphics[]{figures/3Dmodel.pdf}\end{array}\right\}\) tilt against it. In order to spin parts around their local up-axis, keep \(\left[\begin{array}{l}\includegraphics[]{figures/3Dmodel.pdf}\end{array}\right]\) pressed while using \(\left\{\begin{array}{l}\includegraphics[]{figures/3Dmodel.pdf}\end{array}\right\}\) and \(\left\{\begin{array}{l}\includegraphics[]{figures/3Dmodel.pdf}\end{array}\right\}\) Keys \(\left\{\begin{array}{l}\includegraphics[]{figures/3Dmodel.pdf}\end{array}\right\}\), \(\left\{\begin{array}{l}\includegraphics[]{figures/3Dmodel.pdf}\end{array}\right\}\) translate the selected part along the World axes, and \(\left\{\begin{array}{l}\includegraphics[]{figures/3Dmodel.pdf}\end{array}\right\}\).

\(\left\{\begin{array}{l}\includegraphics[]{figures/3Dmodel.pdf}\end{array}\right\}\), \(\left\{\begin{array}{l}\includegraphics[]{figures/3Dmodel.pdf}\end{array}\right\}\) scale the part.

\({}^{*}\)_Generate Default View_' computes optimal camera settings such that the visible parts of the 3D scene fit tightly into the viewing area. The result is printed, formatted as a list of \(\left\{\begin{array}{l}\includegraphics[]{figures/3Dmodel.pdf}\end{array}\right\}\)options, into the JavaScript console. The calculation is based 


can be set individually for every view. The additional views can later be selected either from a drop down list in the tool bar that is associated with the activated 3D object in the Reader or from the context menu of the 3D object.

The file <views file> is structured into view sections, one for every view:

VIEW[=<optional name>]

COD=<x> <y> <z>

C2C=<x> <y> <z>

ROLL=<roll>

% C2W=<camera-to-world matrix> % instead of COO, C2C and ROLL

ROO=<roo>

AAC=<aac>

% ORTHO[=<othographic scaling factor>] % instead of AAC

BGCOLOR=<r> <g> <b>

RENDERMODE=<render mode>

LIGHTS=<lighting scheme>

CROSSSECT

CENTER=<x> <y> <z>

NORMAL=<x> <y> <z>

OPACITY=<cutting plane opacity>

VISIBLE=true | false

PLANECOOLOR=<r> <g> <b>

INTERSECTIONVISIBLE=true | false

INTERSECTIONCOLOR=<r> <g> <b>

SHOWTRANSPARENT=true | false

SECTIONCAPPING=true | false

END

PARTSATTRS=keep

PART=<part name as in the Model Tree (required, optional if UTF16NAME present)>

UTF16NAME=<part name as hex encoded Unicode string>

VISIBLE=true | false

OPACITY=<part opacity>

RENDERMODE=<part render mode>

TRANSFORM=<12 element transformation matrix>

END

PART=<...>

...

END

etc.

END

VIEW

...

END

etc.

A view section starts with the keyword VIEW, optionally followed by a name for the view, and ends with the keyword END. If no name is given to the view, a default one is created, consisting of 'View' followed by the number of the current VIEW section in the file. A VIEW section may contain optional entries for setting the camera position and global rendering attributes of the scene, a CROSSSECT subsection as well as PART subsections for setting rendering and other attributes of parts individually. Table 1 lists the entries in a VIEW section.

Part sub-sections are opened by PART=<part name> and closed by END. There may be as many part subsections as there are parts in a 3D scene. Table 2 lists the possible entries in a PART sub-section. All entries are optional. However, a UTF16NAME entry is recommended, as the part name may contain non-ASCII characters. The value of the UTF16NAME key is the part name as a hex-encoded Unicode string. If UTF16NAME is not used, the part name in the 3D file must be entirely composed of ASCII characters. In that case, <part name> is mandatory and must match the part name as indicated in the 3D Model Tree of the 3D object (accessible via right-click onto the model in the Reader). The part can be scaled and repositioned by means of a TRANSFORM entry which takes a 12-element transformation matrix as its value. Remaining entries in a part sub-section control the visual appearance of the part.

A view section may contain at most one CROSSSECT sub-section. It inserts a cutting plane at a definite position and orientation in the 3D space, controlled by optional CENTER and NORMAL entries. The appearance characteristics of the cutting plane and the intersection of the plane with the 3D geometry are controlled by optional OPACITY, VISIBLE, PLANECOLOR, INTERSECTIONVISIBLE, INTERSECTIONCOLOR, SHOWTRANSPARENT, SECTIONCAPPING entries. See Table 3 for explanation.

The views file can be commented. As usual, comments start with the percent sign.

To facilitate the creation of a views file, option '3Dmenu' can be added to \includemedia (see above). It creates context (right-click) menu entry 'Get Current View' which outputs a complete VIEW section corresponding to the current view of the 3D object in the Reader, including camera position, an optional cross section, and all part and viewing options that can be modified via the 3D toolbar (option '3Dtoolbar') or the context menu of the 3D object (entries '_Part Options_', '_Viewing Options_'). Hence, apart from tweaking one or another entry, there should be no need for writing views files by hand.

3Dplaytype=linear | oscillating According to the PDF specification, embedded keyframe animations can be played in two ways. If set to 'linear', keyframe animations are driven linearly from beginning to end, while 'oscillating' lets the animation play in a forth-and-back manner.

3Dplaycount=<integer number> A non-negative <integer number> represents the number of times the animation is played. A negative integer indicates that the animation is infinitely repeated. This value is ignored if option 3Dplaytype is not set.

3Dplayspeed=<positive number> This option can be used to adjust the keyframe animation speed. A value of '1' corresponds to the default speed defined in the 3D file.

add3Djscript=<3D JavaScript file>, add3Djscript=<another 3D JavaScript file>,...

Things like animation, lighting, background of 3D objects etc. may also be script driven. Every invocation of 'add3D3script' associates another JavaScript file with the 3D object. Upon activation of the 3D object, the scripts are executed once in the order of their inclusion. Refer to the Acrobat 3D JavaScript Reference [3] for syntax details. The following 3D JavaScript loads an image file that was attached by 'addresource=images/sunset.jpg' and uses it as the scene background.

 sunset = new Image(new Resource('pdf://images/sunset.jpg'));  reh = new RenderEventHandler();  reh.onEvent = function(event) {  runtime.removeEventHandler(this);  event.canvas.background.image=sunset;  }  runtime.addEventHandler(reh); For convenience, subdirectory 'javascript' of the'media9' installation contains three 3D JavaScript files which may come in handy at times: 'animation.js' enables embedded keyframe animation in 3D files; '3Dspintool.js' enables the Spin tool of the 3D plugin for easier rotating the 3D object with the mouse; 'asylabels.js' adds 'billboard behaviour' to text labels in Asymptote (\(\geq v2.17\)) generated PRC files for improved visibility; text labels always face the camera while rotating the 3D object with the mouse.

\begin{table}
\begin{tabular}{l l l} \hline key & type & remarks \\ \hline COO & three numbers & centre of orbit, see option ‘3Dcoo’ \\ C2C & three numbers & centre of orbit to camera vector, see option ‘3Dc2c’ \\ ROO & number & radius of orbit, see option ‘3Droo’ \\ C2W & 12 numbers & camera-to-world transformation matrix, see option ‘3Dc2w’ \\ AAC & number & camera aperture angle, see option ‘3Daac’ \\ ORTHO & number (optional) & enables orthographic view, see option ‘3Dortho’ \\ PSOB & string & expert setting, see option ‘3Dpsob’ \\ ROLL & number & camera roll, see option ‘3Droll’ \\ BGCOLOR & three numbers & given as <r> <g> <b>, specify the 3D scene background colour (RGB), see option ‘3Dbg’ \\ RENDERMODE & string & render mode of the 3D object, see option ‘3Drender’ \\ LIGHTS & string & lighting scheme, see option ‘3Dlights’ \\ PARTSATTRS & string & allowed values are ‘keep’ and ‘restore’; decides on whether to restore or not original part attributes before applying new ones from this view; see option ‘3Dpartsattrs’ \\ PART (sub-section) & string & part name as in the 3D Model Tree; name argument is optional if a UTF16NAME entry is present in the sub-section opened by a PART keyword, otherwise required; see Table 2 for list of possible entries \\ CROSSSECT (sub-section) & – & see Table 3 for list of possible entries \\ \hline \end{tabular}
\end{table}
Table 1: Entries in a VIEW section.

\begin{table}
\begin{tabular}{l l l} \hline key & type & remarks \\ \hline UTF16NAME & hex string & part name in UTF-16 (aka Unicode), encoded as a hexadecimal string; optional, but useful for part names composed of non-latin characters; \\ VISIBLE & boolean & a flag (‘true’ or ‘false’) indicating the visibility of this part \\ OPACITY & number & a number between 0.0 and 1.0 specifying the opacity of this part \\ RENDERMODE & string & rendermode of this part, overrides global RENDERMODE value in parent VIEW section, see option ‘3Drender’ \\ TRANSFORM & 12 numbers & transformation matrix defining the part’s position and scaling \\ \hline \end{tabular}
\end{table}
Table 2: Entries in a PART sub-section.

\begin{table}
\begin{tabular}{l l l} \hline key & type & remarks \\ \hline CENTER & three numbers & central point coordinates of the cutting plane \\ NORMAL & three numbers & normal vector coordinates of the cutting plane pointing into the cut-off region \\ OPACITY & number & a number between 0.0 and 1.0 specifying the opacity of the cutting plane \\ VISIBLE & boolean & a flag (‘true’ or ‘false’) indicating the visibility of the cutting plane \\ PLANECOLOR & three numbers & given as ‘<r> ‘<g> ‘<b>, specify the colour (RGB) of the cutting plane \\ INTERSECTIONVISIBLE & boolean & a flag (‘true’ or ‘false’) indicating the visibility of the intersection of the cutting plane with any 3D geometry \\ INTERSECTIONCOLOR & three numbers & given as ‘<r> ‘<g> ‘<b>, specify the colour (RGB) for the cutting plane’s intersection with the 3D geometry \\ SHOWTRANSPARENT & boolean & a flag (‘true’ or ‘false’) indicating that the portion of a model on the cut side of a section plane shall be viewed using a transparent render mode \\ SECTIONCAPPING & boolean & a flag (‘true’ or ‘false’) indicating whether the section plane shall be closed and rendered as if cutting through a solid object \\ \hline \end{tabular}
\end{table}
Table 3: Entries in a CROSSSECT sub-section.

### Control buttons

\mediabutton[<options>]{<normal button text or graphic>}

This command inserts a clickable button for media control. Actions to be performed are specified through options'mediacommand', '3Dgotoview' and 'jsaction'. By using these options repeatedly and in any combination, several actions can be bound to one media button, and one media button can be used to control several media at the same time. Media actions are started in the given order but performed in parallel, because they do not wait for each other to finish. The target of an action is specified via the label that was also given to a particular media by the 'label' option of '\includemedia'. Individual button faces can be defined for the'mouse-over' and'mouse-button-down' events using the 'overface' and 'downface' options. Without options, the button produced does nothing. The options provided are as follows:

\overface=<mouse-over text or graphic>

If specified, the media button changes its appearance when the mouse pointer is moved over it. Without this option, the button appearance does not change. An \includegraphics command may need to be enclosed in braces.

\downface=<mouse-button-down text or graphic>

If specified, the media button changes its appearance when the mouse button is pressed while the pointer is over it. An \includegraphics command may need to be enclosed in braces.

\tooltip=<tip text>

A box with <tip text> is shown when the mouse pointer is moved over the button.

3Dgotoview=<label text>[:<view specification>]

Selects a view from the list of predefined views associated with a 3D media inclusion (see option '3Dviews'). The target media is specified by <label text>, as defined by the 'label' option of '\includemedia'. <label text> alone without a view specification simply activates the 3D object if not yet activated. <view specification> which is separated from the label by a colon (:) can be one of the following: an integer specifying the zero-based index into the list of views in the 3D views file; one of 'D', 'F', 'L', 'N', 'P' indicating the default, first, last, next or previous view in the list of views; a string delimited by '(' and ')' matching the name of a view as specified by the 'VIEW=...' entry in the views file. The option can be given several times to simultaneously change the view in more than one 3D inclusion. However, it cannot be used to create an animation effect within the same 3D inclusion, because 3Dgotoview actions are executed in parallel.

\mediacommand=<label text>[:<command> [(<arg1>) (<arg2>)...]]

A media command <command>, with arguments if required, is sent to a media inclusion identified by <label text>, as defined by the 'label' option of '\includemedia'. <label text> alone without a command specification simply activates the media, if not yet activated. The option can be used multiple times within the same button to target different media inclusions at the same time or to execute several commands for the same media. Depending on the type of the target media (3D or Flash), <command> is either the name of a JavaScript function defined in a 3D JavaScript file associated withthe 3D media (see option 'add3Djscript') or the name of an ActionScript function that was exposed by the embedded Flash file. ActionScript functions are exposed to the scripting context of the hosting document by using the ExternalInterface call within the Flash file. Arguments to be passed to <command> must be enclosed in '(' and ')' and separated by spaces, the whole list be finally enclosed in '[' and ']', even if there is only a single argument. Arguments can be of Boolean type (true, false), numbers (integer, reals) and strings. The number of arguments and their types must match the definition of the function to be called. Media players VPlayer.swf and APlayer.swf shipping with'media9' expose a number of ActionScript functions that can be used with this option (see Tab. 6). <command> [(<arg1>) (<arg2>)...] must be enclosed in braces if there are embedded equals signs or commas. Examples of using'mediacommand' are given in Figs. 2 and 6.

jsaction=[<label text>:]{<JavaScript code>} The JavaScript code is executed in the context of the document's instance of the JavaScript engine (there is one instance of the JavaScript engine per open document in Adobe Reader). <JavaScript code> is required and must be enclosed in braces. Unlike media actions defined with options'mediacommand' and '3Dgotoview', the JavaScript action defined here is not targeted at a particular embedded media and can be used to run arbitrary code. Therefore, <label text> is optional. If provided, it must be separated from <JavaScript code> by a colon. However, it is recommended to provide a label text. It ensures that annotRM['<label text>'] is a valid JavaScript reference to the AnnotRichMedia object. annotRM['<label text>'] can be used to get access to the global context of the annotation's instance of the 3D JavaScript engine (there is one instance of the 3D JavaScript engine per activated RichMedia Annotation with 3D content). The 3D JavaScript context of a 3D model can be accessed as annotRM['<label text>'].context3D. Refer to the Acrobat 3D JavaScript Reference [3] for details on built-in JavaScript objects that are available in the 3D context. The annotRM['<label text>'].callAS() method may be used as an alternative to the'mediacommand' option. Both serve as means of running ActionScript functions exposed by embedded Flash files. See [4] for details.

draft final See above.

Embedding Flash, video and sound,

image slide-shows

A YouTube video clip, as shown in Fig. 1, may serve as a basic example of loading Flash content from a URL to be displayed in an embedded fashion in a PDF document. Indeed, a YouTube clip is nothing more than a small SWF file which loads a video stream and other necessary resources, such as user controls and a player skin from a remote server. It can be configured via ActionScript variables to play several videos in a row, to play a video in a loop etc. Player parameters are documented on [http://code.google.com/apis/youtube/player_parameters.html](http://code.google.com/apis/youtube/player_parameters.html) and can be passed to the player using either the 'flashvars' option, as in the example, or appended to the URL string after the video ID. A question mark '?' must be put between the video ID and the parameter string. Some of the documented parameters, such as'rel', seem to have an effect only if they are passed as part of the URL.

Media files (video, sound, images) are always loaded and then played by a media player application. Four players are installed along with the'media9.sty' package file: three simple players for video ('VPlayer.swf'), sound ('APlayer.swf') and slide-shows of embedded and/or remote (live or static) image files ('SlideShow.swf'), and the fully blown third-party media player 'StrobeMediaPlayback.swf' with some fixes to improve its usability. The simple players are 'chromeless', that is, they do not have graphical user controls. Nevertheless, interactivity is provided through left mouse button press and release for playing, pausing, resuming playback, through the player's context menu (right-click), and through the keyboard as summarized in Table 4. The player apps were compiled using the open-source Apache Flex SDK [5] from XML source files which reside in the doc/ folder of the package installation. For 'StrobeMediaPlayback.swf',

Figure 1: A YouTube video as an example of a Flash application loaded from a URL.






\begin{table}
\begin{tabular}{l l}  & (a) \\ \hline parameter & description \\ \hline source=\textless{}file path or URL\textgreater{} & (required) path to embedded media file (see option ‘addresource’), or URL (http, rtmp) to online media file \\ autoPlay=true|false & if =true, automatically starts playback after activation (see option ‘activation’) \\ autoRewind=true|false & (VPlayer.swf only) if =true, automatically rewind to the first frame after playback has finished; default is ‘false’ \\ loop=true|false & if =true, media is played in a loop \\ scaleMode=letterbox|none| & default: letterbox; determines how to \\ stretch|zoom & scale the video in order to fit into player \\ hideBar=true|false & (APlayer.swf only) if =true, the progress \\ bar indicating the play position is not & \\ \hline volume=\textless{}value between 0.0 & sets volume of the sound \\ and 1.0\textgreater{} & balance=\textless{}value between \\  & -1.0 and 1.0\textgreater{} & speakers \\ \hline  & (b) \\ \hline parameter & description \\ \hline xml=\textless{}file path or URL\textgreater{} & (required) path to embedded (option ‘addresource’) or URL of remote configuration file \\ delay=\textless{}number\textgreater{} & sets time delay in seconds for transition between slides during playback, default: 5 s \\ autoPlay=true|false & if =true, automatically starts cycling through slides after activation (see option ‘activation’ \\ \hline \end{tabular}
\end{table}
Table 5: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 5: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 5: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 6: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 4: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 7: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 8: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 9: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 5: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 5: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 4: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 5: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 9: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 10: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 11: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 12: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 13: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 14: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 15: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 16: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 17: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 18: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 19: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 15: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 14: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \hline \end{tabular}
\end{table}
Table 17: Parameters (ActionScript variables) for media players (a) ‘VPlayer.swf’ & ‘APlayer.swf’, (b) ‘SlideShow.swf’ shipping with media9. Parameters are passed as a ‘& (b) \\ \end{tabular}

\begin{table}
\begin{tabular}{l l l} \hline function & argument & description \\ \hline play & number (optional) & play media, optionally starting at _number_ \\  & & seconds offset into the media file \\ pause & number (optional) & pause media, optionally at the given offset of _number_ seconds into the media file \\  & & toggle between play and pause \\  & & load another media file (path to file, embedded using option ‘addresource’, or URL) \\ seek & number & move the play location to a time offset from the beginning of the media; argument measured in seconds \\  & & reward media to the beginning (without pausing it) \\  & & set volume level \\  & & and 1 \\  & balance & number between \(-1\) \\  & & and +1 \\  & & mute \\  & & \\  & & \\  & & \\  & & \\  & & \\  & & \\  & & \\  & & \\  & & \\  & & \\  & & \\  & & \\  & & \\  & & \\ \end{tabular}
\end{table}
Table 6: Exposed ActionScript functions of media players ‘VPlayer.swf’ and ‘APlayer.swf’ that can be called from within media buttons (see Sect. 5.3) or from JavaScript using the ‘callAS’ method of the ‘AnnotRichMedia’ JavaScript object (see [4] for further information).

{includemedia[  addresource=bird.mp3,  flashvars={  source=bird.mp3 &autoPlay=true  },  transparent,  passcontext %show APlayer's right-click menu  ]{\color{blue}}framebox[0.4\linewidth][c]{Singing bird}}{APlayer.swf} (a) ```
``` \includemedia[  flashvars={  source=[http://mp3.live.tv-radio.com/franecculture%](http://mp3.live.tv-radio.com/franecculture%)  /all/franecculturehautdebit.mp3 &autoPlay=true },  transparent,  passcontext %show APlayer's right-click menu ]{\color{blue}}fbox{Listen live to Radio France Culture}}{\%  [http://mirrors.ibiblio.org/pub/mirrors/CTAN/macros/latex/%](http://mirrors.ibiblio.org/pub/mirrors/CTAN/macros/latex/%)  contrib/media9/players/APlayer.swf% } (b)
```

```
\includemedia[  label=song49,  flashvars={source=[http://www.openbsd.org/songs/song49.mp3](http://www.openbsd.org/songs/song49.mp3)},  transparent,  passcontext %show VPlayer's right-click menu ]{\color{blue}}fbox{Listen to OpenBSD 4.9 release song}}{APlayer.swf}\ \mediabutton[  mediacommand=song49:play[(5.5)],  mediacommand=song49:pause[(37)] ]{\fbox{First verse}} \mediabutton[  mediacommand=song49:play[(39)],  mediacommand=song49:pause[(49)] ]{\fbox{The Answer}} \mediabutton[  mediacommand=song49:play[(206.5)],  mediacommand=song49:pause[(221)] ]{\fbox{Harmonica solo}}
```

Listen to OpenBSD 4.9 release song

Figure 6: Example of (a) embedded sound file, (b) streamed audio and (c) progressively downloaded MP3. ID3 tags ‘title’, ‘artist’ and ‘album’ are displayed if contained in the MP3 stream or file. In (b), the sound player, APlayer.swf, is loaded from a CTAN mirror upon activation.

\includemedia[  %activate=onclick, % default  addresource=cube.mp4,  flashvars={  source=cube.mp4  &autoPlay=true % start playing on activation  &loop=true  },  passcontext %show player's right-click menu ]{\includegraphics[height=0.45\linewidth]{cubeposter}}{VPlayer9.swf}

Figure 7: Video and sound examples that should run in Adobe Reader for Linux up to version 9.4.1. Here, players ‘VPlayer9.swf’ and ‘APlayer9.swf’ are used. Both are compatible with Adobe Flash Player 9 plugin that is bundled with the Reader. Also, the video player needs to be activated by mouse click (which is the default). We provide a poster image that is shown in the inactive state.

\begin{table}
\begin{tabular}{l l l} \hline function & argument & description \\ \hline play & & play slide-show \\ pause & & pause slide-show \\ playPause & & toggle between play and pause \\ setXML & string & load another configuration file (path to file, embedded using option ‘addresource’, or URL) \\ seek & int number & go to slide ‘number’ (zero-based) \\ slideNum & & returns current slide number (zero-based); only useful in JavaScript via ‘callAS’ method \\ numSlides & & returns total number of slides in the slide-show; only useful in JavaScript via ‘callAS’ method \\ playing & & returns boolean value ‘true’, if the slide-show is currently playing, ‘true’ otherwise; only useful in JavaScript via ‘callAS’ method \\ rotate & int number (optional) & rotate current slide by number\(\times\)90\({}^{\circ}\) \\ \hline \end{tabular}
\end{table}
Table 7: Exposed ActionScript functions of slide-show player ‘SlideShow.swf’ that can be called from within media buttons or from JavaScript.

\begin{table}
\begin{tabular}{l l} \hline parameter & description \\ \hline src=\textless{}file path or URL> & (required) path to embedded media file (see option ‘addresource’), or URL (http, rtmp) \\  & of online media file \\ autoPlay=true|false & default: false; if =true, automatically starts playback after activation (see option ‘activation’ \\ autoRewind=true|false & default: true; if =false, keep last frame after end of playback \\ loop=true|false & if =true, media is played in a loop \\ scaleMode=letterbox|none| & default: letterbox; determines how to scale the video in order to fit into player \\ controlBarMode=docked| & default: docked; determines position and \\ floating|none & visibility of control bar \\ controlBarAutoHide= & default: true; automatically hide or not \\ true|false & control bar \\ controlBarAutoHideTimeout= & default: 3; time span before auto-hide \\ \textless{}number [s]> & volume=\textless{}value between 0.0 \\  & and 1.0> \\ audioPan=\textless{}value between & default: 0; sets balance of sound speakers \\  & -1.0 and 1.0> \\ muted=true|false & default: false; mute or not sound \\ \hline \end{tabular}
\end{table}
Table 8: Parameters (ActionScript variables) for ‘StrobeMediaPlayback.swf’ shipping with media9. Parameters are passed as a ‘&’-separated string using ‘flashvars’ option.

Embedding 3D objects

### Introduction

Adobe Acrobat/Reader 7 was the first version to allow for embedding 3-dimensional graphic objects, such as CAD models or 3D scientific data, that can be manipulated interactively by the user. U3D was the first supported format and was mainly developed by Right Hemisphere and Adobe. U3D had some deficiencies and was later replaced by the PRC format after Adobe purchased the original developer, the French company 'Trade and Technology France'. U3D is still supported, but PRC is preferred as it allows for exact representation of curved surfaces and better compression. Both, U3D and PRC specifications are public [6, 7].

Currently, two open-source software packages are known to export into the PRC file format. The first one is Asymptote [8], which is a descriptive 2D and 3D vector graphics language and interpreter and which uses TeX to typeset labels and equations. It allows for high quality mathematical figures and technical drawings. An impressive gallery of examples can be found on its Web site. The second one is MathGL [9], a library for scientific data visualization. It provides interfaces to a number of programming and scripting languages as well as an interpreter for its own command language 'MGL'.

MeshLab [11] is an open-source conversion and processing software for 3D mesh data which can import from and export to a number of file formats. Its U3D export filter is based on the open-source 'Universal 3D Sample Software' [10].

There are a few options to \includemedia which define how the 3D object is positioned within the view port of a virtual camera, or conversely, how the virtual camera is positioned and oriented within a coordinate system, called 'The World', which bears the 3D object at a fixed position. Fig. 8 should help to grasp the scenery: The virtual camera is orbiting at a distance of \(ROO\) (option '3Droo') around the centre of orbit, specified by the position vector \(\overrightarrow{COO}\) (option '3Dcoo'); \(<\)_AAC_ (option '3Daac') is the camera's aperture angle. The direction vector \(\overrightarrow{CO2C}\) (option '3Dc2c') is needed to specify the initial camera position. The camera may be given an initial roll angle (option '3Droll') around its optical axis \((-1)\cdot\overrightarrow{CO2C}\). Fig. 8 shows the camera parameters for the perspective view mode. Alternatively, the orthographic view mode may be chosen. In orthographic view, the 3D object is parallelly projected onto the virtual camera chip. Before reaching the camera chip, the projected image must be scaled in order to fit onto the chip. Orthographic view can be enabled using the '3Dortho' option which takes the scaling factor as its argument.

Above options define the default view, i. e. the view that is shown initially after activating the 3D object in the Reader. Of course, once activated, the camera position can be changed using the mouse and one can change forth and back between perspective and orthographic viewing modes using the 3D tool bar.

By default, the virtual camera sits at the origin \((0,0,0)\) of the World, looking in the positive \(Y\) direction, i. e. default settings of 3Droo=0, 3Dcoo=0 0 0 and 3Dc2c=0 -1 0 are assumed. (Note that \(\overrightarrow{CO2C}\) is the opposite of the optical axis vector.) Thus, in order to get a 'front view' of the 3D object it is sufficient to set the radius of orbit, i. e. the distance between camera and object appropriately. Sometimes you may want to adjust the orbital centre, i. e. the target of the camera as well, in particular, if the object is irregularly shaped or if it is not centred around the World origin. Fortunately, it is possible to let the values of the corresponding options be determined automatically. Choosing option '3Dmenu' adds '_Generate Default View_' to the context menu of the activated 3D scene. Selecting this entry calculates and outputs optimal camera settings which can be inserted into the option list of \includemedia.

Additional resource files that are needed to render the 3D scene can be embedded using the 'addresource' option. Typical resources are bitmaps and Flash files (even animated and interactive ones), to be used as materials or scene backgrounds, as well as additional 3D objects in the U3D or PRC file format. The allowed file formats of _bitmapped_ image files depend on the \(\overline{\mathit{\text{HE}}}\)Xworkflow. \(\overline{\mathit{\text{HE}}}\)X\(\rightarrow\)dvips\(\rightarrow\)ps2pdf/Distiller accepts PS and EPS files; pdf\(\overline{\mathit{\text{HE}}}\)X accepts PNG, JPEG and JBIG2; (\(X_{\overline{\mathit{\text{HE}}}}\)X\(\rightarrow\) (x)dvipdfmx accepts PNG and JPEG. 3D JavaScript is necessary to load these resources upon activation. 3D JavaScript files are attached using the 'add3Dscript' option.

Below, several examples of embedded 3D files are shown. The first one, Fig. 9 is a PRC file generated with Asymptote. Note the text labels always facing the camera thanks to the attached 3D JavaScript file 'asylabels.js'. The second example, Fig. 10,

Figure 8: Camera and 3D object in the World System \(XYZ\); centre of orbit position vector \(\overline{\mathit{COO}}\), centre of orbit to camera direction vector \(\overline{\mathit{C2C}}\), radius of orbit \(\mathit{ROO}\), aperture angle of camera \(\sphericalangle AAC\).

demonstrates the use of a views file which defines additional named views of the 3D object. Moreover, the possibilities of the extended 3D context menu can be evaluated. They were enabled by adding the '3Dmenu' option to \includemedia. All part and scene rendering attributes that can be changed via the '_Part Options_' and '_Viewing Options_' menu entries, as well as a cross section to be added with the '_Cross Section_' menu entry can be saved into a new view ('_Get Current View_'). Position, orientation and scaling of individual parts and of the cross section can be changed using the keyboard (keys \(\left\{\begin{array}{l}\includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.26378pt]{3Dmenu}\\ \includegraphics[width=14.226378pt]{3Dmenu}\\ \includegraphics[width=14.


()includemedia[  label=malte,  width=0.5\linewidth,height=0.5\linewidth,  activate=pageopen,  3Dmenu,  3Dc2c=11,  3Dcoo=-0.001042630523443222 1.4577869224116568e-190.028235001489520073,  3Droo=0.2604540212188131,  add3Djscript=malte.js  ]{malte.u3d}

 \mediabutton[  jsaction=malte:{annotRM['malte'].context3D.cntrClockWise();}  ]{includegraphics[height=1.44em]{boutona}}  \mediabutton[  jsaction=malte:{annotRM['malte'].context3D.pause();}  ]{includegraphics[height=1.44em]{boutonb}}  \mediabutton[  jsaction=malte:{annotRM['malte'].context3D.clockWise();}  ]{includegraphics[height=1.44em]{boutonc}}  \hspace{lem}  \mediabutton[  jsaction=malte:{annotRM['malte'].context3D.scaleSpeed(1/1.1);}  ]{includegraphics[height=1.44em]{boutond}}  \mediabutton[  jsaction=malte:{annotRM['malte'].context3D.origSpeed();}  ]{includegraphics[height=1.44em]{boutone}}  \mediabutton[  jsaction=malte:{annotRM['malte'].context3D.scaleSpeed(1.1);}  ]{includegraphics[height=1.44em]{boutonf}}

Figure 11: Animated U3D example of a Maltese drive contributed by Jean-Luc Chesnot. The animation and the functions called in the JavaScript actions of the media buttons are defined in the JavaScript file ‘malte.js’.

### 3D quick-start guide

1. Insert the 3D object with default camera settings and with extended context menu enabled (option '3Dmenu'): \includemedia[ width=0.5\linewidth,height=0.5\linewidth,
2.25 activate=pageopen, 3Dmenu ]{}{myfile.u3d}
3. Compile the document.
4. Open the PDF document in Adobe Reader and go to the page containing the 3D object. Select '_Generate Default View_' from the 3D context menu (right mouse click) and wait for the JavaScript console to pop up. Optionally, drag the object with the mouse to change the viewpoint of the camera and select '_Generate Default View_' again. This will re-adjust the distance between camera and target to fit all visible parts tightly into the viewport. The options printed into the console are updated accordingly.
5. Copy the camera settings (3Droo=..., 3Dcoo=..., etc.) from the console into the option list of \includemedia.
6. Compile the document again.

_Optional steps_ (option '3Dmenu' required):

1. Additional, named views; cross sections; rescaled, repositioned parts: 1. Open a text file, e. g.'myviews.vws', to be populated with additional views of the 3D object. 2. Manipulate the 3D object using the mouse (camera position) and via 3D context menu items '_Part Options_' and '_Viewing Options_' (visibility, rendering attributes, background etc.); the camera target can be moved into the centre of a single part via '_Part Options_'\(\rightarrow\)'_Zoom to Part_'. 3. Add a cross section plane (select '_Cross Section_' from the 3D context menu), adjust its position using the keyboard; keyboard keys are given here. 4. Adjust scaling and position of individual parts using the keyboard; keyboard keys are given here. 5. Re-adjust the camera distance using either '_Generate Default View_' or '_Part Options_'\(\rightarrow\)'_Fit Visible_'. 6. When you are done, select '_Get Current View_' to get the VIEW section, readily formatted for insertion into the views file. Repeat steps (a)-(f) to get any number of views you want to define. The views file can be edited manually to give meaningful names to the views (change the value of the VIEW key), or to further tweak camera settings, opacity, part options etc. 7. Attach the views file with option '3Dviews': \includemedia[ width=0.5\linewidth,height=0.5\linewidth,height=0.5\linewidth,height=0.5\linewidth,
8.5activate=pageopen, 3Dviews=myviews.vws, 3Dmenu ]{}{myfile.u3d} If you are satisfied with the predefined views in the views file, the default view first specified through the options of \includemedia can be deleted. The first view in the views file becomes the default view then.
7. Associate any number of 3D JavaScript files with the 3D object: \includemedia[ width=0.5\linewidth,height=0.5\linewidth, activate=pageopen, add3Djscript=somescript.js, add3Djscript=otherscript.js, 3Dviews=myviews.vws, 3Dmenu ]{}{myfile.u3d} A few 3D JavaScript files ready to be used are already installed along with'media9.sty', see above.

## 8 Caveats

1. Large media files may cause TeX to interrupt with error! TeX capacity exceeded, sorry [main memory size=3000000]. when using latex in dvips mode. While writing the DVI file, media files in the current page that are about to be embedded are kept in TeX's memory until shipping out of the readily typeset page. In the case of large or many files, this may be more than TeX can cope with by default. There are two options to handle such situations: The first one is to increase TeX's main memory. You may follow the steps in the Bugs section of the 'animate' package documentation. In TeXlive-2012, the maximum value that can be set is main_memory = 12435455. If increasing TeX's main memory does not help, use the package option 'bigfiles' with media9. It defers file embedding from the DVI producing to the PS producing step.
2. In right-to-left typesetting context (RTL) using the (pdf)TeX or XeTeX engines, the <poster text> argument of \includemedia and the text arguments for button faces of the \mediabutton command should be enclosed in pairs of \beginR and \endR.

## 9 Acknowledgements

This package was written using the new LaTeX3 syntax which was a lot of fun. Many thanks to the LaTeX3 team!

## References

* [1] Adobe Systems Inc.: _Strobe Media Playback_, 2010, available at [http://osmf.org/strobe_mediaplayback.html](http://osmf.org/strobe_mediaplayback.html)
* [2] Adobe Systems Inc.: _Adobe Supplement to ISO 32000, BaseVersion 1.7, Extension-Level 3_, 2008, available at [https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/adobe_supplement_iso32000.pdf](https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/adobe_supplement_iso32000.pdf)
* [3] Adobe Systems Inc.: _JavaScript for Acrobat 3D Annotations API Reference_, available at [https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/Acro12_MasterBook/JS_3D_Intro/JS_3D_Intro.htm](https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/Acro12_MasterBook/JS_3D_Intro/JS_3D_Intro.htm)
* [4] Adobe Systems Inc.: _JavaScript for Acrobat API Reference_, available at [https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/Acro12_MasterBook/JS_API_AcroJSPreface/JS_API_AcroJSPreface.htm](https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/Acro12_MasterBook/JS_API_AcroJSPreface/JS_API_AcroJSPreface.htm)
* [5] The Apache Software Foundation: _Apache Flex SDK_, available at [http://flex.apache.org](http://flex.apache.org)
* [6] ECMA International: _Universal 3D File Format (ECMA-363), 4th Edition_, 2007, available at [http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-363%204th%20Edition.pdf](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-363%204th%20Edition.pdf)
* [7] Adobe Systems Inc.: _PRC Format Specification_, available at [https://web.archive.org/web/20081202034541/http://livedocs.adobe.com/acrobat_sdk/9/Acrobat9_HTMLHelp/API_References/PRCReference/PR_Format_Specification/index.html](https://web.archive.org/web/20081202034541/http://livedocs.adobe.com/acrobat_sdk/9/Acrobat9_HTMLHelp/API_References/PRCReference/PR_Format_Specification/index.html)
* [8] A. Hammerlindl, J. Bowman and T. Prince: _Asymptote: The Vector Graphics Language_, available at [http://asymptote.sourceforge.net](http://asymptote.sourceforge.net)
* library for scientific graphics_, available at [http://mathgl.sourceforge.net](http://mathgl.sourceforge.net)
* [10] T. O'Rourke, T. Strelchun: _Universal 3D Sample Software_, available at [http://sourceforge.net/projects/u3d](http://sourceforge.net/projects/u3d)
* [11] P. Cignoni _et al._: _MeshLab_, available at [http://meshlab.sourceforge.net](http://meshlab.sourceforge.net)
* [12] RightHemisphere Inc.: _DeepExploration_, [http://www.righthemisphere.com/products/dexp/](http://www.righthemisphere.com/products/dexp/)