2012-01-05 78 views

回答

2

我开始PHP的输出缓冲,那么就产生LaTeX的代码,就像你生成HTML代码。之后检索缓冲区,并为其添加一个LaTeX生成器。例如:

<?php ob_start(); ?> 
\documentclass{article} 
\begin{document} 
\section{Title} 
\subsection{Subtitle} 
Plain text. 
\subsection{Another subtitle} 
More plain text. :-P 
\end{document} 
<?php 
    $latex = ob_get_clean(); 
    $file = tmpnam('/tmp'); 
    file_put_contents($file, $latex); 
    exec('latex --output /path/to/your/result.pdf '.escapeshellarg($file)); 
    unlink($file); 
?> 

请注意,上面的代码具有伪代码的状态。我只是从记忆和受过教育的猜测中写出东西,而不是测试任何东西。但是这个原则应该起作用。