Any API for LaTeX in PHP or how to generate pdf in PHP?

If so, where can I find the API and document.

If not, what should I do to generate a pdf document use PHP?


Here is a start:


But it seems not free!!! Now I cannot afford the license fee. :injured:

And the pdf I want to generate requires typesetting much.

Do you have any other suggestions?


You can run LaTeX server-side as a system call, convert to PDF (or use pdflatex) and serve that to the browser.


Nice try. Thanks.

Have you ever tried that?

Whatever I will try it at once :cool:

Just be careful with the system command and check what arguments you give, it may be a vulnerability. (Imagine someone changing a GET variabele which is passed unchecked to system() like $_GET[‘latex_file’] = “; echo /etc/passwd” )


I have one problem. The frequency of generating pdf file might be quite high. This will cause any problems? Because we both know the LaTeX is not so efficient when compiling.{it even need compiling twice!}

I cannot test this right now, I just worry that some terrible prob might take place.

Well, I think that if the generation exceeds once per 5-10 minutes, it shouldn’t be run on any shared hosting account, because you will use too much cpu time then. You might get reprimanded by the hoster. If it’s your own server it’s no problem, but it can be slow. Why would you need to recompile so often, can’t you cache those PDF’s and only recompile once every hour or something? What is your purpose?

What I do is a system where users can input there information, and then according to their information, the system will generate a pdf document for user to download or read.

My problem is that the number of users could be quite large, and for each user the system should compile to generate a pdf. So the frequency of generating pdfs could be quite high.

This system runs on its own server. So do not worry about the machine.

my advice would be try it, and just keep an eye on the servers ‘top’ output…if it goes too high, then implement a queuing system where pdf 2 only starts compiling with pdf 1 is finished, and email the user when its done.

Well, try doing some timing. Try to find out how much time it takes to compile a representative LaTeX document on your server and do some testing. If it becomes too much users, maybe you can queue the generation of their PDFs? Like they do on download servers for games, where you are put in a waiting line. It’s not the nicest option for your users, It depends really on your hardware too, how many people can be compiling at the same time.

Ah steb types faster than me… :smiley:


It becomes more and more complex. Maybe I should try this, because so far, it is the only solution I can find.


In this case, I think JSP does much better, because Jave provide API for LaTeX:-)

Sending a email is a quite brilliant alternative.