[Tex/LaTex] A button that runs an external program from a Beamer PDF presentation

beamerhyperrefpdf

I want to add a "run demo" button to a Beamer presentation (PDF file) that will launch an external Java application. Can this be done somehow – Embed an "exec" command inside a PDF using LaTeX/Beamer?

Best Answer

With Textworks on a Windows, MikTeX installation a simple link to the command amazingly will enable you to execute it, in the TeXWorks pdf reader. The following minimal will bring up the calculator program, provided "windows/system32" is in your path.

\documentclass{article}
\usepackage{hyperref}
\begin{document}
  \url{"calc.exe"}
\end{document}

This will not work with the Adobe pdf reader, although I am sure there is a way to bypass the security features of Adobe.

As I mentioned in the comments another way is to provide a link that activates a php script through localhost. A simple function to do this is shown below:

function pdflatex($data=''){
        if (!empty($_POST)){
            $code=$_POST['ascript'];
        }
        //$f='ZZZ.tex';
        //$res = file_put_contents('C:/latex-samples/'.$f, trim($code));
        //ob_start();
        $t='pdflatex.exe  c:/latex-samples/ZZZ.tex 2>&1';
        echo '<pre>'.shell_exec($t).'<pre>';
    }

In the sample I invoke the pdflatex.exe and redirect the output to the screen, so that you can see the output. I use scripts like this normally to run, language scripts through a textarea in the browser (hence the commented lines). In this case the script is captured and send as POST and saved in a file (ZZZ.tex), which you can then let pdflatex to handle.

I normally use WAMP or IndigoStar to install the web stack. The latter at http://www.indigostar.com/indigoperl.php will set Apache for Perl and PHP. Both Perl as well as Python have similar commands to php's shell_exec, as well as variations to this command.

Related Question