9

I have searched far and wide to find a PHP-based tool to convert LaTeX to PDF, but have had no success. I understand that LaTeX runs on the server side, however I still require a PHP-based command process in order to generate said PDF files using LaTeX.

Edit

Additionally, installing binaries, libraries or tools on to the server is a no-no. The tool at my disposal is PHP and the functionalities it has built in. Any class or PHP tool that can convert LaTex to PDF is incredibly useful.

Any guidance would be most appreciated.

Shoe
  • 74,840
  • 36
  • 166
  • 272
nderjung
  • 1,607
  • 4
  • 17
  • 38

3 Answers3

12

i just installed the package texlive-binaries and used a shell exec with the pdflatex command to generate the PDF from a (La)TeX file:

shell_exec("/usr/bin/pdflatex --interaction batchmode $filename");

i know this is not what you asked for but i don't know of a php lib as complete as the already existing latex compilers.

why reinvent the wheel anyways?

Update: When you have enough space, install textlive-full instead of texlive-binaries. This will install all the available packages, fonts, etc. and avoid you some headache why your document renders wrong.

Kaii
  • 20,122
  • 3
  • 38
  • 60
  • How does one go about installing the texlive-binaries on both a window and then a linux server? – nderjung Dec 20 '11 at 16:26
  • on debian linux, you just do `sudo apt-get install texlive-binaries`. on a windows system you follow the instructions on the [texlive website](http://www.tug.org/texlive/) – Kaii Dec 20 '11 at 18:17
  • I cannot accomplish such a task in my server environment. The tool at my disposal is PHP and the functionalities it has. Unless there is some Class or PHP tool that can convert LaTex to PDF, then I'm afraid this is of no help. – nderjung Dec 22 '11 at 18:14
  • Using shell_exec() is a security issue. Be warned. – josh123a123 Jun 30 '15 at 15:50
  • 1
    @josh122a123 no, it's not. Passing unfiltered user input is the security issue you're thinking about. The same applies to database queries, all kind of file operations or any other type of privileged access, i.e. backend API calls. Using shell_exec() is NOT a security issue per se. – Kaii Jul 01 '15 at 19:39
0

that is my example: name: phplatex.php

<?php
$data = shell_exec('/Library/TeX/texbin/pdflatex --interaction=nonstopmode -output-directory=/Users/arico/a/destino /Users/arico/a/fuente/prueba.tex');
echo ('Latex: ' . $data . '');
?>

path of pdflatex executable: /Library/TeX/texbin/pdflatex

path of output file in pdf: (you need permissions to write) -output-directory=/Users/arico/a/destino

path of source file in latex: /Users/arico/a/fuente/prueba.tex

Sᴀᴍ Onᴇᴌᴀ
  • 8,218
  • 8
  • 36
  • 58
Canay94
  • 1
  • 1
0

If you can't change your server setup to install server package for LaTeX you can't convert LaTeX files them into PDF...

but what you could check to convert directly into PDF without LaTeX, but that depends what you like to accomplish? It might be a look worth...fpdf...

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • I have looked into fpdf, as you can see by my previous question: http://stackoverflow.com/questions/8478720/fpdf-and-tv-film-screenplay-formatting I can write a script to convert XML to LaTeX, I am just attempting to find a way of outputting certain characteristics LateX happens to offer. – nderjung Dec 22 '11 at 18:27
  • So now the question is coming to my mind: What's the reason to use LaTeX? Which functionality do you need of LaTeX ? – khmarbaise Dec 22 '11 at 19:00
  • LaTex has a built in `Screenplay` class, as pointed out by @Blender, which has certain functionalities that pose difficult to recreate. LaTeX offers a simpler solution (As noted in my previous question). – nderjung Dec 24 '11 at 00:29
  • Ok..I know LaTeX so you need to install a LaTeX system on the server to use it. That's the point. There seemed to be no way around it. – khmarbaise Dec 24 '11 at 12:15