[pdftex] Launching programs...

Steffen Neumann sneumann at TechFak.Uni-Bielefeld.DE
Thu Sep 11 12:46:39 CEST 2003

Thierry Bouche <thierry.bouche at ujf-grenoble.fr> writes:
> Ah, great! in fact this is what hyperref will put in the PDF if you
> say \href{run:mplayer movie.mpg}, which doesn't work under windows

Over here one of us created a hack that involves the TeX code below.
(BTW. is \href{} the recommended way to run programs ? 
 Does it need JavaScript ?)

So once you have these macros, you do 


In your local directory you have a Unix Script 
called myprogram, which can search for different 
movieplayers, probably handle MacOSX quirks (untested)
and finally run your movie.

For Windows, you have a myprogram.bat or myprogram.pif
(or both ?) that do pretty much the same. An advanced 
Version (which does not open a window or icon on your screen, and what
we have over here) is a little myprogram.exe,
(source below, courtesy Frank Loemker)
which needs amovie.ocx to run the movie. 



#include <windows.h>
#include <stdlib.h>

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                                        LPSTR lpCmdLine, INT nCmdShow)
        LPTSTR lpMsgBuf;
        STARTUPINFO si;

        memset (&pi, 0, sizeof(PROCESS_INFORMATION));
        memset (&si, 0, sizeof(STARTUPINFO));
        si.cb = sizeof(STARTUPINFO);

        if (CreateProcess (NULL,
                        "rundll32.exe amovie.ocx,RunDll /play /close VIDEOFILE.mpg                       
                        NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi) == 0) {

                                        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
                                        (LPTSTR) &lpMsgBuf,
                                        0, NULL);
                MessageBox (NULL, lpMsgBuf, "Error starting program",
        return 0;


% pdfannotlink had been renamed between pdftex 0.13 and 0.14
% provide backwards compatible macro names
\ifx\pdfstartlink\@undefined% less than version 14

% Launch based on a link, like \pdfstartlink{/usr/bin/xterm}{text} 
% with optional style argument how the link text should be done,
% underline being the default
  \leavevmode\pdfstartlink attr{/Border [0 0 0]} user{/Subtype /Link /A << % 
    /S /Launch /F (#2) >>}{\underline{#3}}\pdfendlink\rule{0mm}{1em}%
  \leavevmode\pdfstartlink attr{/Border [0 0 0]}%
  user{/Subtype /Link /H /O /A << /S /Launch /F (#2) >>}{\fbox{#3}}%
  \leavevmode\pdfstartlink attr{/Border [0 0 0]} user{/Subtype /Link /A << % 
    /S /Launch /F (#2) >>}{#3}\pdfendlink\rule{0mm}{1em}%
% Launch when entering the slide
  \pdfpageattr{ /AA << /O << /S /Launch /F (#1) >> >>}}
% PS version of the commands.

More information about the pdftex mailing list