如何通过PHP将LaTeX转换为PDF/PNG

如何通过PHP将LaTeX转换为PDF/PNG

问题描述:

我在PHP中有 LaTeX 代码(不是.tex文件);例如由$ _POST收到.如何在服务器上将呈现的 LaTeX 保存为PNG或PDF文件?

I have LaTeX code inside PHP (not as .tex file); for example received by $_POST. How can I save the rendered LaTeX as a PNG or PDF file on my server?

编辑:我知道PHP通常不会这样做.我将在PHP中运行一个shell命令.因此,我需要在Linux终端中执行此操作.

I know that PHP normally does not do this. I will run a shell command within PHP. Thus, I need something to do so in Linux terminal.

您可以执行exec()pdfTex生成PDF

you could exec() pdfTex to generate a PDF

URL: http://www.tug.org/applications/pdftex/

运行命令

pdftex file.tex

使用file_put_contents()将tex代码从$ _POST保存到文件后,请确保您具有写入指定文件夹的权限.

after you saved your tex-code from $_POST to a file using file_put_contents() - make sure you have the rights to write in the specified folder.

希望有帮助!