[texhax] embedding java applets in pdf output files

Steve Schwartz s.schwartz at imperial.ac.uk
Fri Nov 16 16:09:14 CET 2007


Tim,

On Thu, 2007-11-15 at 20:10 -0800, Tim wrote:
> Is there a way to embed a java application within a *.pdf file using 
> pdfLaTeX?
> 
> Any help on this would be appreciated, or even pointing me in the 
> direction to search.  Google has failed me this time..   :(

I know of two generic approaches, which I've run across in discussions
about how to play movies within pdflatex-generated presentations. They
should work for anything else you can run or launch, I guess.

Here are some README notes I wrote for myself. If you substitute a
script to launch your applet for movie_script.sh below, it should work I
think. But since the script is run outside the pdf itself, it (a) isn't
embedded in the pdf, (b) isn't portable and (c) is operating-system
dependent.

The 1st is to use the hyperref package:

In your latex source there is, for example:

\href{run:movie_script.sh}{Click Here}

movie_script.sh is just a shell script to run your favorite player, e.g.
a file with the one line:

mplayer -geometry 50%:50% -nofs  /home/sjs/movies/mymovie.mpg

(xine also works pretty well; you need something with a good command
line interface and which gives you control, e.g., to hide the controls,
etc.).

Then you need:

In ~/.mailcap:
application/x-sh; /bin/sh %s

to invoke sh to run your shell script. You can also use /bin/bash or
some
other shell interpreter. You also need to associate the .sh
ending with a shellscript:

In ~/.mime.types:
application/x-sh sh

There are ways to avoid opening your mime-types up to running a shell
script (which is a security risk) or you could teach your mailcap about
running videos (but then you lose control over options passed to the
player for specific ones); let me know if you want these notes.

The 2nd is to use pdf capabilities. I'll confess I've never got this to
work properly, but maybe it is closer to what you want. [I didn't try
very hard because the hpyerref solution has always been adequate for my
needs, but it would be nice to get something to auto-launch without a
click when you open the page.] It still uses an external script, say
videoscript.sh, that you write to do what you want (and hence still
suffers from (a)-(c) above). The following is copied from a posting I
received from someone else. I'd be interested to know if you get it to
work.

Define the following two new commands in pdflatex,

\newcommand{\pdflaunch}[1] {\pdfpageattr{/AA << /O << /S /Launch /F (#1)
>>>>}}
\newcommand{\pdflaunchlink}[2]{%
      \pdfannotlink attr{/Border [0 0 0]} user{/Subtype /Link /A << %
        /S /Launch /F (#1) >>}%
      \pdfliteral{0 1 0 0 k}%
      {#2}\pdfliteral{0 0 0 1 k}\pdfendlink%
      }

you have either the possibility to launch this script instantly with a
new slide:

\pdflaunch{videoscript.sh}

or after pressing a special link defined by:

\pdflaunchlink{videoscript.sh}{Start video}

Don't forget to kill the video application when it is not needed
anymore. For this purpose again define a little script e.g.:

killall mpeg_play

and call it as mentioned above.

HTH

Steve

-- 
+-------------------------------------------------------------------+
Professor Steven J Schwartz      Phone: +44-(0)20-7594-7660
Space and Atmospheric Physics    Fax:   +44-(0)20-7594-7772
The Blackett Laboratory          E-mail: s.schwartz at imperial.ac.uk
Imperial College London          Office: Huxley 6M70 
London SW7 2BW, U.K.             Web: http://www.sp.ph.ic.ac.uk/~sjs
+-------------------------------------------------------------------+



More information about the texhax mailing list