12

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?

  • 1
    Have a look on \href of the hyperref package. – Martin Scharrer Jul 13 '11 at 10:57
  • Maybe \url{run:<something>}. – Display Name Jul 13 '11 at 11:20
  • 1
    @xport: More like \href{run:/path/to/program}{Text Or Button image/diagram}. – Martin Scharrer Jul 13 '11 at 11:36
  • Using URLs requires a protocol handler for "run", which is not found on my system, and frankly, I think it is because of serious security issues. Does anyone knows of a tried-and-tested way to do this? – Little Bobby Tables Jul 13 '11 at 12:18
  • I would suggest you use a 'localhost' and execute it via a brower link. For example you could use WAMP and php. Your link then points to a php file that uses exec to execute an external command. Similar solutions exist for other languages. If you familiar with the above I can post a snippet. (My preference for this, is that you are not fiddling with the pdf security model). – yannisl Jul 13 '11 at 15:54
  • @Yiannis: That's a smart workaround that I did not think about, can you post some details? @xport: I tried using \href's run: but ran into some PDF security issues. In what env. did this work for you? – Little Bobby Tables Jul 14 '11 at 07:09
  • @Little Bobby Tables Please see my post below for some ideas. – yannisl Jul 16 '11 at 02:57

1 Answers1

6

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.

yannisl
  • 117,160