[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 

	\pdflaunch{myprogram}

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. 

Yours, 
Steffen

-------------------------------------------------------------------

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

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

        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) {

                FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
                                        NULL,
                                        GetLastError(),
                                        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
                                        (LPTSTR) &lpMsgBuf,
                                        0, NULL);
                MessageBox (NULL, lpMsgBuf, "Error starting program",
                                        MB_OK|MB_ICONINFORMATION);
        }
        return 0;
}

-------------------------------------------------------------------

\ifpdf
% pdfannotlink had been renamed between pdftex 0.13 and 0.14
% provide backwards compatible macro names
\ifx\pdfstartlink\@undefined% less than version 14
 \let\pdfstartlink\pdfannotlink
 \let\pdflinkmargin\@tempdima
 \let\pdfxform\pdfform
 \let\pdflastxform\pdflastform
 \let\pdfrefxform\pdfrefform
\fi

% 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
\newcommand{\pdflaunchlink}[3][underline]{\leavevmode%
\ifthenelse{\equal{#1}{underline}}{%
  \leavevmode\pdfstartlink attr{/Border [0 0 0]} user{/Subtype /Link /A << % 
    /S /Launch /F (#2) >>}{\underline{#3}}\pdfendlink\rule{0mm}{1em}%
}{}%
\ifthenelse{\equal{#1}{boxed}}{%
  \leavevmode\pdfstartlink attr{/Border [0 0 0]}%
  user{/Subtype /Link /H /O /A << /S /Launch /F (#2) >>}{\fbox{#3}}%
  \pdfendlink\rule{0mm}{1em}%
}{}%
\ifthenelse{\equal{#1}{plain}}{%
  \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
\newcommand{\pdflaunch}[1]{%
  \pdfpageattr{ /AA << /O << /S /Launch /F (#1) >> >>}}
\else
% PS version of the commands.
\newcommand{\pdflaunchlink}[3]{#3}
\newcommand{\pdflaunch}[1]{#1}%
\fi


More information about the pdftex mailing list